الانتقال إلى المحتوى
Claude وأدوات الـ AI للبرمجةClaude Code· 6 دقائق للقراءة

Don't Let the Author Grade Its Own Work: Reviewing AI-Generated Code

A same-session review shares the assumptions behind the bug. Review from a fresh context, then fix only what a failing test proves.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • Claude Code 2.x
محتويات المقال

A developer spends an afternoon with Claude on a retry wrapper for the payments client. Early on, Claude reasons that "the provider deduplicates charges, so retrying is safe", and nobody questions it. At the end the developer types "review your changes carefully and fix every issue you find". Seven findings come back: a vague variable name, a missing doc comment, an interface worth extracting, null checks for a value that is never null, a test for a negative timeout. Claude fixes all seven, and the diff grows from 90 lines to 260. The one real bug survives: the wrapper retries POST /charges on a timeout without an idempotency key, so a slow response can charge a customer twice.

The common misconception

"Asking the same session to review its own changes, and fixing everything it reports, is a thorough code review." It sounds right for good reasons:

  • Claude is a strong reviewer, and it's the same model either way.
  • The session has the most context: the requirements, the edge cases, why every line is there.
  • A list of findings feels like rigor, and fixing all of them feels like diligence.
  • Self-review before opening a PR is good practice for people too.

The half-truth: a same-session pass does catch slips, like a typo or a forgotten await. But the context that makes it informed is the same context that makes it blind, and a pile of findings isn't the same as the right ones.

What actually happens

The author's reasoning is the blind spot

In the same session, the reviewer reads the diff next to every decision that led to it. "The provider deduplicates charges" is already in the context as a settled fact, so the review checks the code against that belief instead of checking the belief. The Claude Code docs say what an independent reviewer buys you: it "isn't swayed by the reasoning that produced the code", and "a fresh reviewer does help, because it hasn't seen your reasoning".

Research on LLM evaluators points the same way. A study of found "an LLM evaluator scores its own outputs higher than others'" while human annotators judged them equal. It graded text summaries, not code, but it's one more reason not to let the author grade its own work.

Fresh context, not a smarter model

/code-review gets you independence without extra setup. In a terminal session it runs as a background with its own context window; the docs describe it as "a fresh subagent that never saw your conversation". With no target it reviews your branch's commits ahead of upstream plus uncommitted changes, it follows your CLAUDE.md, and the findings arrive in your conversation when it finishes.

Independence isn't extra intelligence, though. The docs are blunt that by default a subagent is "the same model (or a smaller one) on the same task. You get parallelism or a fresh pair of eyes out of it, but not a smarter answer." A review is still Claude deciding. In the docs' own split, /code-review sits on the non-deterministic side, while tests, a typecheck, a Stop hook and CI are enforced, and "a person who approves the merge" has the last word.

A reviewer asked for problems always finds some

The second half of the myth does as much damage. The docs warn: "A reviewer that's asked to find problems will always find something. If you fix every finding, you end up with extra abstraction layers and tests for cases that can't happen." That's the 260-line diff. /code-review gives you a dial: at low it reports the findings it's most confident in, "so you see fewer false positives", and from medium through max it broadens coverage.

ReviewerSaw the author's reasoning?Who decidesGood at
Same session, "review your changes"Yes, all of itClaudeSlips and typos, not its own assumptions
/code-reviewNo, a fresh subagentClaudeCorrectness bugs in the diff
Second session against SPEC.mdNoClaudeRequirements the code missed
Tests, typecheck, CINot applicableYour checks, every runWhatever the checks encode
A person approving the mergeOnly what the PR showsYouIntent, risk, whether it should ship

The same review, done independently

Here is the request from the story, and the version that keeps the reviewer independent and the fixes small:

text
review your changes carefully and fix every issue you find

The first line is the command; the paragraph is your next prompt once the findings arrive. Asking for a failing test first is what separates a real bug from a plausible one: the double-charge either reproduces against a stubbed timeout or it doesn't. The skip list is the part you read, because skipping is where the author's bias can creep back.

You can run the same pass outside the session, which suits a pre-push habit or a CI job:

Bash
# No conversation at all: the findings go to stdoutclaude -p "/code-review low main...feature/retry-policy" > review.txt

How to apply it in your project

  1. Commit before reviewingA clean commit makes the review's diff and any fixes easy to read and easy to revert.
  2. Review from a fresh contextRun /code-review in the session, or a second session with the spec. Don't ask the author session to grade itself.
  3. Pick the effort on purposeUse low for a short list of high-confidence findings; go higher when you want coverage and have time to triage.
  4. Triage with testsFix a finding only after a failing test shows it. Everything else goes on a skip list with a reason, and you read it.
  5. Keep the last word deterministic and humanTests and CI must pass, and a person approves the merge. The review informs them; it doesn't replace them.

Key takeaways

  • A same-session review shares the author's assumptions, so the bugs those assumptions caused look correct.
  • /code-review runs in a fresh subagent that never saw your conversation; a second session works too.
  • A fresh reviewer is the same model with fresh eyes, not a smarter one, so keep tests, CI and human approval.
  • A reviewer asked for problems always finds some: fix correctness bugs, proven with a failing test, and skip the rest.
  • Read the skip list, and commit before --fix so git can undo what checkpoints don't.

📚 المصادر

  1. Review locally with /code-review — Claude Code Docs
  2. Best practices for Claude Code — Claude Code Docs
  3. Commands — Claude Code Docs
  4. Panickssery, Bowman, Feng, LLM Evaluators Recognize and Favor Their Own Generations, arXiv:2404.13076

التعليقات (0)