AI Code Review That Earns the Right to Block: Shadow Mode, Calibration Against Human Review, Then a Gate
Make Claude Code a required reviewer on day one and two of every three blocks are noise. Run it in shadow mode on a SupportDesk pull request, label 13 findings with the human verdict (high: 100% agreement, medium 50%, low 25%), then gate only on high. A missing cap fails the check; a low finding after the fix does not.
What you will learn
- Explain why an AI reviewer that blocks on every finding from day one floods the team
- Run Claude Code review in shadow mode: post inline comments that never fail the check
- Calibrate each severity against human review with agreement and false-alarm rates
- Switch to gate mode with a required status check that blocks only on the severity that earned it
Before you start
- A Claude Code review bot in CI
- GitHub Actions and branch rules
- Basic Python
An AI reviewer can read every pull request. The real question is when it should block a merge.
Our answer comes in three stages: shadow mode, then calibration against human review, then a gate. We'll follow all three on GitHub, with Claude Code reviewing a SupportDesk change: pull request #2, goodwill refunds for late orders.
A reviewer that blocks on day one
Here is the tempting setup. On day one, the team makes the AI reviewer a required check, and every finding blocks the merge. A pull request comes in and the reviewer finds three things. One is real: the code logs the customer's email. The other two are noise: the prompt wording could be clearer, and a variable should be renamed. (Those two are sample findings for the example.) All three block. So two of the three blocks are false alarms, and the team learns to ignore the reviewer.
Think of a new hire joining the code-review rota. At first they shadow: they review every pull request but sign nothing. Then they compare notes with a senior reviewer: where did they agree, and where were they wrong? Only then do they sign off, and only on the kind of issue they've proven they get right. Trust is earned on the record, not granted on day one.
The review job
The workflow runs Claude Code headless on the diff, asks for JSON findings that match a schema, and hands them to a small script. The relevant step:
- name: Review the diff with claude -p
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
git diff origin/${{ github.base_ref }}...HEAD > pr.diff
claude -p "$(cat .github/review_prompt.md)" \
--output-format json \
--json-schema "$(cat .github/review_schema.json)" \
--allowedTools "Read,Grep,Glob" \
--model sonnet --max-budget-usd 0.50 > review.json
Read-only tools, a JSON schema and a spend cap. The review bot in CI article covers this job in depth. This review ran for real on GitHub Actions; the SupportDesk app inside the repo still answers with a stand-in model, so its own tests need no API key.
post_comments.py: one switch, shadow or gate
"""Read the JSON from claude -p and post each finding as an inline PR comment.
REVIEW_MODE=shadow: post, never fail. REVIEW_MODE=gate: fail on any high finding."""
import json, os, subprocess, sys
out = json.load(open(sys.argv[1], encoding="utf-8"))
review = out.get("structured_output") or json.loads(out["result"])
findings = review["findings"]
mode = os.getenv("REVIEW_MODE") or "shadow"
for f in findings:
body = f"**{f['severity']}** {f['message']}"
if mode == "shadow":
body += ("\n\n_AI review in shadow mode: "
"this does not block the merge._")
print(f"{f['file']}:{f['line']} "
f"[{f['severity']}] {f['message']}")
# ... posts body as an inline comment with gh api, skipping ones already posted
high = [f for f in findings if f["severity"] == "high"]
print(f"{len(findings)} findings, {len(high)} high, "
f"mode {mode}")
if mode == "gate" and high:
print("gate: a high finding blocks the merge")
sys.exit(1)
(Excerpt; the full script also skips comments it already posted.)
- The mode comes from a repository variable,
REVIEW_MODE, and the default is shadow. - Each finding becomes an inline comment, severity first. In shadow mode one more line says it doesn't block.
- Every finding is also printed to the job log.
- Only in gate mode, and only on a high finding, does the script exit with 1 and fail the check.
Stage 1: shadow mode on pull request #2
The GitHub Actions bot posted the review as inline comments on the changed lines. The job log (trimmed to the printed findings):
supportdesk/refunds.py:16 [high] The goodwill bonus is added on top of the percent refund with no cap, so the refund can exceed the order total (e.g. 100% plus a bonus).
supportdesk/refunds.py:17 [high] This logs the customer's email, which violates the privacy rule; log the customer id instead.
tests/test_refunds.py:23 [low] The test asserts 25.0 but order_total is 40.00, so 50% plus a 5 bonus is 25.0 and passes. It never covers the cap case where the refund exceeds the order total, which is the rule that matters.
3 findings, 2 high, mode shadow
Two high findings and one low, and the check passed, because shadow mode never fails. Then the human side: the repository owner reviewed the same pull request and agreed on both high findings (the cap, and the email log they had missed too). That review comment is the label we need: for each AI finding, did the human agree?
Stage 2: calibrate against human review
Each shadow finding gets the human verdict: agree, disagree or no reply. Rows 1 to 3 are PR #2's real shadow findings; the other ten are sample labels, so the example has enough rows to show the idea.
"""Calibrate the AI reviewer against human review, using the shadow-mode labels.
Each row is one finding posted in shadow mode, and what the human reviewer said."""
import json, pathlib
# the team's bar: a severity may block a merge
# only if humans agreed with it this often
BAR = 0.9
SEVERITIES = ["high", "medium", "low"]
path = pathlib.Path(__file__).with_name("shadow_labels.json")
rows = json.loads(path.read_text(encoding="utf-8"))
real = sum(r["source"] == "PR #2" for r in rows)
print(f"{len(rows)} shadow findings ({real} from PR #2, the rest sample labels)")
wrong = sum(r["human"] == "disagree" for r in rows)
print(f"if every finding blocked: {wrong} of {len(rows)} would be false alarms")
blocking = []
for sev in SEVERITIES:
group = [r for r in rows if r["severity"] == sev]
agree = sum(r["human"] == "agree" for r in group)
disagree = sum(r["human"] == "disagree" for r in group)
agreement = agree / len(group)
false_alarms = disagree / len(group)
blocks = agreement >= BAR
if blocks:
blocking.append(sev)
verdict = "can block" if blocks else "comment only"
print(f"{sev}: {len(group)} findings, agreement {agreement:.0%}, "
f"false alarms {false_alarms:.0%} -> {verdict}")
rule = " and ".join(blocking) or "nothing"
print("gate: block the merge on", rule)
$ python calibration/calibrate.py
13 shadow findings (3 from PR #2, the rest sample labels)
if every finding blocked: 4 of 13 would be false alarms
high: 5 findings, agreement 100%, false alarms 0% -> can block
medium: 4 findings, agreement 50%, false alarms 50% -> comment only
low: 4 findings, agreement 25%, false alarms 50% -> comment only
gate: block the merge on high
- Agreement is the share of findings the human agreed with. False alarms is the share they disagreed with. "No reply" counts as neither.
- If every finding had blocked, 4 of the 13 blocks would have been false alarms.
- The bar is the team's, 0.9. Only high clears it, so the rule is: block the merge on high.
Stage 3: the gate
Two switches turn it on. The repository variable REVIEW_MODE is set to gate. And in the branch rule on main, require status checks to pass before merging is ticked, with claude-review listed as required next to the eval gate.
A new commit on the same pull request still has no cap on the goodwill refund. The job log:
supportdesk/refunds.py:17 [high] goodwill_refund adds a bonus on top of the percent refund with no cap, so the refund can exceed order_total (e.g. 100% plus a bonus), violating the rule that a refund never exceeds what the customer paid.
posted as an inline comment
1 findings, 1 high, mode gate
gate: a high finding blocks the merge
##[error]Process completed with exit code 1.
The check fails, it is required, so the merge button is greyed out. Then the fix lands: the refund is capped at the order total. The reviewer runs again:
supportdesk/refunds.py:15 [low] `bonus` is not validated, so a negative bonus can make the goodwill refund negative (the cap only guards the upper bound).
posted as an inline comment
1 findings, 0 high, mode gate
One low finding, posted as a comment. All checks pass and the merge button is enabled. A low finding informs the reviewer. It doesn't block. And a person still approves the merge.
Common mistakes
- Gating on every finding from day one. The team drowns in false alarms and starts to ignore the check.
- Staying in shadow mode for good. Nothing is ever enforced, even the findings the reviewer gets right every time.
- Letting the AI approve and skipping human review. The gate can block; only a person approves (see Claude code review in the SDLC).
- Calibrating on a handful of findings. This example uses 13 rows, ten of them sample labels, to show the method. A real shadow period needs many more before a severity earns the right to block.
- Setting the mode in the workflow file. A repository variable lets you switch shadow and gate without a code change.
Quick recap
| Stage | What changes | In this run |
|---|---|---|
| Shadow | Comments only, the check never fails | 3 findings, 2 high, check passed |
| Calibrate | Agreement and false alarms per severity, against a bar | high 100%, medium 50%, low 25%; bar 0.9 |
| Gate | REVIEW_MODE=gate + required status check | missing cap: blocked; after the fix: low only, merge enabled |
| Approval | Always a person | the owner reviewed PR #2 |
Try it yourself
Add five more medium findings to shadow_labels.json, all marked agree. Predict medium's new agreement before you run calibrate.py, and whether it now clears the 0.9 bar. If it doesn't, how many more agreed findings would it take?
Related course on Udemy
Claude Certified Developer - Professional (CCDV-P) Exam Prep
Claude agents in production: reliability, observability, evals, cost, guardrails and fleets.View on Udemy ↗: Claude Certified Developer - Professional (CCDV-P) Exam Prep (paid course, opens in a new tab)Related posts
CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
Three needs in one repo: a test command, a rule that Claude must never read .env, and a shared deploy skill. See which file each belongs in, how the settings layers merge, and what a plugin manifest carries.
Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
Pack a support team's ticket-triage routine into one skill folder, then watch three requests load one, two or all three levels: the catalog, the SKILL.md body, and a script whose code never enters the context.
One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
Change one line in a repo and ask where it lands. A small resolver for bookshop-bot shows that a new model id in settings.json reaches only CI, a prompt bump reaches dev and CI, and a prod block edit reaches only prod.
Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
Follow one prompt edit from a branch to a merge: version prompts and the model pin like code, keep the API key in GitHub Secrets, gate changes by path, let Claude review the diff, and leave the merge to a person.
