Isolation des sessions pour les revues
Effectuez la revue dans une nouvelle instance dépourvue du contexte de génération.
Isolation des sessions pour les revues est une leçon Claude Architect gratuite sur CoddyKit. Ceci est la leçon 3 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Claude Architect, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Claude Architect comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
The Author Bias Problem
When Claude generates code and then reviews it in the same session, the review is compromised. The model still holds its own reasoning in context, so it tends to defend its choices instead of challenging them.
This is the same-session self-review anti-pattern. The author retains the rationale for every decision and rarely flags its own assumptions as suspect.
The exam principle is blunt: independent, fresh-instance review beats same-session self-review. In CI/CD, that means the reviewer should never share context with the generator.
Why a Fresh Instance Wins
A reviewer that starts from a blank context window approaches the diff like an outsider. It has no investment in why a function was written a certain way, so it evaluates the code on its merits alone.
- Generation context = the prompts, exploration, and reasoning that produced the code.
- Review context = just the code, the standards, and the review criteria.
Keeping these separate removes the confirmation bias that makes a self-review wave its own work through. Session isolation is the mechanism that enforces this separation in a pipeline.
Non-Interactive Mode in CI
Pipelines have no terminal to type into, so Claude Code must run in non-interactive (print) mode. Use -p (or --print) to pass a single prompt and get a single result back, then exit.
This is the foundation for an isolated review step: each invocation is a fresh process with its own clean context, completely separate from any generation step that ran earlier.
# Non-interactive review invocation in a CI job
claude -p "Review the staged diff for correctness and security issues." \
--output-format jsonParseable Output for the Gate
A CI step needs machine-readable results, not prose. Add --output-format json so the pipeline can parse findings and decide whether to pass or fail the build.
Pairing JSON output with a schema makes the result deterministic to consume: your gate script reads structured fields instead of grepping free text for words like "LGTM" or "done" — which is an anti-pattern.
claude -p "$(cat .ci/review-prompt.md)" \
--output-format json \
> review-result.json
# Gate script parses structured fields, never scans text
jq '.findings[] | select(.severity == "blocker")' review-result.jsonTwo Processes, Two Contexts
The cleanest isolation pattern in CI/CD is to split generation and review into two separate Claude Code invocations. The generation job writes code; a later, independent -p job reviews it.
Because each invocation is its own process, the reviewer never inherits the generator's conversation history. This mirrors the multi-agent rule from the exam: subagents do not inherit a coordinator's history — context must be passed explicitly, never assumed.
# Stage 1 — generation (its own session/context)
claude -p "Implement the feature described in TICKET-412."
# Stage 2 — review (a brand-new process, zero shared context)
claude -p "Review the resulting diff against our coding standards." \
--output-format jsonResume Is Not Isolation
It is tempting to --resume the generation session and ask it to review its own work. Don't. A resumed session carries the original reasoning back into context — that is exactly the self-review bias you want to avoid.
There is a second hazard: resumed tool results can be stale if the codebase changed since they were captured. Sometimes a fresh session seeded with a structured summary beats resuming a named session outright.
For unbiased review, default to a fresh session every time.
# --resume continues a NAMED session (keeps prior context — biased for review)
claude --resume feature-412 -p "Now review what you wrote." # avoid for review
# fork_session branches from a shared point — still inherits context
# For review, prefer a clean -p invocation instead.Feed Only the Diff and the Rules
An isolated reviewer should receive a tight, relevant payload: the diff to inspect plus the standards to apply. Trim verbose tool output to the fields that matter — bloated context triggers the lost-in-the-middle effect, where the model attends to the start and end far more than the middle.
Keep the review criteria near the start or end of the prompt so they are not buried mid-context.
git diff --staged > /tmp/diff.patch
claude -p "You are an independent reviewer with no prior context.
Review ONLY this diff against the rules below.
<rules>$(cat .ci/review-rules.md)</rules>
<diff>$(cat /tmp/diff.patch)</diff>" \
--output-format jsonExplicit Criteria Beat Vague Asks
An isolated session has no shared assumptions to fall back on, so the criteria must be explicit. Precise rules dramatically cut false positives.
- Vague:
"be more precise"— produces noisy, inconsistent flags. - Explicit:
"flag a comment only when it contradicts the code it describes"— produces actionable findings.
For CI reviews specifically, the goal is to minimize false positives — a reviewer that cries wolf gets ignored and erodes trust in the gate.
Few-Shot Examples for Consistency
To make an isolated reviewer behave consistently across runs, add 2-4 targeted few-shot examples covering the ambiguous cases. The model generalizes from them — it doesn't just echo them back.
Few-shot is the right tool for consistency, edge cases, output format, and reducing hallucinated findings. A couple of well-chosen flag / do-not-flag examples align the reviewer's judgment with your team's bar.
<examples>
<example verdict="flag">
Code swallows the exception silently — masks failures. Report it.
</example>
<example verdict="do-not-flag">
A TODO comment about future work is not a defect. Ignore it.
</example>
</examples>Structured Output Locks the Verdict
Force the reviewer to emit a structured verdict via a tool and JSON Schema. Set tool_choice to "any" so the model must call a tool — this guarantees structured output instead of free prose.
Mark a field required only when it is always present. Never require a possibly-absent field, or the model will fabricate a value. Use an enum with an "other" option plus a free-text detail field so new finding types stay representable.
review_tool = {
"name": "submit_review",
"description": "Return the review verdict and findings.",
"input_schema": {
"type": "object",
"properties": {
"verdict": {"enum": ["pass", "fail"]},
"findings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"category": {"enum": ["bug", "security", "style", "other"]},
"detail": {"type": "string"}
},
"required": ["category", "detail"]
}
}
},
"required": ["verdict"]
}
}
# tool_choice="any" guarantees a tool call (structured output)
message = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=2048,
tools=[review_tool],
tool_choice={"type": "any"},
messages=[{"role": "user", "content": review_prompt}],
)Re-Runs: Report Only New Issues
When a pull request is updated and the review re-runs, a fresh session would re-flag everything from scratch — including already-acknowledged items. That creates noise.
The exam pattern: when re-running, include the prior results and report only new or still-unfixed issues. You preserve session isolation (still a clean reviewer) while passing the prior findings in explicitly as input — context handed over deliberately, not inherited from a resumed generation session.
claude -p "Independent re-review. Below are the diff and the findings
from the previous run. Report ONLY new issues or prior issues that
are still unfixed. Do not repeat resolved items.
<previous_findings>$(cat last-review.json)</previous_findings>
<diff>$(git diff --staged)</diff>" \
--output-format jsonQuick Check
Test your grasp of the core decision behind isolated reviews.
Recap: Isolation by Design
Key takeaways for session-isolated reviews in CI/CD:
- Fresh instance beats self-review — the author defends its own work; an outsider doesn't.
- Separate processes — review with a distinct
claude -pinvocation; never--resumethe generation session for review. - Non-interactive + JSON —
-pwith--output-format jsongives clean context and parseable results; never grep text for completion signals. - Explicit criteria + 2-4 few-shot examples minimize false positives and keep verdicts consistent.
- tool_choice "any" forces structured output; require only always-present fields.
- On re-runs, pass prior findings explicitly and report only new or unfixed issues.
- Never route blocking pre-merge reviews through the Batch API.
Questions Fréquemment Posées
La leçon « Isolation des sessions pour les revues » est-elle gratuite ?
Oui — le texte complet de « Isolation des sessions pour les revues » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Claude Architect, passe à CoddyKit PRO. Le cours Claude Architect comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Isolation des sessions pour les revues » ?
Effectuez la revue dans une nouvelle instance dépourvue du contexte de génération. Tu pratiques Claude Architect avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Claude Architect ?
Aucune expérience préalable n'est requise. Claude Architect sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 3 sur 4.
Combien de temps prend la leçon « Isolation des sessions pour les revues » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Claude Architect ?
Oui. Chaque leçon Claude Architect inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Mode non interactif
- Sortie structurée
- Isolation des sessions pour les revues
- Génération de tests et normes