AI Code Reviewer
Build a GitHub/GitLab bot that reviews PRs with explicit rules, grounded context, and quality tracking.
Design & Review Strategy
Choose model, define review rules from team history, and design the PR comment format.
Why
An AI reviewer's value is in the rules, not the model. Without explicit rules (max function length, banned APIs, security patterns), the LLM gives generic 'consider...' comments that developers ignore. Precise rules plus grounded context (diff + related code) produce actionable reviews that get resolved, not dismissed.
When
Before connecting the bot. Spend 1 week defining 10-20 rules from your team's actual review comment history.
How
Example
Common Problems
- ⚠No rules — the LLM posts generic 'consider adding a comment' on every PR, developers dismiss them within a week
- ⚠Posting a wall of text instead of line comments — developers cannot action a 20-line essay, they skim and miss real issues
- ⚠Reviewing bot PRs (dependabot) — the bot posts on the dependency bot's PRs, creating infinite comment loops
Best Practices
- ✓Mine 6 months of your team's review comments to define rules — the bot should enforce your team's standards, not generic ones
- ✓Post findings as reviewable line comments capped at 5 per PR — signal-to-noise ratio determines whether developers read the bot
- ✓Skip draft PRs and bot-authored PRs in the webhook handler to avoid noise and comment loops
Resources for this stage
Tools
Templates
Implementation & PR Integration
Build the webhook, diff parsing, and comment posting with rate limits and grounding.
Why
The webhook loop is where bots fail — posting on every push spams PRs, posting without throttling hits API limits, and posting ungrounded comments (not tied to specific lines) trains developers to ignore the bot. Batch reviews per PR and only comment on changed lines.
When
After rules produce good findings on sample diffs. Connect the webhook and run on a test repo before pointing at the main repo.
How
Example
Common Problems
- ⚠Posting on every push without dedup — a 10-commit PR gets 10 identical reviews, spamming the timeline
- ⚠Ungrounded comments (no line position) — posted as a general PR comment, developers cannot resolve them inline
- ⚠Hitting the GitHub API rate limit mid-review — the bot silently fails and the PR gets no review at all
Best Practices
- ✓Cache findings by (rule_id, diff_hash) and delete old bot comments before posting — makes re-pushes idempotent
- ✓Use the GitHub Review API to batch all comments into one review event, not individual comment posts
- ✓Queue reviews when approaching the API rate limit and process from a queue (BullMQ + Redis) instead of failing silently
Deployment & Tuning
Deploy as a serverless function or container, track review quality, and tune rules weekly.
Why
AI reviewers degrade silently — a model update changes comment style, or a new codebase pattern triggers false positives. Without tracking 'comments resolved vs dismissed' and a weekly rule review, the bot's signal-to-noise ratio drops until developers disable it.
When
When the bot posts on real PRs. Track quality metrics from day 1 and tune rules weekly based on the data.
How
Example
Common Problems
- ⚠No quality tracking — the bot posts for months, dismiss rate climbs to 80%, developers mute it and nobody notices
- ⚠Unpinned model — a silent model update changes comment tone, false positives spike, trust evaporates overnight
- ⚠No developer feedback channel — developers find the bot annoying but have no way to signal it, so they disable it silently
Best Practices
- ✓Track resolve vs dismiss rate per rule from day 1 — dismiss rate is the leading indicator of bot trust
- ✓Pin the model version and re-run on 50 historical PRs before upgrading — catch behavior changes before they hit production
- ✓Add a thumbs-down reaction to every comment and survey monthly — if helpfulness drops below 3/5, pause and review rules
Resources for this stage
Tools
Templates
Full Developer Lifecycle
A 14-stage developer roadmap from idea to maintenance — visualize dependencies and track progress.
Next Step