Skip to content

Tutorial: AI-Powered Code Reviews

OpenCodeHub integrates with LLMs (GPT-4, Claude) to provide automated, intelligent code reviews on every Pull Request. This tutorial guides you through setting it up.

  • An OpenCodeHub instance running v1.0.0+.
  • An API Key from OpenAI or Anthropic.

As an administrator, you need to configure the AI provider in your environment variables.

For OpenAI:

Terminal window
AI_PROVIDER=openai
OPENAI_API_KEY=sk-proj-...

For Anthropic:

Terminal window
AI_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-...

Restart your OpenCodeHub instance to apply changes.

By default, AI review is opt-in per repository to save costs.

  1. Navigate to Repository Settings > AI Review.
  2. Toggle Enable AI Review.
  3. Select Triggers:
    • On PR Open: Reviews the initial code.
    • On Every Push: Reviews every update (Can be expensive).
    • Manual Only: Developers must click “Request AI Review”.
  1. Create a Pull Request with some code.
  2. If configured for “Manual Only”, look for the ”🤖 Request AI Review” button in the PR sidebar. Click it.
  3. Wait a few seconds (or minutes for large PRs).
  4. The AI will comment directly on lines of code with:
    • 🔴 Security Risks: SQL injection, hardcoded secrets.
    • 🟡 Bugs: Null pointer exceptions, logic errors.
    • 🔵 Suggestions: Code style, minor performance tweaks.

You can customize the system prompt used for reviews by editing src/lib/ai/prompts.ts if you are self-hosting and want to enforce specific coding standards.