AI-based local code diff reviewer that runs on every git commit.
Project description
🤖 DiffReviewer — Local AI Code Review on Every Commit
DiffReviewer is a lightweight, local-first AI assistant that reviews your code on every Git commit and provides helpful suggestions about:
- 🔍 Code quality
- ⚙️ Logical issues
- ✨ Readability and improvements
It uses a local GGUF-compatible LLM (like Mistral or StarCoder) through llama.cpp, and runs silently in the background without blocking your workflow.
🚀 Features
- ✅ Runs locally (no data is sent to the cloud)
- ✅ Hooks into Git using a global pre-commit hook
- ✅ Queues and reviews changes asynchronously — never blocks your commits
- ✅ Automatically deduplicates model loads (only one review at a time)
- ✅ Diff-aware (only reviews staged changes)
- ✅ Saves feedback in a
.diff_review/folder per repo - ✅ Supports models like Mistral, StarCoder, DeepSeek etc.
- ✅ Works with or without GPU
- ✅ Highly configurable during setup
📦 Installation
🔹 Option 1: From PyPI
pip install diff-reviewer
🔹 Option 2: From GitHub (latest)
pip install git+https://github.com/your-username/DiffReviewer.git
🔹 Option 3: Local development install
git clone https://github.com/ChargedMonk/DiffReviewer.git
cd DiffReviewer
pip install .
💠 One-Time Setup
To set up the global Git hook and configure the reviewer:
diff-reviewer init \
--model-dir ~/.models \
--model-file mistral-7b-instruct-v0.2.Q4_K_M.gguf \
--gdrive-model-url https://drive.google.com/file/d/1IVrCT8mzSNtfUJ5rTyDbLfcxbHzkcX2K/view \
--text-context 8192 \
--review-dir .diff_review \
--prompt-prefix "You are a senior code reviewer. Given the diff and surrounding code context, suggest improvements in code quality, logic, and readability. Be precise and constructive." \
--max-tokens 1024
This will:
- Register a global Git pre-commit hook at
~/.git-hooks/ - Persist your config to
~/.diff_reviewer_config.json - Start reviewing staged changes in background after every commit
💾 Model Setup
Download a .gguf model (e.g., from HuggingFace or Google Drive), then place it in your preferred directory:
~/.models/mistral-7b-instruct-v0.2.Q4_K_M.gguf
Then use --model-dir and --model-file during init.
You can also provide a Google Drive download URL via --gdrive-model-url if the model isn't present — it will be downloaded automatically.
🧠 How Queued Reviews Work
To avoid system freezes and GPU overload:
✅ DiffReviewer now uses a file-based job queue. Each commit writes a job to ~/.diff_reviewer/queue, and a single background worker handles them one at a time. Why it matters:
⏱ Multiple commits don’t overload your system
🔄 Model is only loaded once per session
💻 Your terminal and Git remain fully responsive
♻️ Crashed or exited workers restart automatically
💡 How It Works
- On commit, the pre-commit hook captures the staged diff.
- The diff is base64-encoded and enqueued as a job.
- A background worker processes jobs one by one.
- Each changed file is reviewed using a local LLM.
- Suggestions are saved in .diff_review/..review.txt
Example output:
📤 Running code reviewer in background... (log: /tmp/diff_reviewer_1234.log)
✅ Review completed!
Check .diff_review/ in your repo to view suggestions.
🧐 Example Suggestion
📝 Suggestions for utils.py:
- The function `process_data` has nested conditionals that could be flattened for readability.
- Consider using `enumerate()` instead of manually managing the index.
⚙️ Configuration Options (via diff-reviewer init)
| Option | Description |
|---|---|
--model-dir |
Path to directory where .gguf models are stored |
--model-file |
Name of the model file to load |
--gdrive-model-url |
Optional Google Drive URL to download model if missing |
--text-context |
Max context length to use (e.g., 8192) |
--review-dir |
Directory to save review suggestions in each repo |
--prompt-prefix |
Prompt to guide the AI reviewer |
--max-tokens |
Max tokens in the generated review output |
Config is saved in ~/.diff_reviewer_config.json and used automatically on every commit.
🐛 Troubleshooting
📌 Review doesn’t run on commit?
- Ensure you ran:
diff-reviewer init - Check that
~/.git-hooks/pre-commitexists and is executable - Make sure the model
.gguffile is correctly named and placed
🤊 Too slow?
- Use smaller quantized models (e.g., Q4_K_M instead of Q8_0)
- Avoid very large models like 13B unless you have a GPU
- Check that your
text-contextandmax-tokensaren't too high
💥 Terminal frozen?
Ensure the reviewer is backgrounded correctly. This is handled automatically via the pre-commit script placed in ~/.git-hooks/.
📜 License
MIT License
🙌 Credits
Powered by llama-cpp-python and open-source GGUF models from Hugging Face, Google Drive, and the open source AI community.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file diff-reviewer-0.1.1.tar.gz.
File metadata
- Download URL: diff-reviewer-0.1.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0348ece07bd1387704c22d6ee95c29648192d4f82411c5307ccbc8e63db2f04
|
|
| MD5 |
fddec4bb68d8f455bc3415004c0d9a46
|
|
| BLAKE2b-256 |
dd4334c328f57a3a8e11f1e468fd2d260bf5b7c872115b39b474b63a585dd355
|
File details
Details for the file diff_reviewer-0.1.1-py3-none-any.whl.
File metadata
- Download URL: diff_reviewer-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08751b1e37711a37feedc11c1e5921c5ac9ba9737c2025250e741391e3f0b590
|
|
| MD5 |
2ba22cc20cc8a60c7b928a1340804e44
|
|
| BLAKE2b-256 |
0595da739e848c7cf53f627a994f41ed17206d232973dcd391b7eb12e1fb43ca
|