Skip to content

AI Code Review

AI Code Review uses advanced language models to automatically review your pull requests, catching bugs, security issues, and code quality problems before they reach production.

OpenCodeHub supports 10+ AI providers. Configure one or more in your .env file:

ProviderModelsAPI Key Env Var
OpenAIGPT-4, GPT-4o, GPT-4 TurboOPENAI_API_KEY
AnthropicClaude 3.5 Sonnet, Claude 3 OpusANTHROPIC_API_KEY
GoogleGemini 1.5 Pro, Gemini FlashGOOGLE_AI_API_KEY
GroqLlama 3, Mixtral (fast inference)GROQ_API_KEY
OpenRouterMulti-model gatewayOPENROUTER_API_KEY
TogetherLlama, Mixtral, CodeLlamaTOGETHER_API_KEY
BytezVarious modelsBYTEZ_API_KEY
OllamaAny local model (Llama, CodeLlama, etc.)No key needed
External AgentCustom webhookEXTERNAL_AGENT_WEBHOOK_URL

Security Vulnerabilities

  • SQL injection, XSS, CSRF
  • Authentication/authorization bypasses
  • Exposed secrets or credentials
  • Insecure dependencies

Performance Issues

  • N+1 database queries
  • Inefficient algorithms
  • Memory leaks
  • Missing indexes

Code Quality

  • Best practice violations
  • Code smells (long functions, deep nesting)
  • Incomplete error handling
  • Missing input validation

Potential Bugs

  • Null/undefined pointer exceptions
  • Race conditions
  • Off-by-one errors
  • Type mismatches
1. Developer opens/updates PR
2. OpenCodeHub sends diff to AI provider
3. AI analyzes code changes
4. AI posts inline comments + summary
5. Developer addresses feedback

Privacy note: Code is sent to the configured AI provider. Use Ollama or the external agent for sensitive codebases.

OpenAI:

Terminal window
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxx

Anthropic:

Terminal window
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxx

Google Gemini:

Terminal window
GOOGLE_AI_API_KEY=xxxxxxxxxxxxx

Groq (fast, cheap):

Terminal window
GROQ_API_KEY=gsk_xxxxxxxxxxxxx

Ollama (local, private):

Terminal window
# No env var needed — configure in Settings → AI
# Just install Ollama: https://ollama.com
# Pull a model: ollama pull codellama:13b

Multiple providers: Configure all keys. The system picks the best available provider.

Via Web UI:

  1. Go to Repository → Settings → AI Review
  2. Toggle Enable AI Code Review
  3. Configure trigger, severity threshold, and max files
  4. Click Save

Via API:

Terminal window
curl -X PATCH https://git.yourcompany.com/api/repos/OWNER/REPO/settings \
-H "Authorization: Bearer $TOKEN" \
-d '{ "aiReview": { "enabled": true } }'

Via CLI:

Terminal window
och repo config ai-review --enable

When enabled, AI reviews trigger automatically when PRs are opened or updated.

Web UI: Open PR page → Click “Request AI Review”

CLI:

Terminal window
och review ai <pr-number>

API:

Terminal window
curl -X POST https://git.yourcompany.com/api/repos/OWNER/REPO/pulls/125/ai-review \
-H "Authorization: Bearer $TOKEN"
SeverityMeaningExample
CRITICALMust fix — security/data lossSQL injection, exposed key
WARNINGShould fix — perf/best practiceN+1 query, missing error handling
INFOConsider — suggestionBetter variable name

AI posts an overall summary with statistics, critical issues, and recommendations.

Create .opencodehub/ai-review.yml in your repo:

include:
- "src/**/*.ts"
exclude:
- "**/*.test.ts"
- "dist/**"
focus:
security: 10
performance: 8
bugs: 8
code_quality: 5
custom_rules:
- name: "No console.log in production"
pattern: 'console\.log\('
severity: warning
message: "Remove console.log before merging"

Or use Settings → AI Review Rules in the web UI.

ProviderApprox Cost per Review
GroqFree (rate limited)
OllamaFree (local)
OpenAI GPT-4o~$0.02-0.10
Anthropic Claude~$0.03-0.15
Google Gemini~$0.01-0.05

Cost optimization:

  • Keep PRs small and focused
  • Skip test files in review config
  • Use severity threshold to filter info-level comments
  • Use Groq or Ollama for routine reviews, GPT-4/Claude for critical code

AI review taking too long: Large PR (many files). Split into smaller PRs.

AI review failed: Check API key is valid. Verify provider is configured in Settings → AI.

Too many false positives: Refine rules in Settings → AI Review Rules. Add custom instructions.

Missing obvious bugs: Add custom instructions describing your conventions and patterns.