The problem
When I want feedback on my code, the easy option is pasting it into a
hosted AI tool. But my code is mine, and I'd rather it stayed on my
laptop. So I built a code reviewer that runs entirely on my own machine.
What I built
A small Python tool that takes my uncommitted git diff and has a local
open-weight model review it. It's about 15 lines of code.
I tested it on a small file by adding an average function with no
check for an empty list. This is what the model printed:
- Missing error handling for division by zero.
- Variable names could be more descriptive (e.g., `nums` could be `numbers`).
- No tests have been added for the new `average` function.
- Consider handling the case where the list is empty.
How it works
Three layers:
-
Weights:
qwen2.5-coder:7b, an open-weight coding model -
Runtime: Ollama, which loads the model and serves it on
localhost - Harness: my script, which gets the diff, sends it to the model and prints the review
I also packaged the reviewer's instructions as a custom Ollama model
with a Modelfile.
The code
The whole reviewer is review.py:
import subprocess, sys
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="local")
diff = subprocess.run(["git", "diff"], capture_output=True, text=True).stdout
if not diff.strip():
sys.exit("No uncommitted changes to review.")
resp = client.chat.completions.create(
model="qwen2.5-coder:7b",
messages=[
{"role": "system", "content": "You are a code reviewer. Point out bugs, unclear names and missing tests. Be short, use bullet points."},
{"role": "user", "content": diff[:12000]},
],
)
print(resp.choices[0].message.content)
The client talks to Ollama on my own machine through its
OpenAI-compatible API, so nothing goes to the cloud.
Why open matters
- Privacy: my code never leaves my computer. With a hosted tool, private or unreleased code goes to someone else's server.
- Offline: once the model is downloaded, it runs locally and doesn't need the internet.
- Cost: there is no per-token bill, so I can run it as often as I like.
One honest note: Qwen is open-weight, not fully open-source. I can
download and run the model, but the training data and code aren't public.
What I learned
The tool only reviews files git already tracks, so my first runs showed
"No uncommitted changes" until I understood why. Setting up Ollama,
Python and git took longer than writing the code itself.
Honest limits
This run found the real bug (average would crash on an empty list) and
the missing tests. But the model's answers change between runs. In an
earlier run it padded the review with generic advice about naming and
imports, in another it suggested renaming my add function instead of
fixing the bug, and in another it noticed that add subtracts but
missed a missing zero check. It also only sees what git diff shows.
Small local models are less reliable than big hosted ones, so I treat
the review as a second pair of eyes, not a verdict.
Try it
- Install Ollama and run
ollama pull qwen2.5-coder:7b python -m pip install openai- Inside any git repo with uncommitted changes, run
python review.py
What's next
Reviewing new files, saving reviews to a file, and an offline assistant
that explains medical reports and government forms in Hindi and Marathi
for people with low connectivity.
Built with @pallvibhalke4creator and @piyushalucca

Repo: https://github.com/purvabhosale3010-svg/Local-code-reviewer

Top comments (0)