An AI-powered code review tool that automatically reviews code changes using Large Language Models (LLMs). Supports multiple LLM providers including OpenAI, Anthropic, Moonshot, and custom providers.
- 🤖 AI-Powered Code Review: Automatically reviews code changes using advanced LLM models
- 🔍 Git Integration: Seamlessly compares branches and analyzes diffs
- 📊 Interactive Web UI: Beautiful, GitHub-like interface for reviewing results
- 🎯 Rule-Based Review: Built-in rules for TypeScript, React, and code design best practices
- 🔄 Batch Processing: Intelligently splits large changesets into manageable batches
- 📝 Detailed Comments: Provides line-by-line comments with severity levels and suggestions
- ⚡ Fast & Efficient: Optimized token estimation and context management
- OpenAI: GPT-3.5, GPT-4, and other OpenAI models
- Anthropic: Claude models via Anthropic API
- Moonshot: Moonshot AI models
- Custom: Support for any OpenAI-compatible API endpoint (e.g., DeepSeek)
- 🌐 Internationalization: Supports English and Chinese (Simplified)
- 🔁 Retry Mechanism: Automatic retry for incomplete JSON responses
- 📈 Statistics Dashboard: Comprehensive statistics and problem analysis
- 🔗 GitHub Integration: Automatically post reviews as PR comments
- 💾 Export Results: Save review results as JSON files
- 🎨 Theme Support: Light and dark themes in the web UI
npm install -g @aicodereview/ai-code-reviewnpm install --save-dev @aicodereview/ai-code-reviewgit clone <repository-url>
cd ai-codereview
npm install
npm run buildCreate a .env file in your project root or set environment variables:
# Required
LLM_API_KEY=your_api_key_here
# Optional - LLM Provider Configuration
LLM_PROVIDER=openai # Options: openai, anthropic, moonshot, custom
LLM_MODEL_NAME=gpt-3.5-turbo # Model name (varies by provider)
LLM_BASE_URL= # Required for custom provider
LLM_MAX_TOKENS=8192 # Maximum output tokens
# Optional - Language
LANG=en # Options: en, zh-CN (default: en)OpenAI:
LLM_PROVIDER=openai
LLM_MODEL_NAME=gpt-4
LLM_API_KEY=sk-...Anthropic:
LLM_PROVIDER=anthropic
LLM_MODEL_NAME=claude-3-opus-20240229
LLM_API_KEY=sk-ant-...Custom (DeepSeek):
LLM_PROVIDER=custom
LLM_MODEL_NAME=deepseek-chat
LLM_BASE_URL=https://api.deepseek.com
LLM_API_KEY=sk-...# Review changes against master branch
code-review master
# Review against a specific branch
code-review develop
# Interactive branch selection
code-review
# Use custom rules
code-review master --rules ./custom-rules.json
# Save results without starting server
code-review master --no-server --output ./review-results
# Use Chinese language
code-review master --lang zh-CN# Review and post to GitHub PR
code-review-github \
--github-token $GITHUB_TOKEN \
--github-owner owner \
--github-repo repo \
--github-pr 123 \
--pwd /path/to/repocode-review [baseBranch] [options]
Options:
-r, --rules <files...> Additional rule JSON files to load
-p, --pwd <directory> Working directory (default: current directory)
--env <file> Path to .env file (default: .env)
--no-server Do not start review report server
-o, --output <directory> Output directory for JSON files
--max-retries <number> Maximum continuation attempts for incomplete JSON (default: 10)
--lang <language> Language: en or zh-CN (default: en)
-h, --help Display help
-V, --version Display versioncode-review-github [options]
Options:
-r, --rules <files...> Additional rule JSON files to load
-p, --pwd <directory> Working directory (default: current directory)
--env <file> Path to .env file (default: .env)
--max-retries <number> Maximum continuation attempts (default: 10)
--github-token <token> GitHub token (or set GITHUB_TOKEN env var)
--github-owner <owner> Repository owner (or set GITHUB_REPOSITORY_OWNER)
--github-repo <repo> Repository name (or set GITHUB_REPOSITORY_NAME)
--github-pr <number> PR number (or set GITHUB_PR_NUMBER)
--review-event <event> Review event: COMMENT, APPROVE, or REQUEST_CHANGES
-o, --output <directory> Output directory for JSON files
--lang <language> Language: en or zh-CN (default: en)
-h, --help Display help
-V, --version Display version- Branch Selection: If no branch is specified, the tool lists all remote branches for selection
- Diff Analysis: Compares current branch with target branch and extracts code changes
- File Filtering: Automatically filters to review only
.tsand.tsxfiles - Batch Processing: Splits files into batches based on context window limits
- AI Review: Calls LLM API to review each batch of changes
- Result Processing: Parses and normalizes review comments
- Output: Saves results and optionally starts web server
The tool includes built-in rules for:
- TypeScript (15 rules): Type safety, interface definitions, generics, etc.
- React (20 rules): Component design, hooks usage, performance optimization, etc.
- Code Design (21 rules): Function design, code organization, error handling, etc.
Create custom rule files in JSON format:
{
"category": "custom",
"name": "Custom Rules",
"rules": [
{
"id": "custom-001",
"name": "Rule Name",
"description": "Rule description",
"level": "strict|suggestion|optimization",
"goodExample": "Correct example code",
"badExample": "Incorrect example code",
"reason": "Why this rule exists"
}
]
}Load custom rules:
code-review master --rules ./my-rules.json ./team-rules.jsonThe web interface provides:
- File Tree: Navigate through changed files
- Diff View: Side-by-side code comparison
- Comment Markers: Inline comments with severity indicators
- Statistics Dashboard:
- Problem type distribution (pie chart)
- Rule statistics
- File-level statistics
- Filtering: Filter comments by severity, file, or rule
- Theme Toggle: Switch between light and dark themes
See README-GITHUB.md for detailed GitHub Actions setup instructions.
Quick setup:
- Copy
examples/github-workflow/code-review.ymlto.github/workflows/ - Configure GitHub Secrets (LLM_API_KEY, etc.)
- Push to trigger automatic code reviews on PRs
{
filePath: string; // File path
line: number; // Start line number
endLine: number; // End line number
severity: 'error' | 'warning' | 'info';
message: string; // Comment message
ruleId: string; // Rule ID
ruleName: string; // Rule name
ruleLevel: string; // Rule level (strict/suggestion/optimization)
ruleDesc: string; // Rule description
suggestion?: string; // Optional suggestion
tags?: string[]; // Optional tags
}{
comments: ReviewComment[];
summary: string;
startTime?: string; // ISO 8601 format
endTime?: string; // ISO 8601 format
duration?: number; // Duration in milliseconds
}- Node.js 18+
- npm or pnpm
# Install dependencies
npm install
# Install UI dependencies
cd ui && npm install && cd ..
# Build
npm run build
# Development mode
npm run dev masterai-codereview/
├── src/
│ ├── cli.ts # Main CLI entry
│ ├── cli-github.ts # GitHub CLI entry
│ ├── git/ # Git operations
│ ├── review/ # Review logic
│ │ ├── adapters/ # LLM provider adapters
│ │ ├── agent.ts # Review agent
│ │ └── rules/ # Built-in rules
│ ├── server/ # Web server
│ └── utils/ # Utilities
│ ├── i18n.ts # Internationalization
│ ├── github.ts # GitHub API
│ └── storage.ts # File storage
├── ui/ # React web UI
└── examples/ # Example files
The tool supports multiple languages:
- English (en): Default language
- Chinese Simplified (zh-CN): Full Chinese support
Set language via CLI:
code-review master --lang zh-CNOr via environment variable:
export LANG=zh-CN
code-review mastercode-review mastercode-review develop --rules ./team-rules.jsoncode-review master --no-server --output ./reviewscode-review-github \
--github-token $GITHUB_TOKEN \
--github-owner myorg \
--github-repo myrepo \
--github-pr 42# .env
LLM_PROVIDER=custom
LLM_MODEL_NAME=deepseek-chat
LLM_BASE_URL=https://api.deepseek.com
LLM_API_KEY=sk-...
code-review masterIssue: LLM_API_KEY environment variable is not set
Solution: Set the LLM_API_KEY environment variable or create a .env file.
Issue: Context length exceeded
Solution: The changeset is too large. The tool automatically batches files, but if a single file exceeds the limit, consider:
- Using a model with a larger context window
- Reducing the
LLM_MAX_TOKENSvalue - Reviewing smaller changesets
Issue: Failed to parse JSON response
Solution: The tool automatically retries incomplete JSON responses. If it still fails:
- Increase
--max-retriesvalue - Check your API key and network connection
- Try a different model
Issue: Server port already in use
Solution: The tool automatically finds an available port. If issues persist, check for other processes using ports 3000-3010.
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Built with:
Made with ❤️ for better code quality




