Deep Code Review
Thorough, multi-pass review of a GitHub change using the LOCAL git checkout for
diffs and file contents, and gh only for PR metadata and posting. Make a todo
list first, then follow these passes precisely.
Arguments
<PR#> (optional): review that GitHub PR. Without it, review the current
branch vs its base.
--comment: post the result as a PR comment (requires a PR context). Without
it, output to the terminal only.
--base <branch>: override the auto-detected base branch.
Pass 0 — Eligibility + context load
Dispatch an agent on the Haiku model (pass model: "haiku") for each mechanical
sub-step below — eligibility (step 2), CLAUDE.md discovery (step 3), and the change
summary (step 4) — so the expensive orchestrator model is not spent on, and its
context not bloated by, mechanical work. The decomposition (Pass 1) and the Pass 4
re-check likewise run on the Haiku model.
- Resolve scope & base.
- Determine
owner/repo from git remote get-url origin (or gh repo view --json nameWithOwner).
- Base branch:
--base if given; else the PR's base (gh pr view <#> --json baseRefName); else git merge-base HEAD origin/main (fall back to origin/master). Record the base ref to use in diffs as origin/<base>.
- Head SHA: full local
git rev-parse HEAD. Use this SHA LITERALLY in output links — never compute it inside a URL.
- Eligibility (only if a PR is in scope).
gh pr view <#> --json state,isDraft,headRefName,headRefOid,baseRefName,title,body,author. Stop (do not review) if: closed; draft / WIP; obviously automated or trivial; or we already posted a review (scan gh pr view <#> --comments for our "### Deep code review" + "Generated with [Claude Code]"). Sync guard: if local branch != headRefName → stop: "Local branch <cur> != PR source <headRefName>. Run: git checkout ". If local HEAD != headRefOid → stop: "Local HEAD <local[:8]> != PR head <headRefOid[:8]>. Run: git pull".
- CLAUDE.md discovery.
git diff --name-only origin/<base>...HEAD; Read the root CLAUDE.md (if any) and any CLAUDE.md in directories of changed files.
- Change summary. From the PR title/body (or
git log origin/<base>..HEAD --oneline when no PR), produce a concise summary.
- Second-brain reads.
knowledge_search with 3–5 keywords drawn from the changed paths/stack → collect convention/decision pages. Pass their text as "project conventions" alongside CLAUDE.md.
episodic_search for prior reviews touching these files/this repo → distill a short "previously flagged / previously dismissed here" note.
- Read
~/.second-brain/review-false-positives.md if it exists (else treat as empty). Hold its contents for Pass 3.
- Change-intent classification (Haiku step). From the PR title/body (or
git log origin/<base>..HEAD --oneline when no PR), set is_bugfix = does this
change CLAIM TO FIX a reported runtime behavior (vs. a feature / refactor / docs /
test-only change)? Record it — it gates Pass 3.5.
- Fragile-premises note. Read
~/.second-brain/review-fragile-premises.md if it
exists (else treat as empty). Hold its contents for Pass 2d.
Pass 1 — Review-unit decomposition (Haiku model)
git diff --stat origin/<base>...HEAD. Group changed files into logical review
units (implementation + its tests; module/package cohesion; cross-layer feature
slices; config/infra serving one purpose). Skip 100%-deleted files and
trivial-only changes (whitespace, import reorder, version bump). Split any unit
15 files or ~3000 lines. Cap at 15 units (merge smallest if over). Tag each
unit priority: critical (auth/security/data/access) | high (core logic,
user-facing) | medium (utilities/internal) | low (config). Set docs_only: true
ONLY when every file is prose documentation — matches *.md/*.mdx/*.txt/*.rst
or lives under docs/** — AND none lives under skills/**, agents/**, tests/**,
or any other executable/prompt tree. Those files ARE the product (a SKILL.md or
agent .md is code-as-prompt) and must be reviewed on the best model, not the Haiku model.
Config files (*.json, *.yaml, *.toml, dotfiles) are code-side, NOT docs. Any
unit tagged critical or high is docs_only: false regardless of extension.
There is no early-exit — true docs units are still reviewed, just on the Haiku model. Emit JSON:
[{"name":"...","files":["..."],"priority":"critical","skip":false,"docs_only":false}, ...]
Filter skip:true; sort critical-first; record the skipped count.
Pass 2 — Per-unit review (parallel agents, model by code-vs-docs)
Dispatch one Agent(subagent_type: "second-brain:code-review-unit-reviewer") per
non-skipped unit, choosing the model by unit kind:
- code units (
docs_only: false): dispatch with NO model override — the agent
inherits the session model, i.e. the best model available (the v2 directive).
- doc units (
docs_only: true): dispatch with model: "haiku" — docs don't
need deep reasoning.
Dispatch in waves of at most 5 concurrent agents (not all 15 at once): run
critical/high code units first, then medium/low code units, then doc units. Pack
each wave to the cap from the priority-sorted list — backfill spare slots from the
next tier; don't leave slots idle. The wave cap bounds peak agent count and RAM.
Pass each agent: unit name + file list,
origin/<base> as the base ref, the change summary, the combined project
conventions (CLAUDE.md + wiki pages), and the episodic prior-review note. Each
agent returns structured findings only (no file bodies). Collect them.
Pass 2b — Architectural pass (advisory, parallel)
If at least one critical or high unit exists, dispatch exactly ONE
Agent(subagent_type: "second-brain:quality-reviewer") over the deduped union of
all critical+high unit files. It occupies one slot in wave 1 (as do the Pass 2c
history reviewer and the Pass 2d premise reviewer when they run) — so wave 1 holds at
most 2 unit-reviewers + the architectural + history + premise reviewers (≤5 concurrent
total), keeping the cap intact. Each skipped advisory/lens pass returns its slot to
unit-reviewers (all three of 2b/2c/2d run → ≤2 unit-reviewers; any two run → ≤3; any
one runs → ≤4; none → ≤5 unit-reviewers) — the ≤5 cap holds in every combination. It
depends only on Pass 1's unit list, not Pass 2's
findings. Pass it origin/<base> (the SAME base-ref form Pass 2 uses), the change
summary, and the file set, and instruct it to scope findings to lines changed since
that ref — ignore pre-existing issues on untouched lines. If there are no
critical/high units, skip this pass.
Its CRITICAL/WARNING/INFO output is collected verbatim for a separate
"Architectural notes (advisory)" section in Pass 4. These notes are advisory only:
they are never scored or recorded as false positives, and are kept distinct from
the numbered bug findings.
Pass 2c — History / regression pass (scored, parallel)
If at least one non-skipped code unit exists (docs_only: false), dispatch
exactly ONE Agent(subagent_type: "second-brain:code-review-history-reviewer") over
the deduped union of all non-skipped code-unit files. It occupies one slot in wave
1 alongside the architectural reviewer (see the Pass 2b wave-1 note). It depends
only on Pass 1's unit list, not Pass 2's findings, so it runs concurrently. Pass it
origin/<base> (the SAME base-ref form Pass 2 uses), the change summary, the combined
project conventions (CLAUDE.md + wiki), and the episodic prior-review note. Unlike the
architectural pass, its findings ARE bugs (category regression): they flow into
Pass 3 dedup + scoring exactly like the per-unit findings. If every unit is docs-only,
skip this pass.
Pass 2d — Runtime-premise pass (scored, parallel)
If at least one non-skipped code unit exists (docs_only:false), dispatch exactly
ONE Agent(subagent_type:"second-brain:code-review-premise-reviewer") over the deduped
union of all non-skipped code-unit files. It occupies one slot in wave 1 alongside
the architectural (2b) and history (2c) reviewers. It depends only on Pass 1's unit
list, not Pass 2's findings, so it runs concurrently. Pass it origin/<base>, the
change summary, the combined project conventions (CLAUDE.md + wiki), the prior-review
note, and the review-fragile-premises.md contents from Pass 0. Its findings (category
premise) flow into Pass 3 dedup + scoring exactly like the per-unit findings. The
premise reviewer NAMES unproven runtime premises (the bug class diff-static review
misses); Pass 3.5 PROBES them. If every unit is docs-only, skip this pass.
Pass 3 — Dedup + scoring + filter
- Dedup: if a shared file produced the same finding in two units, keep the
better-explained one. On a cross-pass collision between a
regression finding
(Pass 2c, which cites a prior commit short-SHA) and a non-regression finding on
the same line, prefer the regression one — its commit citation is what makes it
actionable and would otherwise be lost.
- Score: for each unique finding dispatch
Agent(subagent_type: "second-brain:code-review-scorer"), passing the finding,
its file paths, the project conventions, and the false-positive store contents
from Pass 0. A premise finding (Pass 2d) scores HIGH when the premise is
load-bearing AND unproven AND — if Pass 3.5 ran — shown BROKEN; LOW when Pass 3.5
confirmed it holds or it is established/defended. A premise Pass 3.5 marked BROKEN
is force-promoted to confirmed (≥70) regardless of the scorer's number.
- Partition the scored findings into three buckets (keep all until Pass 4):
- confirmed (score ≥ 70): the numbered review output, sorted by severity then score.
- low-confidence (score 16–69): NOT confirmed, but surfaced in Pass 4 as a
separate, clearly-labeled "Lower-confidence findings" section so a real but
hard-to-verify bug is never silently dropped. Retain until Pass 4.
- killed-hard (score ≤ 15): dropped — neither shown nor recorded. The scorer
now inherits the session model (matches the reviewer it gates), so a ≤15 kill is
trustworthy enough to drop without recording.
Pass 3.5 — Bug-fix real-env verification (orchestrator, gated)
Runs ONLY when is_bugfix (Pass 0) AND Pass 2d flagged ≥1 load-bearing premise. This
is the ONE step that executes code — run by the orchestrator (this trusted session),
NEVER by a sandboxed PR-influenced agent.
- Confirm with the user. Print exactly what each
proof_probe will run; it
executes code. On decline: skip, mark the premise findings "unverified (user
declined)", continue to Pass 4. Never blocks the review.
- Probe each flagged premise via its
proof_probe, exercising the changed code
path in the real env — the actual environment state, NOT a sandbox that sets
convenient values. Record holds / BROKEN. A BROKEN premise elevates its finding
to confirmed critical ("fix does not hold in the real runtime").
- Failure-regime test check. Confirm the change adds/modifies a test that
exercises the premise's FALSE regime (e.g. the env var UNSET). Missing → a
test-gap finding ("no test covers the regime where the bug occurs").
Best-effort: any probe error is reported, never fails the review.
Pass 4 — Output + false-positive write-back
Output.
Default (no --comment): print the formatted review to the terminal.
--comment: re-run the eligibility check (still open, no competing deep
review posted since we started), then gh pr comment <#> --body "...".
Comment format (no emojis):
### Deep code review
Analyzed X review units (Y files, Z skipped as trivial). Found N issues:
1. **<brief description>** (category: severity)
<link>
...
Generated with [Claude Code](https://claude.ai/code) using second-brain:code-review-deep
Or, if none: Analyzed X review units (Y files, Z skipped as trivial). No issues found.
Lower-confidence findings (unverified). If the low-confidence bucket
(score 16–69) is non-empty, append — after the numbered confirmed findings and
before the architectural notes — a section titled Lower-confidence findings (unverified — may be false positives). Lead with one line noting these were
found but not confirmed at high confidence and may include false positives, then
list each as - **<brief>** (category: severity) followed by its <link>. Keep
it visually distinct from the numbered confirmed list and from the architectural
notes so the three are never conflated. For --comment, post it under that same
subhead. If the bucket is empty, omit the section.
Architectural notes (advisory). If Pass 2b ran, append after the numbered
findings a section titled Architectural notes (advisory — not blocking)
containing the quality-reviewer output. For --comment, post it under that
same labelled subhead, visually separated from the numbered bug list so a
reader never mistakes an architectural opinion for a confirmed bug.
Runtime-premise verification. If Pass 3.5 ran, append a section titled
Runtime-premise verification listing each probed premise with holds / BROKEN
and a one-line real-env evidence note. A confirmed BROKEN premise may be appended
(user-confirmed) to ~/.second-brain/review-fragile-premises.md using the format
below — same best-effort, never-fail discipline as the false-positive store.
Link format (literal full SHA, renders in Markdown):
https://github.com/<owner>/<repo>/blob/<FULL-SHA>/<path>#L<start>-L<end>
— full SHA written literally (NOT $(git rev-parse …)), # after the path,
range L<start>-L<end>, ≥1 line of context each side.
False-positive write-back (user dismissals only — no auto-record).
- Do NOT auto-record killed-hard or low-confidence findings. v2.1 removes the
auto-record ratchet: a wrong auto-suppression hides a real bug indefinitely,
whereas a missing entry just means the finding is re-judged next run (cheap, now
that the scorer matches the reviewer). The store grows ONLY from explicit user
action.
- After a terminal review, offer: "Mark any shown finding (confirmed or
lower-confidence) as a false positive to remember it?" Record only the findings
the user dismisses.
- For each user-dismissed pattern, append an entry to
~/.second-brain/review-false-positives.md (read current contents with Read,
append, Write back; if the file is absent create it with the header below).
Recording is best-effort — a write failure must NOT fail the review.
File header (only when creating it):
# Review false-positive patterns
<!-- Read by code-review-scorer to suppress known non-issues. Append-only. -->
Per entry:
## <short pattern title>
- repo: <owner/repo>
- where: <path or glob> (<category>)
- why not a bug: <one-line reason>
- source: user-dismissed
- date: <YYYY-MM-DD>
Fragile-premises file (~/.second-brain/review-fragile-premises.md) — header on create:
# Review fragile-premise patterns
<!-- Read by code-review-premise-reviewer to raise severity on known-fragile runtime premises. Append-only. -->
Per entry:
## <short premise title>
- repo: <owner/repo>
- premise: <the assumption that proved fragile>
- why fragile: <one-line: how it fails in the real runtime>
- source: pass-3.5-confirmed | user
- date: <YYYY-MM-DD>
Degradation
If parallel subagent dispatch is unavailable, fall back to a single-context
review over the full git diff origin/<base>...HEAD (no unit fan-out, no parallel
scoring) and say so in the output. Second-brain reads and FP write-back still apply.
False positives to avoid (carried from the standard reviewer)
Pre-existing issues; not-actually-a-bug; senior-engineer nitpicks; anything a
linter/typechecker/compiler catches; general quality gripes unless a convention
requires them; convention issues explicitly silenced in code; intentional
functional changes; real issues on lines this change did not modify.
Notes
- Do not build, typecheck, or run the app — CI handles that. The ONE exception is
Pass 3.5: a narrow, orchestrator-run, user-confirmed, bug-fix-only premise probe
(a specific
proof_probe, not a general build/typecheck/test run).
- Use
gh for PR metadata/posting; use local git diff + Read for code.
- Small changes (< 20 files) may yield only 1–3 units. That's fine.
- If repeated runs leave "ghost" agents / RAM growth, triage on the affected box:
(a)
ps -eo pid,etimes,args | grep -E 'claude --bare|claude -p' — recursive
extractors (fires only in API-key mode; OAuth queues them) → fix at the Stop-hook
extractor; (b) ps -eo pid,ppid,args | grep server.bundle — orphaned MCP servers
whose parent claude exited → reap them; (c) the session claude RSS climbing
run-over-run is parent-context bloat, inherent to inline fan-out — the wave cap +
lean sub-agent returns above are the mitigation (bounded, not a true leak).
- Model vs. agent names: whenever a pass names a model (Haiku / Sonnet / Opus) it
means the dispatch
model parameter (e.g. model: "haiku") — NEVER an agent name.
Subagents are always named via subagent_type: "second-brain:<agent>". Don't go
looking for an agent called "Haiku".
Source: Cain-Ish/claude-code-plugin — distributed by TomeVault.
1---2name: code-review-deep3description: In-depth multi-pass code review of a GitHub change (local checkout). Decomposes the diff into logical review units, reviews each on the best available model (docs on the Haiku model), runs an advisory architectural pass on the highest-risk units, scores findings with an FP-aware scorer, consults the second-brain for conventions and prior reviews, and records false positives. Local output by default; --comment posts to the PR. Use when this capability is needed.4---56# Deep Code Review78Thorough, multi-pass review of a GitHub change using the LOCAL git checkout for9diffs and file contents, and `gh` only for PR metadata and posting. Make a todo10list first, then follow these passes precisely.1112## Arguments1314- `<PR#>` (optional): review that GitHub PR. Without it, review the current15 branch vs its base.16- `--comment`: post the result as a PR comment (requires a PR context). Without17 it, output to the terminal only.18- `--base <branch>`: override the auto-detected base branch.1920## Pass 0 — Eligibility + context load2122Dispatch an agent **on the Haiku model** (pass `model: "haiku"`) for each mechanical23sub-step below — eligibility (step 2), CLAUDE.md discovery (step 3), and the change24summary (step 4) — so the expensive orchestrator model is not spent on, and its25context not bloated by, mechanical work. The decomposition (Pass 1) and the Pass 426re-check likewise run on the Haiku model.27281. **Resolve scope & base.**29 - Determine `owner/repo` from `git remote get-url origin` (or `gh repo view --json nameWithOwner`).30 - Base branch: `--base` if given; else the PR's base (`gh pr view <#> --json baseRefName`); else `git merge-base HEAD origin/main` (fall back to `origin/master`). Record the base ref to use in diffs as `origin/<base>`.31 - Head SHA: full local `git rev-parse HEAD`. Use this SHA LITERALLY in output links — never compute it inside a URL.322. **Eligibility (only if a PR is in scope).** `gh pr view <#> --json state,isDraft,headRefName,headRefOid,baseRefName,title,body,author`. Stop (do not review) if: closed; draft / WIP; obviously automated or trivial; or we already posted a review (scan `gh pr view <#> --comments` for our "### Deep code review" + "Generated with [Claude Code]"). **Sync guard:** if local branch != `headRefName` → stop: "Local branch `<cur>` != PR source `<headRefName>`. Run: git checkout <headRefName>". If local HEAD != `headRefOid` → stop: "Local HEAD `<local[:8]>` != PR head `<headRefOid[:8]>`. Run: git pull".333. **CLAUDE.md discovery.** `git diff --name-only origin/<base>...HEAD`; Read the root CLAUDE.md (if any) and any CLAUDE.md in directories of changed files.344. **Change summary.** From the PR title/body (or `git log origin/<base>..HEAD --oneline` when no PR), produce a concise summary.355. **Second-brain reads.**36 - `knowledge_search` with 3–5 keywords drawn from the changed paths/stack → collect convention/decision pages. Pass their text as "project conventions" alongside CLAUDE.md.37 - `episodic_search` for prior reviews touching these files/this repo → distill a short "previously flagged / previously dismissed here" note.38 - Read `~/.second-brain/review-false-positives.md` if it exists (else treat as empty). Hold its contents for Pass 3.396. **Change-intent classification** (Haiku step). From the PR title/body (or40 `git log origin/<base>..HEAD --oneline` when no PR), set `is_bugfix` = does this41 change CLAIM TO FIX a reported runtime behavior (vs. a feature / refactor / docs /42 test-only change)? Record it — it gates Pass 3.5.437. **Fragile-premises note.** Read `~/.second-brain/review-fragile-premises.md` if it44 exists (else treat as empty). Hold its contents for Pass 2d.4546## Pass 1 — Review-unit decomposition (Haiku model)4748`git diff --stat origin/<base>...HEAD`. Group changed files into logical review49units (implementation + its tests; module/package cohesion; cross-layer feature50slices; config/infra serving one purpose). Skip 100%-deleted files and51trivial-only changes (whitespace, import reorder, version bump). Split any unit52> 15 files or ~3000 lines. Cap at 15 units (merge smallest if over). Tag each53unit priority: critical (auth/security/data/access) | high (core logic,54user-facing) | medium (utilities/internal) | low (config). Set `docs_only: true`55ONLY when every file is *prose* documentation — matches `*.md`/`*.mdx`/`*.txt`/`*.rst`56or lives under `docs/**` — AND none lives under `skills/**`, `agents/**`, `tests/**`,57or any other executable/prompt tree. Those files ARE the product (a `SKILL.md` or58agent `.md` is code-as-prompt) and must be reviewed on the best model, not the Haiku model.59Config files (`*.json`, `*.yaml`, `*.toml`, dotfiles) are code-side, NOT docs. Any60unit tagged `critical` or `high` is `docs_only: false` regardless of extension.61There is no early-exit — true docs units are still reviewed, just on the Haiku model. Emit JSON:6263 [{"name":"...","files":["..."],"priority":"critical","skip":false,"docs_only":false}, ...]6465Filter `skip:true`; sort critical-first; record the skipped count.6667## Pass 2 — Per-unit review (parallel agents, model by code-vs-docs)6869Dispatch one `Agent(subagent_type: "second-brain:code-review-unit-reviewer")` per70non-skipped unit, choosing the model by unit kind:7172- **code units** (`docs_only: false`): dispatch with NO model override — the agent73 inherits the session model, i.e. the best model available (the v2 directive).74- **doc units** (`docs_only: true`): dispatch with `model: "haiku"` — docs don't75 need deep reasoning.7677Dispatch in **waves of at most 5 concurrent agents** (not all 15 at once): run78critical/high code units first, then medium/low code units, then doc units. Pack79each wave to the cap from the priority-sorted list — backfill spare slots from the80next tier; don't leave slots idle. The wave cap bounds peak agent count and RAM.81Pass each agent: unit name + file list,82`origin/<base>` as the base ref, the change summary, the combined project83conventions (CLAUDE.md + wiki pages), and the episodic prior-review note. Each84agent returns structured findings only (no file bodies). Collect them.8586## Pass 2b — Architectural pass (advisory, parallel)8788If at least one `critical` or `high` unit exists, dispatch exactly ONE89`Agent(subagent_type: "second-brain:quality-reviewer")` over the deduped union of90all critical+high unit files. It **occupies one slot in wave 1** (as do the Pass 2c91history reviewer and the Pass 2d premise reviewer when they run) — so wave 1 holds at92most 2 unit-reviewers + the architectural + history + premise reviewers (≤5 concurrent93total), keeping the cap intact. Each skipped advisory/lens pass returns its slot to94unit-reviewers (all three of 2b/2c/2d run → ≤2 unit-reviewers; any two run → ≤3; any95one runs → ≤4; none → ≤5 unit-reviewers) — the ≤5 cap holds in every combination. It96depends only on Pass 1's unit list, not Pass 2's97findings. Pass it `origin/<base>` (the SAME base-ref form Pass 2 uses), the change98summary, and the file set, and instruct it to scope findings to lines changed since99that ref — ignore pre-existing issues on untouched lines. If there are no100critical/high units, skip this pass.101102Its `CRITICAL`/`WARNING`/`INFO` output is collected verbatim for a separate103"Architectural notes (advisory)" section in Pass 4. These notes are advisory only:104they are never scored or recorded as false positives, and are kept distinct from105the numbered bug findings.106107## Pass 2c — History / regression pass (scored, parallel)108109If at least one non-skipped **code** unit exists (`docs_only: false`), dispatch110exactly ONE `Agent(subagent_type: "second-brain:code-review-history-reviewer")` over111the deduped union of all non-skipped code-unit files. It **occupies one slot in wave1121** alongside the architectural reviewer (see the Pass 2b wave-1 note). It depends113only on Pass 1's unit list, not Pass 2's findings, so it runs concurrently. Pass it114`origin/<base>` (the SAME base-ref form Pass 2 uses), the change summary, the combined115project conventions (CLAUDE.md + wiki), and the episodic prior-review note. Unlike the116architectural pass, its findings ARE bugs (category `regression`): they flow into117Pass 3 dedup + scoring exactly like the per-unit findings. If every unit is docs-only,118skip this pass.119120## Pass 2d — Runtime-premise pass (scored, parallel)121122If at least one non-skipped **code** unit exists (`docs_only:false`), dispatch exactly123ONE `Agent(subagent_type:"second-brain:code-review-premise-reviewer")` over the deduped124union of all non-skipped code-unit files. It **occupies one slot in wave 1** alongside125the architectural (2b) and history (2c) reviewers. It depends only on Pass 1's unit126list, not Pass 2's findings, so it runs concurrently. Pass it `origin/<base>`, the127change summary, the combined project conventions (CLAUDE.md + wiki), the prior-review128note, and the `review-fragile-premises.md` contents from Pass 0. Its findings (category129`premise`) flow into Pass 3 dedup + scoring exactly like the per-unit findings. The130premise reviewer NAMES unproven runtime premises (the bug class diff-static review131misses); Pass 3.5 PROBES them. If every unit is docs-only, skip this pass.132133## Pass 3 — Dedup + scoring + filter1341351. **Dedup**: if a shared file produced the same finding in two units, keep the136 better-explained one. On a cross-pass collision between a `regression` finding137 (Pass 2c, which cites a prior commit short-SHA) and a non-regression finding on138 the same line, prefer the `regression` one — its commit citation is what makes it139 actionable and would otherwise be lost.1402. **Score**: for each unique finding dispatch141 `Agent(subagent_type: "second-brain:code-review-scorer")`, passing the finding,142 its file paths, the project conventions, and the false-positive store contents143 from Pass 0. A `premise` finding (Pass 2d) scores HIGH when the premise is144 load-bearing AND unproven AND — if Pass 3.5 ran — shown BROKEN; LOW when Pass 3.5145 confirmed it holds or it is established/defended. A premise Pass 3.5 marked BROKEN146 is force-promoted to confirmed (≥70) regardless of the scorer's number.1473. **Partition** the scored findings into three buckets (keep all until Pass 4):148 - **confirmed** (score **≥ 70**): the numbered review output, sorted by severity then score.149 - **low-confidence** (score **16–69**): NOT confirmed, but surfaced in Pass 4 as a150 separate, clearly-labeled "Lower-confidence findings" section so a real but151 hard-to-verify bug is never silently dropped. Retain until Pass 4.152 - **killed-hard** (score **≤ 15**): dropped — neither shown nor recorded. The scorer153 now inherits the session model (matches the reviewer it gates), so a ≤15 kill is154 trustworthy enough to drop without recording.155156## Pass 3.5 — Bug-fix real-env verification (orchestrator, gated)157158Runs ONLY when `is_bugfix` (Pass 0) AND Pass 2d flagged ≥1 load-bearing premise. This159is the ONE step that executes code — run by the orchestrator (this trusted session),160NEVER by a sandboxed PR-influenced agent.1611621. **Confirm with the user.** Print exactly what each `proof_probe` will run; it163 executes code. On decline: skip, mark the premise findings "unverified (user164 declined)", continue to Pass 4. Never blocks the review.1652. **Probe each flagged premise** via its `proof_probe`, exercising the changed code166 path in the **real env** — the actual environment state, NOT a sandbox that sets167 convenient values. Record `holds` / `BROKEN`. A BROKEN premise elevates its finding168 to confirmed critical ("fix does not hold in the real runtime").1693. **Failure-regime test check.** Confirm the change adds/modifies a test that170 exercises the premise's FALSE regime (e.g. the env var UNSET). Missing → a171 `test-gap` finding ("no test covers the regime where the bug occurs").172173Best-effort: any probe error is reported, never fails the review.174175## Pass 4 — Output + false-positive write-back1761771. **Output.**178 - Default (no `--comment`): print the formatted review to the terminal.179 - `--comment`: re-run the eligibility check (still open, no competing deep180 review posted since we started), then `gh pr comment <#> --body "..."`.181 - Comment format (no emojis):182183 ### Deep code review184185 Analyzed X review units (Y files, Z skipped as trivial). Found N issues:186187 1. **<brief description>** (category: severity)188189 <link>190191 ...192193 Generated with [Claude Code](https://claude.ai/code) using second-brain:code-review-deep194195 Or, if none: `Analyzed X review units (Y files, Z skipped as trivial). No issues found.`196 - **Lower-confidence findings (unverified).** If the low-confidence bucket197 (score 16–69) is non-empty, append — after the numbered confirmed findings and198 before the architectural notes — a section titled `Lower-confidence findings199 (unverified — may be false positives)`. Lead with one line noting these were200 found but not confirmed at high confidence and may include false positives, then201 list each as `- **<brief>** (category: severity)` followed by its `<link>`. Keep202 it visually distinct from the numbered confirmed list and from the architectural203 notes so the three are never conflated. For `--comment`, post it under that same204 subhead. If the bucket is empty, omit the section.205 - **Architectural notes (advisory).** If Pass 2b ran, append after the numbered206 findings a section titled `Architectural notes (advisory — not blocking)`207 containing the quality-reviewer output. For `--comment`, post it under that208 same labelled subhead, visually separated from the numbered bug list so a209 reader never mistakes an architectural opinion for a confirmed bug.210 - **Runtime-premise verification.** If Pass 3.5 ran, append a section titled211 `Runtime-premise verification` listing each probed premise with `holds` / `BROKEN`212 and a one-line real-env evidence note. A confirmed BROKEN premise may be appended213 (user-confirmed) to `~/.second-brain/review-fragile-premises.md` using the format214 below — same best-effort, never-fail discipline as the false-positive store.215 - **Link format** (literal full SHA, renders in Markdown):216 `https://github.com/<owner>/<repo>/blob/<FULL-SHA>/<path>#L<start>-L<end>`217 — full SHA written literally (NOT `$(git rev-parse …)`), `#` after the path,218 range `L<start>-L<end>`, ≥1 line of context each side.2192202. **False-positive write-back** (user dismissals only — no auto-record).221 - **Do NOT auto-record** killed-hard or low-confidence findings. v2.1 removes the222 auto-record ratchet: a wrong auto-suppression hides a real bug indefinitely,223 whereas a missing entry just means the finding is re-judged next run (cheap, now224 that the scorer matches the reviewer). The store grows ONLY from explicit user225 action.226 - After a terminal review, offer: "Mark any shown finding (confirmed or227 lower-confidence) as a false positive to remember it?" Record only the findings228 the user dismisses.229 - For each user-dismissed pattern, append an entry to230 `~/.second-brain/review-false-positives.md` (read current contents with Read,231 append, Write back; if the file is absent create it with the header below).232 Recording is best-effort — a write failure must NOT fail the review.233234 File header (only when creating it):235236 # Review false-positive patterns237 <!-- Read by code-review-scorer to suppress known non-issues. Append-only. -->238239 Per entry:240241 ## <short pattern title>242 - repo: <owner/repo>243 - where: <path or glob> (<category>)244 - why not a bug: <one-line reason>245 - source: user-dismissed246 - date: <YYYY-MM-DD>247248 Fragile-premises file (`~/.second-brain/review-fragile-premises.md`) — header on create:249250 # Review fragile-premise patterns251 <!-- Read by code-review-premise-reviewer to raise severity on known-fragile runtime premises. Append-only. -->252253 Per entry:254255 ## <short premise title>256 - repo: <owner/repo>257 - premise: <the assumption that proved fragile>258 - why fragile: <one-line: how it fails in the real runtime>259 - source: pass-3.5-confirmed | user260 - date: <YYYY-MM-DD>261262## Degradation263264If parallel subagent dispatch is unavailable, fall back to a single-context265review over the full `git diff origin/<base>...HEAD` (no unit fan-out, no parallel266scoring) and say so in the output. Second-brain reads and FP write-back still apply.267268## False positives to avoid (carried from the standard reviewer)269270Pre-existing issues; not-actually-a-bug; senior-engineer nitpicks; anything a271linter/typechecker/compiler catches; general quality gripes unless a convention272requires them; convention issues explicitly silenced in code; intentional273functional changes; real issues on lines this change did not modify.274275## Notes276277- Do not build, typecheck, or run the app — CI handles that. The ONE exception is278 **Pass 3.5**: a narrow, orchestrator-run, user-confirmed, bug-fix-only premise probe279 (a specific `proof_probe`, not a general build/typecheck/test run).280- Use `gh` for PR metadata/posting; use local `git diff` + Read for code.281- Small changes (< 20 files) may yield only 1–3 units. That's fine.282- If repeated runs leave "ghost" agents / RAM growth, triage on the affected box:283 (a) `ps -eo pid,etimes,args | grep -E 'claude --bare|claude -p'` — recursive284 extractors (fires only in API-key mode; OAuth queues them) → fix at the Stop-hook285 extractor; (b) `ps -eo pid,ppid,args | grep server.bundle` — orphaned MCP servers286 whose parent `claude` exited → reap them; (c) the session `claude` RSS climbing287 run-over-run is parent-context bloat, inherent to inline fan-out — the wave cap +288 lean sub-agent returns above are the mitigation (bounded, not a true leak).289- **Model vs. agent names:** whenever a pass names a model (Haiku / Sonnet / Opus) it290 means the dispatch `model` parameter (e.g. `model: "haiku"`) — NEVER an agent name.291 Subagents are always named via `subagent_type: "second-brain:<agent>"`. Don't go292 looking for an agent called "Haiku".293294---295> Source: [Cain-Ish/claude-code-plugin](https://github.com/Cain-Ish/claude-code-plugin) — distributed by [TomeVault](https://tomevault.io).296<!-- tomevault:4.0:skill_md:2026-06-16 -->