Code Review Buddy is an AI-powered CLI tool that reviews your staged Git changes before you commit. It detects bugs, security issues, secrets, and code smells, then suggests improvements and a commit message. It supports interactive and non-interactive modes, beautiful output, and is easy to integrate into any workflow or Git hook.
- π€ AI-Powered Analysis: Uses OpenRouter (GPT-4, Claude, Gemini, etc.) to review your code diffs
- π Secret & Issue Detection: Finds bugs, security vulnerabilities, hardcoded secrets (API keys, tokens, private keys), and code smells
- π Quality Scoring: Assigns a 0-100 score, configurable threshold, and per-file breakdown
- πΌοΈ Beautiful Output: Boxen summaries, color-coded CLI, and export to JSON, Markdown, or HTML
- ποΈ Per-File Review: Optionally runs AI review on each staged file for granular feedback
- πΉοΈ Interactive Mode: Accept/ignore/fix-later for each issue, with commit message editing
- πͺ Git Hook Ready: Easy integration with Husky or manual hooks
- π‘οΈ Configurable:
.reviewbuddyrcfor ignore patterns, custom scoring, and output settings - π°οΈ History & Analytics: Tracks review history and summarizes recent code quality
npm install -g code-review-buddynpm install --save-dev code-review-buddygit clone https://github.com/kammounmedaziz/code-review-buddy.git
cd code-review-buddy
npm install
npm link # Optional: makes CLI available globallyCreate a .env file in your project root:
OPENROUTER_API_KEY=sk-or-v1-your-api-key-here # Required
AI_MODEL=gpt-4o-mini # Optional (default: gpt-4o-mini)
REVIEW_SCORE_THRESHOLD=70 # Optional (default: 0)
MAX_TOKENS=1200 # Optional
DEBUG=false # OptionalCreate a .reviewbuddyrc JSON file to customize ignore patterns, scoring, and output:
{
"ignore": ["**/secrets/**", "*.test.js"],
"scoring": { "security": 30, "bug": 10 },
"output": { "format": "markdown", "outFile": "review.md" },
"history": { "enabled": true, "file": ".code-review-buddy/history.json" }
}- Visit OpenRouter.ai
- Sign up and generate an API key
- Add credits (pay-as-you-go)
- Add your key to
.env
git add .# Basic review
code-review-buddy
# Interactive mode (default)
code-review-buddy --interactive
# Per-file AI review (granular feedback)
code-review-buddy --per-file
# Output as JSON, Markdown, or HTML
code-review-buddy --format json --out review.json
code-review-buddy --format markdown --out review.md
code-review-buddy --format html --out review.html
# Force commit even if score is low
code-review-buddy --force
# Debug mode (see raw AI responses)
code-review-buddy --debug| Option | Description |
|---|---|
| -i, --interactive | Enable interactive mode (accept/ignore/fix-later) |
| --no-interactive | Disable interactive mode |
| -f, --force | Force commit even if score is below threshold |
| -d, --debug | Enable debug logging (saves AI responses to files) |
| --no-commit | Skip automatic commit message application |
| -F, --format | Output format: box, json, markdown, html |
| -o, --out | Output file path for reports |
| -p, --per-file | Analyze each staged file individually (per-file AI) |
| --no-history | Disable writing to review history |
| -V, --version | Output the version number |
| -h, --help | Display help information |
# Install husky
npm install --save-dev husky
# Initialize husky
npx husky init
# Create pre-commit hook
echo "code-review-buddy" > .husky/pre-commit
chmod +x .husky/pre-commit# Navigate to your project
cd your-project
# Create pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/sh
code-review-buddy
EOF
# Make it executable
chmod +x .git/hooks/pre-commit# Create hooks directory
mkdir -p .githooks
# Create pre-commit hook
cat > .githooks/pre-commit << 'EOF'
#!/bin/sh
code-review-buddy
EOF
# Configure git to use custom hooks directory
git config core.hooksPath .githooks
# Make executable
chmod +x .githooks/pre-commit# Skip the review for emergency commits
git commit --no-verify -m "emergency fix"
# Or use the force flag
code-review-buddy --forceCode Review Buddy assigns a quality score from 0-100 based on detected issues:
| Issue Type | Score Penalty | Example |
|---|---|---|
| π Secret | -40 points | Exposed API keys, passwords |
| π Security | -25 points | SQL injection, XSS vulnerabilities |
| π Bug | -15 points | Null pointers, logic errors |
| β‘ Performance | -10 points | Inefficient loops, memory leaks |
| π¨ Style | -5 points | Formatting, naming conventions |
Score Interpretation:
- 90-100: Excellent code quality β
- 70-89: Good code with minor issues
β οΈ - 50-69: Moderate issues, improvements needed π§
- 0-49: Significant issues, refactoring recommended β
npm testThe test suite covers:
- Interactive mode and CLI helpers
- Ora spinner/progress indicators
- Secret detection (API keys, tokens, private keys)
- Output formatters (JSON, Markdown, HTML)
- Config ignore patterns and merging
- History persistence and summarization
- Stage Changes: Use
git addto stage files - Run Review: Execute
code-review-buddy - AI Analysis: Sends diff to OpenRouter AI
- Parse Results: Extracts issues and suggestions
- Score Calculation: Applies penalties based on issue types
- Threshold Check: Compares score to configured threshold
- Report: Displays formatted results with colors
- Auto-Commit Message: Applies AI-suggested commit message (optional)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Code Review Results
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Quality Score: 75/100
π Suggested Commit: fix: add null check and improve error handling
βοΈ Threshold: 70/100
β 2 Issues Found
Summary: π 1 bug, β‘ 1 performance
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Null pointer exception [HIGH]
π src/utils.js : line 45
π‘ Variable 'user' may be null before accessing properties
β¨ Add null check before accessing user.name
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β‘ Inefficient array operation [MEDIUM]
π src/service.js : line 120
π‘ Using nested loops causes O(nΒ²) complexity
β¨ Replace with Map for O(n) lookup performance
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Issue: Missing credentials error
# Solution: Make sure .env file exists and contains OPENROUTER_API_KEY
cp .env.example .env
# Edit .env and add your API keyIssue: No staged changes found
# Solution: Stage files before running
git add .
code-review-buddyIssue: AI returns invalid JSON
# Solution: Use debug mode to see raw response
code-review-buddy --debug
# Check debug-ai-response-*.json fileIssue: Score always blocks commits
# Solution 1: Lower threshold in .env
REVIEW_SCORE_THRESHOLD=50
# Solution 2: Use force flag
code-review-buddy --forceContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
git clone https://github.com/kammounmedaziz/code-review-buddy.git
cd code-review-buddy
npm install
cp .env.example .env
# Add your API key to .env
npm linkMIT Β© kammounmedaziz
- π Report a Bug
- π‘ Request a Feature
- π¬ Discussions
Made with β€οΈ by developers, for developers