{"slug": "building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push", "title": "Building an AI-Powered Git Diff Reviewer: Catch Bugs Before You Push", "summary": "A developer built Git Diff Reviewer, an open-source CLI tool that installs as a Git pre-commit hook, extracts staged diffs, and sends them to a configurable LLM provider (Gemini, Groq, OpenRouter, or local Ollama) for a structured review of critical bugs, security vulnerabilities, anti-patterns, and performance issues before code is pushed. The tool filters files via a .reviewerignore file and flags issues such as SQL injection with CWE references, with a local Ollama option for fully private review.", "body_md": "Hey dev.to! 👋\n\nHave you ever pushed a commit in a hurry, only to realize later that you introduced a critical security flaw or a silly bug? We've all been there. The \"oops, I'll fix it in the next commit\" cycle is a rite of passage for developers.\n\n**What if you had a senior developer looking over your shoulder before you even push?**\n\nThat's exactly why I built **Git Diff Reviewer**, a CLI tool that integrates directly into your Git workflow. When you commit, it automatically extracts your diff, sends it to an LLM (Gemini, OpenRouter, Groq, or local Ollama), and gives you a structured review right in your terminal.\n\nLet's dive into how it works and how you can set it up!\n\nGit Diff Reviewer is a pre-commit hook that acts as your personal AI code reviewer. Instead of waiting for CI/CD to fail or a teammate to catch a bug, you get instant feedback.\n\n`git commit`. Zero friction.`.reviewerignore`:`.env` files so you don't waste tokens.\n| Category | What it catches | \n|---|---|\n| Critical Bugs | Logic errors, infinite loops | \n| 🔒 Security Vulnerabilities | SQL injection, XSS, hardcoded secrets (aligned with OWASP/CWE) | \n| ⚠️ Anti-patterns | Code smells and bad practices | \n| ⚡ Performance Bottlenecks | N+1 queries, inefficient loops | \n\n```\n┌──────────────────────────────────────────┐\n│   git commit -m \"feat: update auth\"      │\n└────────────────────┬─────────────────────┘\n                     ▼\n┌──────────────────────────────────────────┐\n│   Pre-commit hook                        │\n│   python main.py --staged                │\n└────────────────────┬─────────────────────┘\n                     ▼\n┌──────────────────────────────────────────┐\n│   Extract staged diff                    │\n│   + filter files via .reviewerignore     │\n└────────────────────┬─────────────────────┘\n                     ▼\n┌──────────────────────────────────────────┐\n│   LLM Provider                           │\n│   Gemini │ Groq │ OpenRouter │ Ollama    │\n└────────────────────┬─────────────────────┘\n                     ▼\n┌──────────────────────────────────────────┐\n│   Structured review printed in terminal  │\n└──────────────────────────────────────────┘\n```\n\nLet's get this running on your machine.\n\n```\ngit clone https://github.com/humammoin09-blip/git-diff-reviewer.git\ncd git-diff-reviewer\npython -m venv .venv\n\n# Windows:\n.\\.venv\\Scripts\\Activate.ps1\n\n# Mac/Linux:\nsource .venv/bin/activate\npip install -r requirements.txt\n```\n\nCopy the example file and add your API key:\n\n```\ncp .env.example .env\n```\n\nOpen `.env` and configure your provider (e.g., Gemini):\n\n```\nLLM_PROVIDER=gemini\nGEMINI_API_KEY=your_api_key_here\n```\n\n💡 **Pro tip:** If you want 100% privacy, set `LLM_PROVIDER=ollama` and run a local model!\n\n```\npython main.py --install-hook\n```\n\nThat's it! Now, every time you commit, the AI will review your code.\n\nImagine you write this code:\n\n``` python\n# auth.py\ndef get_user(user_id):\n    query = f\"SELECT * FROM users WHERE id = {user_id}\"\n    return db.execute(query)\n```\n\nWhen you commit, the AI immediately flags it:\n\n```\n=== AI CODE REVIEW ===\n\n[CRITICAL] SQL Injection vulnerability detected\nFile: auth.py, Line 42\nIssue: User input directly interpolated into SQL query.\nFix: Use parameterized queries.\nCWE-89: Improper Neutralization of Special Elements used in an SQL Command\n\n[WARNING] Hardcoded secret detected\nFile: config.py, Line 15\nIssue: API_KEY = \"sk-abc123...\"\nFix: Move to environment variable.\n```\n\nThis catches the bug before it ever reaches production. 🛑\n\nReal security engineers respect honesty over hype, so here's what the tool cannot do:\n\nI'm just getting started with this. For v2, I'm planning:\n\nIf you find this project useful, please give it a Star on GitHub! ⭐\n\nA modular, terminal-based CLI tool that inspects local git diffs and sends them to your choice of LLM provider for an automated, high-rigor security and code quality review.\n\n`--staged`), unstaged changes (`--unstaged`), or diff against specific branches/commits (`--branch main`).`.md` files for pull request comments…\nBreak it, fuzz it, and if you find a bug, open an issue. I read every single one.\n\nLet me know in the comments what features you'd like to see in v2!", "url": "https://wpnews.pro/news/building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push", "canonical_source": "https://dev.to/humam_moin/building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push-3mab", "published_at": "2026-10-12 14:08:18+00:00", "updated_at": "2026-10-12 14:17:21.682711+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-agents"], "entities": ["Git Diff Reviewer", "Gemini", "Groq", "OpenRouter", "Ollama", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push", "markdown": "https://wpnews.pro/news/building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push.md", "text": "https://wpnews.pro/news/building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push.txt", "jsonld": "https://wpnews.pro/news/building-an-ai-powered-git-diff-reviewer-catch-bugs-before-you-push.jsonld"}}