Written by the Miracuves Editorial Team. Reviewed by Aditya Bhimrajka, Founder & CEO, Miracuves.
Key Takeaways
- The model is the easy part Signed intake, idempotent jobs and explicit states decide whether each review arrives once and on time. GitHub does not redeliver a webhook your server failed to answer.
- Context and linters before the model Chunk diffs by function, add a small context pack, and let deterministic analyzers handle routine issues so the model can judge logic and intent.
- Few comments keep the reviewer read Score, deduplicate and cap findings per pull request, then tune each repository’s threshold from acceptance data.
- Every pull request is untrusted input Redact secrets before any model call, isolate each job and give the reviewer no power to approve, merge or push.
- Own it only when the constraints are real Data residency, scale, domain rules or selling review as a product justify building; otherwise a subscription is usually cheaper.
An AI code reviewer can lose its audience within a month. In the first week, people read every comment. By the end of the month the bot is leaving fifteen notes on a 40-line change, half of them about naming, and engineers scroll past all of them, including the one that would have caught a real bug.
If you lead engineering at a software company, or you want review built into a developer product you sell, this article is for the decision that comes next: build your own reviewer or keep renting one. By the end you should know whether owning one is worth it and, if it is, what to build first and what it costs.
One conclusion up front: the model is the easy part. The comments engineers keep reading come from the plumbing around it.
From pull request event to one posted review
Every review starts with a webhook. When a developer opens a pull request, pushes to it or marks it ready for review, your Git host calls an endpoint you control. What happens in the next few seconds decides whether each review arrives once, on time, or not at all.
Intake: verify, queue, answer fast
The intake service should do three things only: check the signature, write the event to a durable queue and return a 2xx response. GitHub expects that response within 10 seconds, counts a slower one as a failed delivery and, in its own words, does not automatically redeliver failed deliveries. A slow intake on GitHub therefore loses reviews rather than duplicating them. GitLab tells receivers to expect duplicate deliveries after timeouts and temporarily disables a webhook after four consecutive failures. Design for both problems: events that never arrive and events that arrive twice.
Build an idempotency key from the repository, the pull request number and the head commit SHA, and drop any event whose key you have already processed. If a new head SHA arrives while an older review is still running, cancel the older job, because comments on replaced code are pure noise. A scheduled sweep that lists open pull requests and compares each head SHA with your last review catches whatever the webhooks missed.
Give the review job explicit states
- Received: the event is queued with its idempotency key.
- Skipped: the pull request is a draft, touches only lock files or generated code, or the repository has the reviewer switched off.
- Fetching: a worker pulls the diff and the files it needs with a short-lived token scoped to that one repository.
- Analyzing: linters, type checkers and a secret scanner run on the changed files.
- Reviewing: the model reviews each chunk with its context and returns candidate findings.
- Ranking: candidates are deduplicated, scored and cut down to a small set.
- Posted: the findings land on the pull request as one review with a short summary.
- Superseded or Failed: a newer commit arrived, or a step failed and the error was logged without copying source code into the log.
States give you something to alert on and a clean place to measure latency, which matters: a comment that lands after a human approved the change was paid for and ignored. The diagram below shows the six stages a job passes through when all goes well, Received through Posted. Skipped, Superseded and Failed are the exits a job can take instead, which is why the list has more entries than the diagram.

Post one review, not a stream of comments
Bundle the findings into a single review so the author gets one notification, and anchor each comment to a line in the new version of the file. On GitHub, one call with the COMMENT event and a comments array does this; leave the event empty and you get a pending review that your bot must submit separately. Never use APPROVE or REQUEST_CHANGES: a bot that can block or approve a merge holds more power than it needs. On later pushes, resolve or update earlier comments instead of repeating them.
What GitHub, GitLab and Bitbucket each expect
The install model, signature check and comment API differ by host, so write one adapter per host behind a common interface. Details checked against each host’s documentation in November 2026:
| Step | GitHub | GitLab | Bitbucket Cloud |
|---|---|---|---|
| Install model | A GitHub App installed per organization or repository, with fine-grained permissions | A project or group webhook plus a bot user or project access token | A repository or workspace webhook plus an app or access token |
| Events to subscribe to | pull_request (opened, synchronize, ready_for_review) | Merge request events (open, update) | pullrequest:created and pullrequest:updated |
| Verifying the sender | HMAC-SHA256 signature in the X-Hub-Signature-256 header; X-GitHub-Delivery identifies each delivery (docs) | A signing token (GitLab 19.0 and later) adds an HMAC-SHA256 signature in the webhook-signature header; the older X-Gitlab-Token header only carries the secret in plain text (docs) | HMAC-SHA256 signature in the X-Hub-Signature header when a secret is set (docs) |
| Posting line comments | One review with a comments array, pinned to a commit_id (reviews API) | A discussion per finding, with a position that needs the base, start and head SHAs plus the old and new file paths (discussions API) | Pull request comments anchored to a file path and line |
| Status surface | A check run with a summary and annotations, at most 50 annotations per API request; only GitHub Apps can create check runs (checks API) | A commit status or a pipeline job result | A build status on the commit |
| Token lifetime | Installation tokens expire after one hour and can be limited to named repositories (docs) | Set by the token you issue; rotate it on a schedule | Set by the token you issue; rotate it on a schedule |
GitHub App or CI step? A GitHub Actions job is the quickest way to try a reviewer on one repository. At scale it burns CI minutes, waits behind builds, needs model credentials stored as CI secrets wherever it runs and cannot easily keep a shared index or feedback history. Past a handful of repositories, an app backed by your own service is the better shape.
What the model sees decides what it says
Most of the gap between a useful reviewer and an annoying one is the input. A raw diff leaves the model guessing about everything outside the changed lines; the whole repository buries the signal in tokens you pay for.
Chunk by meaning, not by line count
Split the diff along code structure. A parser such as Tree-sitter can tell you which function, method or class each changed hunk belongs to, so you send the whole enclosing function instead of a fragment that starts mid-loop. Group small related hunks in one file into a single chunk, and split very large files at function boundaries so each chunk stays inside your token budget.
Decide early what never gets reviewed: generated clients, vendored dependencies, minified bundles, snapshots and tool-generated migrations. A per-repository config file of ignore patterns saves money and removes a whole class of silly comments.
Build a small context pack for each chunk
- Signatures and docstrings of the functions the changed code calls, found through a symbol index.
- Callers of any function whose signature or behavior changed, because that is where breakage shows up.
- Type definitions, interfaces and schema files the change touches.
- The team’s written conventions: a short review guide kept in the repository, not a 40-page wiki.
- The pull request title, description and linked ticket text, so the model can check whether the code does what the author says it does.
A symbol index rebuilt whenever the default branch changes is usually enough; embedding search for similar code can come later. Save the assembled prompt inputs, or a hash and a pointer, with every finding. When an engineer says a comment is wrong, you need to know whether the model lacked context or misread context it had, because those failures have different fixes.
Let linters catch the routine and the model judge intent
A language model is a poor linter: slower, costlier per check and not repeatable. Linters, type checkers and pattern-based security scanners already catch unused imports, type mismatches and unsafe calls every time, so run them first, on the changed files, inside the review job. This matters more as assistants write a larger share of each diff, since security gaps in AI-prompted code tend to repeat exactly the unsafe patterns scanners are built to catch.
The model then does what rule engines cannot: it can notice that a function name promises one thing and the body does another, that a retry loop has no backoff, that an error is swallowed in a payment path, or that a new endpoint skips the authorization check every sibling endpoint performs.
Pass the analyzer results into the prompt as structured data, tell the model which issues are already flagged so it does not repeat them, and ask whether each one matters in this change. Reuse the repository’s existing ESLint or Ruff configuration: the reviewer should enforce the team’s standards, not its own.
Ask for findings, not prose
Have the model return JSON with fixed fields: file, line range, category (bug, security, performance, readability, test gap), severity, confidence, a one-sentence explanation and an optional suggested patch. Validate the output against a schema and discard anything that points at a line outside the diff. Free-text reviews are hard to rank and impossible to measure.
One diff, one comment: a worked example
Here is what the pipeline should produce for a small change to a refund function. The author tightened the check so a refund cannot exceed the amount not yet refunded, but in the same edit removed the line that records the refund.
def refund(order_id, amount):
order = Order.get(order_id)
- if amount > order.total:
- raise ValueError("refund exceeds order total")
+ if amount > order.total - order.refunded:
+ raise ValueError("refund exceeds remaining balance")
gateway.refund(order.charge_id, amount)
- order.refunded += amount
order.save()
The linters pass, since nothing is syntactically wrong. The context pack includes the Order model, which shows that refunded is a stored running total, and the two callers of refund(). The model returns one structured finding:
{
"file": "billing/refunds.py",
"line_start": 8,
"line_end": 8,
"category": "bug",
"severity": "high",
"confidence": 0.86,
"explanation": "order.refunded is no longer updated, so the new remaining-balance check never sees refunds made here and repeat refunds can exceed the order total.",
"suggested_patch": " order.refunded += amount"
}
Ranking keeps it because it is a high-severity finding in a payment path, and the posted comment reads: “This removes the update to order.refunded, so the new remaining-balance check never sees refunds made here and repeat refunds can exceed the order total. Restore the increment before save().” That is the bar: one specific, checkable comment a senior engineer would have wanted to write.
Stamp the prompt and schema version on every finding, so a later rise in rejected comments can be traced to a prompt edit, a model update or a change in your code.
Fewer comments, chosen better
Volume is what gets a reviewer muted. Ranking is not a finishing touch; it is the part of the system that decides whether people trust it. Score each candidate on a few signals and keep only the top results:
- Severity: a likely bug or security issue outranks a naming nit every time.
- Model confidence: ask for it explicitly, then calibrate it against how often findings at that level were accepted.
- Agreement: a finding raised by both a static analyzer and the model is stronger than either alone.
- Historical acceptance: how often this category was accepted in this repository over recent weeks.
- Location: authentication, billing and data deletion code deserve a lower bar than a test helper.
Then apply a hard cap per pull request, scaled to the size of the change. Merge near-duplicates: if the same missing null check appears in six places, post one comment that lists the six lines. Move low-priority style points into a collapsed summary or drop them.
Teams want different bars. A payments team may want every possible concern raised; a team shipping internal tooling may only want blocking bugs. Make the threshold and the cap configurable per repository, and log every change to those settings so you can explain later why the reviewer went quiet.
Learning from the comments engineers reject
Every reviewer writes wrong comments. One that improves records those mistakes and acts on them, and this is where owning the pipeline pays off most.
Capture signals without asking for forms
Give each comment helpful and not-helpful reactions with an optional reason: wrong, handled elsewhere, intentional, too minor. Add implicit signals: was the suggested patch applied, did the flagged lines change in the next commit, was the comment resolved with no code change? Stored on the finding record next to the category, prompt version and context reference, that becomes a clean dataset nobody had to fill in.
Fix the cheap things before fine-tuning
- Suppress patterns a repository has rejected repeatedly, with an expiry date so each suppression gets reviewed.
- Add accepted and rejected examples from that repository to the prompt as short few-shot references.
- Re-weight categories in the ranking step by acceptance rate.
- Turn recurring accepted findings into deterministic lint rules, so the model stops spending tokens on them.
- Only then consider fine-tuning or preference training on a self-hosted model, using the labeled findings.

Keep an evaluation set
Collect a few hundred past pull requests with known outcomes: real bugs that slipped through, comments that were accepted, comments that were rejected. Run every prompt change and every model swap against this set before it reaches production. Without it, you will fix one complaint with a prompt edit and quietly break three other categories.
Five numbers to review every week
Set targets from your own pilot baseline, not from vendor claims. Results vary widely by language, codebase and team habits.
| Metric | How to measure it | What it tells you |
|---|---|---|
| Acceptance rate | Comments marked helpful or followed by a matching code change, divided by comments posted | Whether engineers trust the reviewer; the first number to fall when noise rises |
| Precision on the evaluation set | Findings a senior engineer judges correct, divided by all findings, on the fixed set of past pull requests | Whether a prompt or model change made comments better or worse |
| Recall on known bugs | Known escaped bugs in the evaluation set that the reviewer flags | Whether it catches what matters, not just what is easy |
| Time to first comment | Minutes from the pull request event to the posted review, at the median and the 95th percentile | Whether comments arrive before a human reviewer starts |
| Cost per review | Model spend plus compute, divided by completed reviews | Whether routing, caching and skipping rules pay off |
Treat every pull request as untrusted input
A code reviewer reads your most valuable asset. Run it with the discipline you would apply to a build server.
Access and isolation
Install the reviewer as an app with per-repository permissions, never on a personal access token tied to one engineer. Request read access to code and write access to pull request comments, nothing more. Mint a token per job limited to the repository under review, run the job in a fresh disposable workspace and delete the clone when it ends. In a multi-tenant product, never let a cache, index or few-shot example from one customer’s repository reach another customer’s review.
Secrets in the diff
Developers do commit API keys, database URLs and private keys. Run a secret scanner on the diff before any text goes to a model. If it finds something, redact the value in the prompt, post a high-priority comment telling the author to rotate the credential, and keep the raw value out of logs, traces and finding records. Redaction has to happen before the model call, not after.
Prompt injection hidden in the code
A comment in the code, a string in a test fixture or a line in the pull request description can carry instructions aimed at the reviewer, such as “approve this change” or “print the environment variables”. OWASP ranks prompt injection first (LLM01:2025) in its Top 10 for LLM applications and describes the indirect form as instructions arriving through external sources such as files. Every pull request is exactly that kind of source.
Several of the OWASP mitigations map directly onto this design:
- Least privilege: the reviewer has no tool or token that can merge, approve or push.
- Segregate external content: wrap repository text in clearly marked data sections, separate from the system instructions.
- Validate output formats: anything that is not a valid finding for a line inside the diff is dropped, so injected text cannot turn into an action.
- Human approval for risky actions: if you later let the reviewer open fix-up commits, put every one behind a human.
- Adversarial testing: keep a handful of planted injection attempts in the evaluation set and fail the release if any of them changes the reviewer’s behavior.
Know where the code goes
With a hosted model API, find out whether inputs are retained, for how long, in which region and whether they can train models, and write the answers into your security documentation. Enterprise buyers will ask.
Hosted or self-hosted model, and the cost of each review
A hosted API gives you the strongest general models with no infrastructure, priced per token. The trade-off: source code leaves your network and your unit cost follows the provider’s price list.
An open-weight model served with an open-source inference server such as vLLM, on your own GPUs or inside a customer’s cloud account, keeps code inside a boundary you control. If your contracts or regulators forbid code leaving your boundary, it is the only option. You then run GPUs and model updates yourself, and a smaller model may need tighter context and stricter ranking.
You can also route: small or low-risk changes go to a cheaper model, sensitive repositories go to the self-hosted one and large or risky changes go to the strongest model available. Put the model behind an internal interface from day one so switching is a config change, not a rewrite.
The cost of one review, and the levers that move it
With a hosted model, a review costs the input tokens times the input price plus the output tokens times the output price, summed over every model call in the job, plus compute for cloning, indexing and static analysis, plus retries. With a self-hosted model, the token line becomes GPU hours divided by the reviews those hours served. The levers, roughly in order of effect:
- Skip work: drafts, generated files, dependency bumps and documentation-only changes rarely need a model.
- Review incrementally: on a new push, review only the commits since the last review, not the whole pull request again.
- Keep context packs tight: signatures instead of whole files, and a hard token budget per chunk.
- Order the prompt for caching: provider caches match on an exact prefix, so instructions, conventions and the schema go first and the diff goes last. OpenAI’s prompt caching guide, for example, requires the whole rendered prefix to match and sets a 1,024-token minimum for GPT-5.6 and later models.
- Route by difficulty: easy chunks go to a smaller model, complex or risky code to the large one.
- Keep outputs short: structured findings with one-sentence explanations cost far less than paragraphs of prose.
Report cost per review, per repository and per team from week one. It is the number you will compare against a per-seat subscription.
Should you rent a reviewer or own one?
A subscription may well be the right answer. A rented tool installs in an afternoon, needs no infrastructure and improves as the vendor ships. Owning the system makes sense only when the constraints in the right-hand column actually apply to you.
| Decision factor | Renting fits when | Owning fits when |
|---|---|---|
| Where code may go | Your security policy allows a third party to process source code under its data terms. | Code must stay in your cloud account or on-premises, or customers contractually forbid third-party processing. |
| Team size and spend | A small team where per-seat pricing stays modest. | A large engineering org where seat licenses cost more than running your own pipeline. |
| Review rules | General best practices are good enough. | The reviewer must enforce domain rules: internal frameworks, data handling, regulatory logic. |
| Noise and model control | The tool’s settings keep comments at a level your team accepts, on whatever model the vendor picks. | You need your own ranking and feedback loop per repository, or to choose, route or self-host models. |
| Product strategy | Code review is an internal productivity aid. | Code review ships as a feature of your own developer tool, IDE product or platform. |
| Ongoing ownership | Nobody can maintain prompts, evaluations and infrastructure. | You can name an owner for the pipeline, its evaluation set and its costs. |
Take the last row seriously: models change and prompts drift, and a neglected in-house reviewer does more harm than a rented one. The strongest case for building is when review is part of a product, such as a white-label AI app builder that generates code for its users and must check it before it ships, or a platform team serving hundreds of internal repositories.
Build order, team and budget for a first release
Avoid building everything at once. Ship in this order, so each phase produces something engineers can see and judge. The week ranges are planning assumptions for one Git host, not industry norms.
- Pipeline skeleton (2-3 weeks): webhook intake, signature check, queue, job states and a single summary comment. No model yet.
- Static analysis pass (1-2 weeks): the repository’s own linters and a secret scanner on changed files, results posted.
- Model review (3-4 weeks): chunking, a basic context pack, structured findings, schema validation and line anchoring.
- Ranking and caps (2-3 weeks): scoring, deduplication and per-repository thresholds.
- Feedback and evaluation set (2-3 weeks, in parallel): reactions, implicit signals and a regression run for every prompt change.
- Admin panel (3-4 weeks, in parallel): repository settings, cost reports, model routing rules and an audit log of configuration changes.
- Pilot (3-4 weeks): two or three repositories with engineers who give blunt feedback, and a weekly review of the five numbers above. If acceptance is low, fix ranking and context before adding features.
With the parallel phases, that is about 12 to 20 weeks to a first release. A self-hosted model path adds roughly 3 to 6 weeks, mostly for GPU capacity, serving and quality tuning.
An illustrative in-house budget
Assumptions: an in-house US team building the release above, with a hosted model API. The hourly rate starts from the BLS median wage for software developers, $135,980 a year in May 2025 or about $65 an hour over 2,080 hours. Wages were 70.0% of private-industry employer compensation costs in June 2026 (BLS), which grosses that up to a loaded rate of about $93 an hour, applied to every role for simplicity.
| Role | People | Weeks | Person-weeks |
|---|---|---|---|
| Backend engineers (intake, jobs, chunking, ranking, host adapter) | 2 | 12 | 24 |
| Machine learning or prompt engineer (prompts, evaluation set, routing) | 1 | 12 | 12 |
| Web engineer (admin panel and cost reports) | 1 | 8 | 8 |
| DevOps engineer (isolated workspaces, secrets, monitoring), half time | 0.5 | 12 | 6 |
| QA engineer | 1 | 8 | 8 |
| Product or project manager, half time | 0.5 | 14 | 7 |
| Total | 65 (2,600 hours) |
At about $93 an hour, 2,600 hours comes to roughly $243,000. An internal-only reviewer for one host with no admin panel, near 30 person-weeks, lands around $112,000. A multi-host product with a self-hosted model path and multi-tenant isolation, near 110 person-weeks, lands around $411,000. After launch, keeping prompts, evaluations and model versions current takes about half an engineer, roughly $97,000 a year at the same rate, plus model or GPU spend that grows with review volume.
These are illustrative estimates, not quotes. They exclude recruiting, model and GPU costs, hosting and audits. Use the structure to compare proposals line by line.
Hold the reviewer’s own code to the standard it enforces. NIST’s Secure Software Development Framework, SP 800-218 (version 1.1, February 2022) is a practical checklist; as of November 2026 its version 1.2 is still a draft, and the companion profile SP 800-218A covers generative AI models.
Where Miracuves fits
Miracuves builds custom AI software alongside its ready-made platforms, and a code reviewer is the kind of project our AI agent development team scopes from the pipeline outward: signed intake with idempotent jobs, function-level chunks from a symbol index, your own linters in front of the model, ranking with per-repository caps, and the feedback capture and regression set that keep comment quality from drifting. You receive the complete source code, prompts and evaluation data included, and where diffs cannot leave your network the model runs inside a cloud account you control.
If your customers ask about SOC 2 or ISO 27001, we build to the controls and take you through the audit with an independent partner; any report or certificate is issued to your company. Bring your repository count, your rules on where code may travel and a few comments your engineers keep dismissing. We will quote it, or tell you plainly if a subscription fits better for now.
Frequently Asked Questions
How does an AI code review tool work?
It receives pull request events from your Git host, collects the changed code plus a small amount of repository context, runs your linters and a secret scanner, and asks a language model for structured findings. A ranking step keeps only the most important ones and posts them as a single review. Good systems also record which comments engineers accept or reject and use that to cut noise over time.
Can an AI code reviewer replace human code review?
No. It works best as a first pass that catches likely bugs, missing checks and test gaps before a person looks at the change. Design decisions, product trade-offs and final approval should stay with your engineers. The reviewer itself should have no permission to approve, merge or push code, which also limits the damage a prompt injection can do.
How do you stop an AI reviewer from leaving too many comments?
Score each finding on severity, model confidence, agreement with static analysis and past acceptance in that repository. Merge duplicates into one comment, apply a hard cap per pull request scaled to the size of the change, and move style points into a collapsed summary. Let each repository set its own threshold and watch the acceptance rate weekly.
Is it safe to send private source code to an LLM for review?
It can be, if you control the data path. Use short-lived tokens limited to one repository, redact secrets before any model call and read the provider’s terms on retention, region and training use. If code may not leave your network, run an open-weight model in your own cloud account and keep every review in a disposable, isolated workspace.
Should an AI code reviewer run as a GitHub App or a GitHub Action?
An Actions workflow is the quickest way to try a reviewer on one repository because there is nothing to host. A GitHub App backed by your own service scales better: it uses installation tokens that expire after an hour, can create check runs, keeps model credentials out of each repository and holds the shared index, feedback history and settings that improve reviews.
How much does it cost to build an AI code review tool?
As an illustrative estimate, an in-house US team building a first release on one Git host needs about 65 person-weeks, roughly $243,000 at a loaded rate near $93 an hour derived from BLS wage and compensation data. A narrow internal reviewer can come in near $112,000. Each review then costs model tokens or GPU time plus compute for cloning and analysis.
Miracuves is an independent software development company. We are not affiliated with, connected to, sponsored by, or endorsed by any company or product named in this article.
Terms such as “X Clone” are used descriptively. It is how the software industry refers to building a platform with functionality comparable to a known service, and how clients search for it.
The entire design and codebase of our products is built by our own team. Our products contain no code, design, graphics, or content originating from any third-party website or applications.
All third-party names and marks referenced in this article are the property of their respective owners, referenced solely to identify the services discussed.


