Git Diff Reviewer: AI Code Review That Catches Bugs Before You Commit

Git Diff Reviewer uses a pre-commit hook to send staged diffs to an LLM for automatic review, catching security issues early.
Git Diff Reviewer is a terminal-based CLI tool that embeds into the Git workflow as a pre-commit hook: when a developer runs git commit, it automatically extracts the staged diff, filters it through .reviewerignore, sends it to an LLM, and outputs a structured review in the terminal. It supports four providers — Gemini, OpenRouter, Groq, and local Ollama — balancing capability, flexibility, low latency, and privacy. Results are categorized into critical bugs, security vulnerabilities (aligned with OWASP/CWE), anti-patterns, and performance bottlenecks, with file, line number, issue description, and Before/After fixes. The tool also supports reviewing unstaged changes, branch comparison, safe truncation of large diffs, Markdown export, and interactive mode. The author candidly notes limitations like LLM hallucinations, context window constraints, and offline requirements, and plans a v2 with GitHub Action integration and a custom rules engine.
Why Pre-Commit Review Matters
Committing code in a hurry and only discovering a security hole or a dumb bug afterward is a loop nearly every developer has been through. Waiting for CI/CD to fail and then doubling back to fix things, or letting a teammate catch the problem during code review, both come with real time costs. Git Diff Reviewer takes a straightforward approach: when git commit fires, it hands the staged diff to an LLM for review, so problems surface locally.

This is a terminal-based CLI tool that embeds into the Git workflow as a pre-commit hook. It extracts the staged diff, sends it to an LLM provider like Gemini, OpenRouter, Groq, or a local Ollama instance, then prints a structured review right in the terminal.
A pre-commit hook is a client-side Git hook mechanism. Git reserves script execution entry points at multiple stages of the commit lifecycle, and pre-commit fires after the developer types git commit but before the commit object is actually created. If the script exits with a non-zero status code, Git aborts the commit. This makes it the ideal place to intercept code before it enters the repository: formatting checks, secret scanning, linting, and the AI review described here can all hook in here. Hook scripts live in the .git/hooks/ directory and by default aren't distributed with the repository, so tools like Git Diff Reviewer that provide an --install-hook command essentially write the script into the local hooks directory with executable permissions, so every commit triggers the review automatically.
Core Features and Review Categories
Git Diff Reviewer supports switching between multiple providers: Gemini offers strong capabilities, Groq delivers ultra-low latency, OpenRouter provides model flexibility, and Ollama satisfies 100% local privacy needs. The tool filters out lockfiles, build artifacts, and .env files via .reviewerignore to avoid wasting tokens.
Review results aren't vague "something's wrong here" notes — they're presented in strict categories:
| Category | What It Catches |
|---|---|
| Critical Bugs | Logic errors, infinite loops |
| 🔒 Security Vulnerabilities | SQL injection, XSS, hardcoded secrets (aligned with OWASP/CWE) |
| ⚠️ Anti-Patterns | Code smells and bad practices |
| ⚡ Performance Bottlenecks | N+1 queries, inefficient loops |
Each issue comes with the file, line number, problem description, and a fix suggestion, and some include Before/After code snippets. The project ships with 22 unit tests to ensure reliability.
OWASP and CWE are two complementary vulnerability classification systems in the security field. OWASP (Open Web Application Security Project) publishes the famous Top 10, summarizing the ten most common security threats to web applications from a risk perspective — injection, broken access control, cryptographic failures, and so on — with an emphasis on "risk categories" and defensive recommendations. CWE (Common Weakness Enumeration), maintained by MITRE, is a standardized enumeration of software weaknesses, each with a unique ID: CWE-89 for SQL injection, CWE-79 for XSS, and so on. The relationship is that one OWASP risk category often maps to multiple specific CWEs. When an AI review tool cites CWE numbers in its report, the benefit is that vulnerability types are mapped to an industry-recognized dictionary, so security engineers can directly look up fixes, integrate with SAST tools or vulnerability management systems, rather than relying on fuzzy natural-language descriptions.
Architecture and Workflow
The tool's execution chain is clear:
git commit -m "feat: update auth"
▼
Pre-commit hook (python main.py --staged)
▼
Extract staged diff + .reviewerignore filtering
▼
LLM Provider (Gemini | Groq | OpenRouter | Ollama)
▼
Structured review output to terminal
Beyond --staged for reviewing the staging area, it also supports --unstaged to review unstaged changes and --branch main to compare against a specific branch or commit. Interactive mode offers guided selection of the diff target and provider. Large diffs are safely truncated to avoid exceeding the model's context window, and review results can be exported to a Markdown file for easy pasting into PR comments.
The staging area is a key layer in Git's three-tree model. Git maintains three areas: the working directory, the staging area (index/staging area), and the repository. git add writes changes from the working directory into the staging area, and git commit then solidifies the staging area's contents into a commit. So the "staged diff" is exactly the portion of changes shown by git diff --staged that are about to be committed. Git Diff Reviewer reviews only this portion by default rather than the entire working directory, precisely to focus on what this commit will actually introduce — temporary changes that haven't been git add-ed won't be falsely flagged. By contrast, --unstaged reviews changes in the working directory that haven't been staged yet, and --branch main compares the current branch against a target branch. These three correspond to different review scenarios.
Installation and Configuration
Setup involves five steps: clone the repo, create a virtual environment, install dependencies, configure environment variables, and install the Git hook.
git clone https://github.com/humammoin09-blip/git-diff-reviewer.git
cd git-diff-reviewer
python -m venv .venv
source .venv/bin/activate # Windows use .\\.venv\\Scripts\\Activate.ps1
pip install -r requirements.txt
cp .env.example .env
Configure the provider in .env, for example Gemini:
LLM_PROVIDER=gemini
GEMINI_API_KEY=your_api_key_here
If you want full privacy, just set LLM_PROVIDER to ollama and run a local model. Finally, run python main.py --install-hook to install the hook. From then on, every commit automatically triggers AI review.
Real-World Example
Suppose you wrote something like this:
**Parameterized queries are the fundamental defense against SQL injection.** SQL injection happens when user input is directly concatenated into an SQL statement string, letting an attacker close out the original semantics and inject arbitrary commands. In the example above, `f"SELECT * FROM users WHERE id = {user_id}"` is a classic bad pattern. Parameterized queries (prepared statements) separate the structure of the SQL statement from the data: you first define a statement template with placeholders (like `?` or `%s`), the database pre-compiles the execution plan, and then user input is bound in as pure data — even if it contains quotes or SQL keywords, it won't be parsed as code. Mainstream languages and drivers all support this natively, e.g. Python's `db.execute("SELECT * FROM users WHERE id = ?", (user_id,))`. This is OWASP's recommended first-line injection defense, so the AI uses it as the standard fix suggestion in reviews.
# auth.py
def get_user(user_id):
query = f"SELECT * FROM users WHERE id = {user_id}"
return db.execute(query)
On commit, the AI immediately flags it:
=== AI CODE REVIEW ===
[CRITICAL] SQL Injection vulnerability detected
File: auth.py, Line 42
Issue: User input directly interpolated into SQL query.
Fix: Use parameterized queries.
CWE-89: Improper Neutralization of Special Elements used in an SQL Command
[WARNING] Hardcoded secret detected
File: config.py, Line 15
Issue: API_KEY = "sk-abc123..."
Fix: Move to environment variable.
The problem is caught before production. This CWE-number-based referencing lets security engineers quickly pinpoint the vulnerability type, rather than getting a vague "not safe" warning.
Known Limitations
The author gives an honest account of the tool's limitations, which deserves credit:
- LLM hallucinations: The AI occasionally produces false positives. Treat it as a "second pair of eyes," not absolute truth.
- Context window limits: Extremely large diffs may exceed the model's processing capacity.
- Offline limitations: Unless you use local Ollama, an internet connection is required.
These three points reveal the shared boundaries of current AI code review tools — they excel at spotting pattern-based issues but still fall short in scenarios requiring full project context to judge.
Roadmap
The v2 roadmap includes: GitHub Action integration (automatic PR review), multi-file context understanding, and a custom rules engine (define your own linting rules). GitHub Action integration and the custom rules engine are the most community-requested directions — the former extends review from local to the PR workflow, while the latter lets teams codify their own coding standards.
The project's core value isn't replacing human review, but intercepting the easiest-to-miss security issues and anti-patterns before commit, lowering the cost of fixes. For individual developers and teams looking to quickly adopt AI-assisted review, this is a low-barrier option.
Related articles

Felix Rieseberg Personal Homepage
Felix Rieseberg's personal homepage sparks attention on Hacker News. This article covers the Slack engineer's technical background, the rise and fall of nativefier, and the value of a developer homepage as a tech calling card.

@ai-sdk/vue 3.0.306 Patch Release Syncs with [email protected] Update
@ai-sdk/vue 3.0.306 released, synced with [email protected]. A routine patch release for the Vercel AI SDK ecosystem with no public API changes; the Vue adapter layer stays version-aligned with the core package.

Gemini 4 Argon API Launches: The Era of Million-Token Output Begins
Google launches Gemini 4 Argon with sparse MoE architecture, up to 1M output tokens, and a 68.90% Vals Index score, available across API, AI Studio, and the Gemini app.