Code Review
Read-only — do not edit, write, or modify files.
The kensai MCP server holds all session state. Agents self-serve context via mcp__kensai__session_priming — no data
threading from lead to agents.
Environment
Agent teams: !printenv CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS
Prerequisites
If printenv above is blank or TeamCreate tool is not available, stop and tell the user:
Agent teams required. Add to settings:
{ "env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1" } }
Then restart.
Call mcp__kensai__session_start with resolved mode and path. On error, inform the user and stop.
Mode: $mode (default: uncommitted) Path: $path (default: current directory)
If mode looks like a path, treat as $path with mode uncommitted.
committed — HEAD~1..HEAD. Review the topmost commit.
uncommitted (default) — HEAD..working tree. Review work-in-progress.
all — HEAD~1..working tree. Review commit + uncommitted (amendment scenario).
Model Selection
After session_start, check session_state for changed_files total. 20+ files → spawn teammates with
model: "<current-model>[1m]". Otherwise default model.
Pipeline
Phase 1: Grounding
- Create a team. Spawn a
review-grounder teammate. No data in spawn prompt — grounder self-serves via
session_priming.
- Wait for grounder to complete. Grounder stores structured context via MCP and calls
mcp__kensai__grounding_complete.
- Shut down the grounder.
Phase 2: Surfacing
Read grounding from mcp__kensai__grounding_get — summary, integration surface, hotspots, blind spots, intent.
Derive surfacing dimensions from grounding — each dimension names a specific risk area this change introduces,
not a generic review category. The dimension tells the surfacer WHERE to focus; the surfacer decides WHAT to find.
Derivation process:
- Read grounding hotspots. Each hotspot is a candidate dimension or feeds into one.
- Read the integration surface. Cross-boundary touchpoints suggest dimensions.
- Name the dimension after the RISK, not after a review discipline.
Self-check before spawning: if you could copy the same dimension name to a different change and it would still
make sense, the dimension is too generic. Rewrite it using terms from the grounding.
Create a task per dimension. Spawn review-surfacer teammates in parallel — one per dimension. Spawn prompt:
dimension name + quality criteria from grounding hotspots (risk patterns to watch for, not methodology).
Always spawn one additional general-review surfacer alongside the dimension surfacers. No prescribed dimension or
quality criteria. Spawn prompt: "General review -- no prescribed dimension. Follow any thread. Focus on behavioral
regressions: semantic contracts, lifecycle guarantees, concurrency, and anything the dimension surfacers might miss."
Wait for all surfacers. They record findings and call mcp__kensai__surface_clean or
mcp__kensai__finding_surface via MCP.
Shut down all surfacers.
Phase 3: Proving
- Call
mcp__kensai__surfacing_complete. If 0 findings -> skips to filing.
- Spawn a
review-prover teammate. Prover self-serves findings and context via MCP, applies falsification gates,
verdicts each finding.
- Wait for prover to complete.
- Check for unverdicted findings — call
mcp__kensai__findings_list with status: "pending". If any remain,
message the prover with the pending finding IDs and wait. Repeat until all are handled.
- Shut down the prover.
Phase 4: Filing
- Read confirmed findings from
mcp__kensai__findings_list with status: "confirmed".
- Apply last-gate filter: already handled? Intentional? Not actionable? Speculative? Boundary crossing? Drop if any.
- Write the terminal report. One issue per finding. Assertions, not questions. Quote code, cite
file:line.
- Call
mcp__kensai__filing_complete.
- Call
mcp__kensai__session_end.
- Clean up the team.
The MCP enforces phase order. Tools reject calls outside their valid phase.
1---2name: kensai-review3description: Local multi-agent code review with adversarial falsification. Orchestrated by the kensai MCP server — call `start`, follow returned instructions through grounding → surfacing → proving → filing. Supports committed, uncommitted, or all changes. Optionally pass a path.4---56# Code Review78**Read-only** — do not edit, write, or modify files.910The kensai MCP server holds all session state. Agents self-serve context via `mcp__kensai__session_priming` — no data11threading from lead to agents.1213## Environment1415Agent teams: !`printenv CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS`1617## Prerequisites18191. If `printenv` above is blank or `TeamCreate` tool is not available, stop and tell the user:2021 > Agent teams required. Add to settings:22 >23 > ```json24 > { "env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1" } }25 > ```26 >27 > Then restart.28292. Call `mcp__kensai__session_start` with resolved mode and path. On error, inform the user and stop.3031**Mode:** `$mode` (default: `uncommitted`) **Path:** `$path` (default: current directory)3233If mode looks like a path, treat as `$path` with mode `uncommitted`.3435- **`committed`** — HEAD~1..HEAD. Review the topmost commit.36- **`uncommitted`** (default) — HEAD..working tree. Review work-in-progress.37- **`all`** — HEAD~1..working tree. Review commit + uncommitted (amendment scenario).3839## Model Selection4041After `session_start`, check `session_state` for `changed_files` total. 20+ files → spawn teammates with42`model: "<current-model>[1m]"`. Otherwise default model.4344## Pipeline4546### Phase 1: Grounding47481. Create a team. Spawn a `review-grounder` teammate. No data in spawn prompt — grounder self-serves via49 `session_priming`.502. Wait for grounder to complete. Grounder stores structured context via MCP and calls `mcp__kensai__grounding_complete`.513. **Shut down the grounder.**5253### Phase 2: Surfacing54551. Read grounding from `mcp__kensai__grounding_get` — summary, integration surface, hotspots, blind spots, intent.562. Derive **surfacing dimensions** from grounding — each dimension names a **specific risk area this change introduces**,57 not a generic review category. The dimension tells the surfacer WHERE to focus; the surfacer decides WHAT to find.5859 Derivation process:60 - Read grounding hotspots. Each hotspot is a candidate dimension or feeds into one.61 - Read the integration surface. Cross-boundary touchpoints suggest dimensions.62 - Name the dimension after the RISK, not after a review discipline.6364 <examples>65 <example>66 <type>Good dimensions (derived from specific change)</type>67 <good>68 For a change that replaces FRT with BVH and widens uint16 to uint32:69 - "uint16-to-uint32 widening across 30+ consumer call sites"70 - "BVH trace semantic parity with FRT canonical implementation"71 - "legacy binary format parse-and-discard correctness"72 </good>73 </example>7475 <example>76 <type>Good dimensions (derived from a pagination + doc change)</type>77 <good>78 - "pagination boundary correctness — block splitting, oversized blocks, page footer"79 - "documentation accuracy after behavioral changes — tool visibility, naming, counts"80 </good>81 </example>8283 <example>84 <type>Bad dimensions (generic review categories)</type>85 <bad>86 - "Correctness review" — every review checks correctness; this doesn't focus the surfacer87 - "Integration review" — too broad; says nothing about what integration risks THIS change has88 - "Completeness review" — generic; the surfacer doesn't know what completeness means for this change89 - "Design review" — applicable to any change; doesn't leverage grounding90 </bad>91 </example>9293 <example>94 <type>Bad dimensions (investigation questions)</type>95 <bad>96 - "tri_ref_t round-trip through damage model" — names the exact code path to check97 - "iterateNodeFaces uint16_t widening — consumer completeness" — tells what to find98 </bad>99 </example>100 </examples>101102 **Self-check before spawning:** if you could copy the same dimension name to a different change and it would still103 make sense, the dimension is too generic. Rewrite it using terms from the grounding.1041053. Create a task per dimension. Spawn `review-surfacer` teammates in parallel — one per dimension. Spawn prompt:106 dimension name + quality criteria from grounding hotspots (risk patterns to watch for, not methodology).1071084. **Always spawn one additional general-review surfacer** alongside the dimension surfacers. No prescribed dimension or109 quality criteria. Spawn prompt: "General review -- no prescribed dimension. Follow any thread. Focus on behavioral110 regressions: semantic contracts, lifecycle guarantees, concurrency, and anything the dimension surfacers might miss."1111125. Wait for all surfacers. They record findings and call `mcp__kensai__surface_clean` or113 `mcp__kensai__finding_surface` via MCP.1146. **Shut down all surfacers.**115116### Phase 3: Proving1171181. Call `mcp__kensai__surfacing_complete`. If 0 findings -> skips to filing.1192. Spawn a `review-prover` teammate. Prover self-serves findings and context via MCP, applies falsification gates,120 verdicts each finding.1213. Wait for prover to complete.1224. **Check for unverdicted findings** — call `mcp__kensai__findings_list` with `status: "pending"`. If any remain,123 message the prover with the pending finding IDs and wait. Repeat until all are handled.1245. **Shut down the prover.**125126### Phase 4: Filing1271281. Read confirmed findings from `mcp__kensai__findings_list` with `status: "confirmed"`.1292. Apply last-gate filter: already handled? Intentional? Not actionable? Speculative? Boundary crossing? Drop if any.1303. Write the terminal report. One issue per finding. Assertions, not questions. Quote code, cite `file:line`.1314. Call `mcp__kensai__filing_complete`.1325. Call `mcp__kensai__session_end`.1336. **Clean up the team.**134135The MCP enforces phase order. Tools reject calls outside their valid phase.