Review your git diffs with AI. Find bugs, security vulnerabilities, and code quality issues before they hit production.
- π AI-Powered Analysis β Reviews your git diffs using any OpenAI-compatible LLM
- π Bug Detection β Catches logical errors, edge cases, and runtime issues
- π Security Scanning β Identifies hardcoded secrets, injection risks, PII leaks, and more
- π‘ Actionable Suggestions β Gets refactoring ideas and best practice improvements
- π Quality Score β Scores your code from 0β100 with clear breakdown
- π¨ Beautiful Output β Color-coded, human-readable terminal output with severity indicators
- βοΈ Configurable β Multiple LLM providers, strictness levels, output formats
- π Commit Suggestions β Generates conventional commit messages from your changes
# Install via npm
npm install -g ai-diff
# Or run directly with npx
npx ai-diffYou need an API key from an OpenAI-compatible provider:
# Option 1: Environment variable
export AI_DIFF_API_KEY=sk-your-key-here
export AI_DIFF_MODEL=gpt-4o
# Option 2: Config file
ai-diff config --api-key sk-your-key-here --model gpt-4o
# Option 3: Use OPENAI_API_KEY (auto-detected)
export OPENAI_API_KEY=sk-your-key-here| Provider | Base URL | Example Model |
|---|---|---|
| OpenAI | https://api.openai.com/v1 |
gpt-4o, gpt-4o-mini |
| Anthropic | https://api.anthropic.com/v1 |
claude-sonnet-4-6 |
| Groq | https://api.groq.com/openai/v1 |
llama-3.3-70b |
| Together | https://api.together.xyz/v1 |
deepseek-ai/DeepSeek-V3 |
| Ollama (local) | http://localhost:11434/v1 |
deepseek-coder |
# Example: Use Groq for fast reviews
ai-diff config --base-url https://api.groq.com/openai/v1 --model llama-3.3-70b# Stage your changes first
git add .
# Review them
ai-diff review
# or simply:
ai-diffai-diff review --commit HEAD
ai-diff review --commit abc1234ai-diff review --unstaged# Detailed (default) β full color-coded output
ai-diff review
# Concise β compact summary
ai-diff review --format concise
# JSON β machine-readable output
ai-diff review --format json | jq '.score'# View current config
ai-diff config --show
# Set API key
ai-diff config --api-key sk-...
# Set model
ai-diff config --model gpt-4o
# Set strictness level
ai-diff config --strictness aggressive
# Set temperature
ai-diff config --temperature 0.5
# Interactive setup wizard
ai-diff initββββββββββββββββββββββββββββββββββββββββββββ
β π€ AI-DIFF β CODE REVIEW β
ββββββββββββββββββββββββββββββββββββββββββββ
Scope: staged changes
Files changed: 3
+42 -12
~ src/index.ts +20 -5
+ src/ai.ts +15 -0
~ src/config.ts +7 -7
π Code Quality Score: 85/100
π Summary:
Adds AI-powered code review functionality with OpenAI integration.
π Issues:
β [HIGH] Unhandled promise rejection in async review
File: src/ai.ts:42
The API call may throw without a catch handler.
π SECURITY CONCERNS
[HIGH] Hardcoded Secret β src/config.ts:15
API key may be logged in error messages.
β Sanitize error messages before logging.
For self-hosted or alternative providers:
# Local Ollama
ai-diff config --base-url http://localhost:11434/v1 --model deepseek-coder
# Azure OpenAI
ai-diff config --base-url https://your-resource.openai.azure.com --model gpt-4o# GitHub Actions β fail on critical issues
ai-diff review --format json | jq -e '.issues | map(select(.severity == "critical")) | length == 0'Add to your .git/hooks/pre-commit:
#!/bin/sh
npx ai-diff review --format concise- Extracts the git diff from your repository (staged, unstaged, or commit)
- Sends the diff to an LLM with a structured review prompt
- Parses the AI response into a structured review (issues, security, suggestions)
- Displays the results with beautiful terminal formatting
Supports any OpenAI-compatible API β OpenAI, Anthropic, Groq, Together, Ollama, and more.
| Variable | Config Key | Default | Description |
|---|---|---|---|
AI_DIFF_API_KEY |
apiKey |
β | API key for LLM provider |
AI_DIFF_API_BASE_URL |
apiBaseUrl |
https://api.openai.com/v1 |
API base URL |
AI_DIFF_MODEL |
model |
gpt-4o |
Model name |
| β | strictness |
balanced |
conservative, balanced, or aggressive |
| β | temperature |
0.3 |
LLM temperature (0β2) |
| β | maxDiffLines |
2000 |
Max diff lines to send |
| β | format |
detailed |
Output format |
# Clone
git clone https://github.com/AFS-Agentics/ai-diff.git
cd ai-diff
# Install dependencies
npm install
# Build
npm run build
# Run locally
npm start -- review --help- TypeScript β Type-safe, modern JavaScript
- Commander β CLI framework
- Chalk β Terminal styling
- OpenAI SDK β LLM API client
- Simple Git β Git operations
MIT Β© AFS Agentics
Contributions are welcome! Feel free to open issues or submit PRs.
Made with β€οΈ by AFS Agentics
