Multi-Pass and Multi-Instance Code Review with Claude: A Fresh Reviewer, Per-File Passes and an Integration Pass
The same session reviews its own refund code and finds nothing. A fresh instance per file finds three local notes, an integration pass finds the real bug (cents sent to a function that wants dollars), and each finding's confidence decides whether it is posted or queued for a person.
What you will learn
- Explain why the session that wrote the code is a poor reviewer of it
- Review with a fresh instance that gets only the code, with no history
- Split a pull request review into per-file passes and one integration pass across files
- Route each finding by its confidence: a PR comment or a human queue
Before you start
- Explicit criteria vs vague prompts
- Claude Messages API basics
- Basic Python
You just wrote the refund code for a shop with Claude, and in the same conversation you ask: now review your work. The answer comes back: looks good to me, no issues. Zero findings.
But refunds.py sends the amount in cents, and utils.py expects dollars. The refund is 100 times too large. The bug ships, because nobody questioned it.
The session that wrote the code is a poor judge of it. This article shows four fixes in one small script: a fresh instance, a pass per file, a pass across files, and a confidence on every finding so you know where it goes.
Why the writer misses it
Think of proofreading your own essay. The line says the refund is paid in dollers. You know what you meant to write, so your eyes slide over the mistake. Looks perfect. A friend reads it fresh. They have no idea what you meant, they read only what is on the page, and right away they ask: dollers?
A writer who reads their own work reads what they meant, not what is there. So the fix isn't trying harder. The fix is a reader who didn't write it.
It's the same with Claude. In the writing session, the conversation already holds the task, the plan and the code. The plan even says cents go to round_money. Ask that session to review, and it reads the code through its own plan. A fresh instance starts with an empty history. It gets only the code, as text, and the request to review it. With no plan to defend, it sees cents going into a function that wants dollars.
Asking the same session to "review again", or giving it extended thinking, keeps the same reasoning. An independent instance does better because it never had that reasoning in the first place. This is the same move as context isolation with subagents: what a call doesn't see can't steer it.
One big review spreads attention thin
The second problem is size. Put a whole pull request into one reviewer, everything at once, and the notes get thin: a rename here, a brief look at refunds, and for utils one note says rounding is fine while another says rounding is wrong. Attention is spread across everything and the notes can contradict each other.
So split the work into small focused passes:
- Pass 1, per file. Each file gets its own fresh reviewer and is checked for local issues only.
- Pass 2, integration. One more fresh reviewer gets all the files and is asked about one thing: how data flows between them.
A bug that lives between two files is invisible to a reviewer who sees one file. That's what pass 2 is for.
The pull request
The project keeps the three files of the pull request as text in fake_model.py, so the reviewers have something to read:
FILES = {
"orders.py": ("def total(order):\n"
" return sum(i.price for i in order.items)\n"),
"refunds.py": ("from utils import round_money\n\n"
"def refund(order):\n"
" cents = order.total_cents\n"
" return round_money(cents)\n"),
"utils.py": ("def round_money(dollars):\n"
" return round(dollars, 2)\n"),
}
Each file looks fine on its own. refund() passes cents; round_money() names its parameter dollars. You only see the problem when you look at both.
review_passes.py: three kinds of call
Every call goes through one helper that asks for findings as JSON: where, text and a confidence from 0 to 1.
FORMAT = " Reply with a JSON list: where, text, confidence 0 to 1."
def ask(system, messages):
reply = client.messages.create(
model="claude-sonnet-5-5", max_tokens=800,
system=system + FORMAT, messages=messages)
return json.loads(reply.content[0].text)
def self_review():
"""Same session: the writing reasoning is still here."""
history = [
{"role": "user", "content": "Write the refund code."},
{"role": "assistant",
"content": "Done. Cents go to round_money."},
{"role": "user", "content": "Now review your own work."}]
return ask("You review code.", history)
def file_pass(name):
"""A fresh instance sees ONE file and nothing else."""
text = f"FILE {name}\n{FILES[name]}"
return ask("Review ONE FILE for local issues.",
[{"role": "user", "content": text}])
def integration_pass():
"""Another fresh instance sees all files, for data flow only."""
text = "\n".join(f"FILE {n}\n{t}" for n, t in FILES.items())
return ask("Review data flow ACROSS FILES.",
[{"role": "user", "content": text}])
The difference between the calls is only in the messages list:
- self_review keeps the assistant turn from the writing. That's the same session, with its plan still in view.
- file_pass is a fresh instance: one new user message, one file, no history.
- integration_pass is another fresh instance: all the files, and a system prompt that asks about data flow across files and nothing else.
A narrow request like "data flow ACROSS FILES" works for the same reason a clear check does in explicit criteria vs vague prompts: the reviewer knows exactly what to look for.
Route each finding by confidence
def route(finding):
if finding["confidence"] >= 0.8:
return "comment on the PR"
return "human queue"
Sure findings go straight to the pull request. Unsure ones wait for a person. The line at 0.8 is the demo's own choice; pick the number that fits your team.
The rest of the script runs the passes and prints the routes:
print("self-review, same session:", len(self_review()), "findings")
print("pass 1: one fresh instance per file")
findings = []
for name in FILES:
found = file_pass(name)
print(f" {name:11}{len(found)} finding")
findings += found
print("pass 2: integration across files")
bridge = integration_pass()
print(f" {len(bridge)} finding")
findings += bridge
print("routing by self-reported confidence")
for f in findings:
print(f" {f['confidence']:.2f} {f['where']:28}{route(f)}")
Run it
The project uses a stand-in model: fake_model.py plugs a mock HTTP transport into the Anthropic client and returns scripted replies, so no API key is needed and every finding and confidence number is scripted. It follows simple rules that act out the pattern: a request that already holds an assistant turn gets no findings, a request whose system prompt says ACROSS FILES gets the cross-file finding, and a single-file request gets that file's local note.
if "assistant" in roles: # same session: reasoning is kept
found = []
elif "ACROSS FILES" in body["system"]:
found = BRIDGE
else:
found = next(v for k, v in LOCAL.items()
if f"FILE {k}" in last)
Running python review_passes.py:
self-review, same session: 0 findings
pass 1: one fresh instance per file
orders.py 1 finding
refunds.py 1 finding
utils.py 1 finding
pass 2: integration across files
1 finding
routing by self-reported confidence
0.55 orders.py:2 human queue
0.70 refunds.py:4 human queue
0.40 utils.py:2 human queue
0.90 refunds.py:5 -> utils.py:1 comment on the PR
- Self-review: zero findings, the same answer the writing session always gave.
- Pass 1: one local note per file. In the scripted replies these are an empty items list not handled (orders.py), no check that the order was paid (refunds.py), and
round()using banker's rounding (utils.py). - Pass 2: the cross-file bug,
refunds.py:5 -> utils.py:1, with the text "refunds sends cents, round_money wants dollars". - Routing: 0.90 is above the line, so it becomes a comment on the PR. The three local notes are below it, so a person looks at them.
Common mistakes
- Reviewing in the writing session. The plan is still in the messages, so the review reads what was meant.
- "Review again" or more thinking time. Same session, same reasoning. Start a new instance instead.
- One giant review of the whole pull request. Attention spreads thin and notes can contradict each other.
- Per-file passes only. Each file looks fine alone; the cents-vs-dollars bug lives between two of them. Add the integration pass.
- Posting every finding. Without a confidence on each one, the sure and the unsure land in the same place.
Recap
| Step | What the reviewer sees | In the run |
|---|---|---|
| Self-review | The writing session, plan included | 0 findings |
| Pass 1, per file | One file, no history | 1 local note per file |
| Pass 2, integration | All files, data flow only | Cents sent, dollars expected |
| Routing | Each finding's confidence | 0.90 to the PR, three to the human queue |
Exam lens: when a model missed an issue in its own output, choose a second independent instance; when a large review misses cross-file problems, choose per-file passes plus an integration pass.
Try it yourself
Add a fourth file to FILES, say a receipts.py that calls refund(), give it a local finding in LOCAL, and run again to see it get its own pass. Then move the line in route() from 0.8 to 0.5 and watch which findings move from the human queue to the PR.
Related course on Udemy
Claude Certified Architect - Foundations (CCAR-F) Exam Prep
Agentic loops, tools, MCP, Claude Code, prompts, structured output and context.View on Udemy ↗: Claude Certified Architect - Foundations (CCAR-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.
