A risk register made of Claude Code controls
Map the risk in a diff, or in a plan before any code exists. The lab combines path tiers, content signals in changed lines, an ast import-graph blast radius and plan drift. Then it turns each mitigation into something Claude Code enforces or a person decides: an ask or deny rule, a hook, a test, a review command or a human. Session: Risk Mapping and Unresolved Risks.
- Python 3.9+
- standard library only
- offline:
samples/change.diff,samples/plan.md,samples/risk_rules.json - reads
common/samples/tiny-app
python3 delivery-3/risk_map.py
The sample diff makes the case-insensitive discount change, and it also does three things the plan forbade.
┌──────────────────────────────────────────────────────────────────────┐
│ Risk map · delivery-3/samples/change.diff + delivery-3/samples/plan.md │
└──────────────────────────────────────────────────────────────────────┘
[1] What changed
file status +/- tier category protected why (path rule)
───────────────────── ──────── ───── ────── ────────────── ───────── ────────────────────────────────────────────────────
CLAUDE.md modified +1/-0 medium agent-behavior - changes what every future session is told; CLAUDE.m…
.claude/settings.json added +9/-0 high agent-config yes changes what Claude may do without asking (permissi…
tests/test_cart.py modified +0/-1 low tests - test code (removals are caught by content signals)
tests/test_pricing.py modified +6/-0 low tests - test code (removals are caught by content signals)
tinyapp/pricing.py modified +4/-3 high money - money, tax and discount rules: every receipt goes t…
24 changed lines in 5 files
[2] Content signals in added/removed lines
where tier signal line
────────────────────────────── ────── ───────────────── ────────────────────────────────────────────────
.claude/settings.json:5 high broad-allow + "Bash(*)"
tests/test_cart.py:20 (before) high removed-assertion - self.assertEqual(cart.tax(), 65) # 900 * 7.2…
tinyapp/pricing.py:32 high float-money + rate = pct / 100 (+1 more: line 33)
.claude/settings.json:7 medium default-mode + "defaultMode": "acceptEdits"
[3] Blast radius (import graph of common/samples/tiny-app)
file dependents tests that import it targeted test command
────────────────── ────────── ───────────────────────────── ──────────────────────────────────────────────────────
tinyapp/pricing.py 5 test_cart.py, test_pricing.py python3 -m unittest tests.test_cart tests.test_pricing
[4] Plan vs diff
out of scope but changed: .claude/settings.json, tests/test_cart.py
changed, not in the plan: CLAUDE.md
planned, not changed: README.md, tinyapp/__init__.py
[5] Risk register (13 risks)
id tier where category risk mitigations
─── ────── ────────────────────────────── ────────────── ────────────────────────────────────────────────────────── ─────────────────────────────────
R1 high .claude/settings.json agent-config changes what Claude may do without asking (permissions, h… deny-edit, human, security-review
R2 high .claude/settings.json scope the plan put .claude/ out of scope, and the diff changes … human
R3 high .claude/settings.json:5 agent-config a whole-tool Bash allow rule pre-approves every shell com… deny-edit, human, security-review
R4 high tests/test_cart.py scope the plan put tests/test_cart.py out of scope, and the dif… human
R5 high tests/test_cart.py:20 (before) tests an assertion was deleted: the suite still passes but chec… human, code-review-high
R6 high tinyapp/pricing.py money money, tax and discount rules: every receipt goes through… ask-edit, test, code-review-high
R7 high tinyapp/pricing.py:32 money float math or round() in money code (CLAUDE.md: never int… test, hook, code-review-high
R8 medium .claude/settings.json:7 agent-config changes the permission mode every session in this repo st… human
R9 medium CLAUDE.md agent-behavior changes what every future session is told; CLAUDE.md is c… human
R10 medium CLAUDE.md scope the diff changes a file the plan never mentions human
R11 medium tinyapp/pricing.py blast-radius 5 modules import it (directly or transitively); 2 test mo… test
R12 low tests/test_cart.py tests test code (removals are caught by content signals) test
R13 low tests/test_pricing.py tests test code (removals are caught by content signals) test
[6] Mitigations as Claude Code controls
.claude/settings.json fragment (review it before merging; written to out/settings_snippet.json):
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"ask": [
"Edit(/tinyapp/pricing.py)"
],
"deny": [
"Edit(/.claude/settings.json)"
]
}
}
• ask rules prompt in every mode that prompts, auto mode included (dontAsk denies them); deny rules block in every mode, bypassPermissions included
• protected paths (.claude/settings.json): default/acceptEdits prompt, auto -> classifier, dontAsk denies, bypassPermissions allows; only a deny rule holds everywhere
• Edit rules also cover sed/tee and redirections in Bash, not a script that opens the file itself: pair with the sandbox
hook mitigation (sketch): a PostToolUse hook on Edit|Write that rejects float math in money files;
see delivery-4/ci_gate and agents-5/guard_hooks for working gate hooks.
[7] Review route (deterministic first; review commands advise, people and checks gate)
1. python3 -m unittest tests.test_cart tests.test_pricing (then the full suite: python3 -m unittest) [check]
deterministic: the cheapest gate, run it first and show the output
2. /code-review high [advisory]
correctness review of the diff (3 high correctness risk(s))
3. /security-review [advisory]
agent config / CI / dependency / security changes: .claude/settings.json (needs an origin remote)
4. send the plan drift back to Claude [check]
revert or justify: .claude/settings.json, CLAUDE.md, tests/test_cart.py
5. human approval (CODEOWNERS / required reviewer) [gate]
high risk with a human gate: .claude/settings.json, tests/test_cart.py
every high risk has a gate or a deterministic check
wrote out/risk_map.md and out/settings_snippet.json
- Agent config is code. A new
.claude/settings.jsonchanges what Claude may do without asking in every future session, so it sits in the high tier with money code. - The suite still passes on this diff, yet it adds
Bash(*), deletes an assertion and brings float math into money code. CLAUDE.md already says "Never introduce floats for money"; a rule that's still being broken has to become a check. - The blast radius from the import graph: five modules depend on
pricing.py, so the targeted test command runs both test modules. - Plan drift, found before anyone reads the code: two files the plan put out of scope, one it never mentioned. Send that back to Claude first.
- The settings snippet: deny edits to
.claude/settings.json, and ask before edits topricing.py..claude/is already a protected path, but only a deny rule holds in every mode. /code-reviewand/security-revieware marked advisory. The route runs the deterministic check first and ends with a human gate.
- Run it on the plan alone, before any code exists:
--plan delivery-3/samples/plan.md. There are no content signals ("a plan has no code yet"), 6 risks instead of 13, and the snippet holds only the ask rule forpricing.py. - Check the "suite still passes" claim yourself. Copy
common/samples/tiny-appto a scratch directory,git applydelivery-3/samples/change.diffthere, and runpython3 -B -m unittest: 15 tests,OK. --strictexits 0 on the sample, because every high risk has a gate or a deterministic check. Break it: in a copy ofsamples/risk_rules.json, set thefloat-moneysignal'smitigationsto["code-review-high"]and run--strict --rules <copy>. It exits 1:R7 tinyapp/pricing.py:32: only advisory mitigations (code-review-high); add a gate or a deterministic check.- On your own work:
git diff main... > /tmp/d.diff, then--diff /tmp/d.diff --repo /path/to/repo. Which rows are noise for your codebase? Tune a copy ofrisk_rules.json(--rules) until the top three are the ones you'd check first.
- Run it twice: on the plan before you approve it, and on the diff before you merge. Drift between the two is the cheapest finding there is.
- "Deny rules block in every mode, including
bypassPermissions." An ask rule prompts even in auto mode; indontAskit denies (permission modes). - Review commands find things; they don't decide. Managed Code Review states it plainly: "A review never approves or blocks the pull request" (code review). So
--strictwants a rule, a hook, a test or a person on every high risk. - Read and Edit deny rules also cover the Bash file commands Claude Code recognizes, such as
sedandtee, and redirect targets. They don't cover a script that opens the file itself, so pair them with the sandbox (permissions).
Footprints, waves and merge points
Plan parallel Claude Code sessions from what each task writes and reads. The lab builds an overlap matrix, waves with the reason each delayed task waits, what-ifs on seats and hotspots, and an ordered list of merge points with the stale reads git can't see. Each task gets a mechanism: a claude --worktree session, a read-only subagent, the main checkout, /batch or agent teams. Session: Parallel Sessions and Merge Points.
- Python 3.9+
- standard library only
- offline:
samples/parallel_tasks.json(nine tiny-app tasks)
python3 delivery-3/parallel_plan.py
┌─────────────────────────────────────────────────────────────────────────┐
│ Parallel plan · tiny-app: discount codes v2, receipts and money parsing │
└─────────────────────────────────────────────────────────────────────────┘
[1] 9 tasks, footprints expanded against the repo
task kind size writes deps
────────────── ─────────── ──── ────────────────────────────────────────────────────────── ──────────────────────────────────────────────
codes-ci edit S tests/test_pricing.py, tinyapp/pricing.py -
region-wa edit S tests/test_pricing.py, tinyapp/pricing.py -
receipt-json edit M tests/test_cart.py, tinyapp/cli.py -
remove-qty edit S tests/test_cart.py, tinyapp/cart.py -
parse-money edit M tests/test_money.py, tinyapp/__init__.py, tinyapp/money.py -
export-receipt edit S tinyapp/__init__.py -
float-audit investigate S (read-only) -
docs-refresh edit S CLAUDE.md, README.md codes-ci, region-wa, receipt-json, parse-money
version-bump edit S tinyapp/__init__.py docs-refresh, remove-qty, export-receipt
[2] Overlap matrix (W write-write: git conflict · r write-read: semantic conflict · d dependency)
# task 1 2 3 4 5 6 7 8 9
─ ────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─
1 codes-ci \ W r r r · r d ·
2 region-wa W \ r r r · r d ·
3 receipt-json r r \ W · r r d ·
4 remove-qty r r W \ · · r · d
5 parse-money r r · · \ W r r W
6 export-receipt · · r · W \ r r W
7 float-audit r r r r r r \ · r
8 docs-refresh d d d · r r · \ r
9 version-bump · · · d W W r r \
hotspot: tinyapp/__init__.py is written by 3 tasks (parse-money, export-receipt, version-bump)
[3] Waves (at most 3 writers at once)
wave 1
codes-ci worktree session claude --worktree codes-ci
receipt-json worktree session claude --worktree receipt-json
parse-money worktree session claude --worktree parse-money
float-audit subagent (read-only) in the main session: "Use the Explore subagent (very thorough) to audit tinyapp/ for float math in money paths; report file:line"
wave 2
region-wa worktree session claude --worktree region-wa
remove-qty worktree session claude --worktree remove-qty
export-receipt worktree session claude --worktree export-receipt
wave 3
docs-refresh main checkout claude (one writer in this wave: no isolation needed)
wave 4
version-bump main checkout claude (one writer in this wave: no isolation needed)
waves: 4 (lower bound 3: codes-ci -> docs-refresh -> version-bump); 9 tasks one by one
why some tasks wait:
task earliest by deps wave reason
────────────── ──────────────── ──── ──────────────────────────────────────────────────────────────
region-wa 1 2 writes tests/test_pricing.py, tinyapp/pricing.py like codes-ci
remove-qty 1 2 writes tests/test_cart.py like receipt-json
export-receipt 1 2 writes tinyapp/__init__.py like parse-money
docs-refresh 2 3 waits for region-wa (wave 2)
version-bump 3 4 waits for docs-refresh (wave 3)
W1 W2 W3 W4
codes-ci ████
receipt-json ████
parse-money ████
float-audit ░░░░
region-wa ████
remove-qty ████
export-receipt ████
docs-refresh ████
version-bump ████
merge ◆ ◆
[4] What-ifs: is it seats or footprints?
scenario waves widest wave wave 1
─────────────────────────────────────────────────────────── ───── ─────────── ────────────────────────────────────────────────────────────────
as planned (max 3 writers) 4 3 codes-ci, receipt-json, parse-money, float-audit
unlimited writers 4 3 codes-ci, receipt-json, parse-money, float-audit
hotspot edits (tinyapp/__init__.py) applied at merge points 4 3 codes-ci, receipt-json, parse-money, float-audit
both 4 4 codes-ci, receipt-json, parse-money, export-receipt, float-audit
[5] Merge points (merge in this order, run the tests after each merge)
after wave 1: codes-ci -> parse-money -> receipt-json
re-check receipt-json against codes-ci (pricing.py): it was built on the old version (a stale read git can't see)
re-check parse-money against codes-ci (pricing.py): it was built on the old version (a stale read git can't see)
re-run float-audit on the merged tree: it read the base, before codes-ci (pricing.py), receipt-json (cli.py), parse-money (__init__.py)
hotspot tinyapp/__init__.py: waves 2 and 4 edit it again; keep this change small and merge it first
git merge --no-ff worktree-codes-ci && python3 -m unittest (and so on; cleanup: git worktree unlock .claude/worktrees/<id>; git worktree remove .claude/worktrees/<id>)
before wave 2: push the merged default branch (or set worktree.baseRef to "head");
new worktrees branch from the remote default branch by default and would miss this merge
after wave 2: region-wa -> export-receipt -> remove-qty
re-check remove-qty against region-wa (pricing.py): it was built on the old version (a stale read git can't see)
hotspot tinyapp/__init__.py: wave 4 edits it again; keep this change small and merge it first
git merge --no-ff worktree-region-wa && python3 -m unittest (and so on; cleanup: git worktree unlock .claude/worktrees/<id>; git worktree remove .claude/worktrees/<id>)
before wave 3: push the merged default branch (or set worktree.baseRef to "head");
new worktrees branch from the remote default branch by default and would miss this merge
[6] Before you start
• add .claude/worktrees/ to .gitignore; the repo needs at least one commit
• a worktree is a fresh checkout: list gitignored files it needs (.env) in .worktreeinclude
• claude --worktree <id> creates .claude/worktrees/<id>/ on branch worktree-<id>, from the remote default branch unless worktree.baseRef is "head"
• on exit a clean worktree of an unnamed session is removed, one with work in it prompts; -p never cleans up and leaves Claude Code's lock (git worktree unlock, then git worktree remove)
• headless variant: claude -p --worktree <id> "<task>" --permission-mode acceptEdits --allowedTools "Bash(python3 -m unittest *)" --max-turns 20 --max-budget-usd 2
• subagents return only a summary to the main session; a subagent with isolation: worktree gets its own worktree
• /batch <instruction> fits 5-30 similar units, one worktree-isolated subagent each (needs git or a WorktreeCreate hook)
• agent teams are experimental and off by default (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1)
• several sessions at once multiply token usage; review is the bottleneck, so plan merge points you can review
wrote out/parallel_plan.md
Wis a write-write overlap, which git will report as a conflict.ris a write-read overlap, a semantic conflict git never sees. codes-ci and region-wa write the same two files.- The read-only audit doesn't need a worktree. It runs as an Explore subagent in the main session, which returns only a summary.
- region-wa could start at once by its dependencies, but it waits a wave because of that one write-write overlap. The wait pushes docs-refresh and version-bump back as well.
- Unlimited writers still take 4 waves. Footprints cap parallelism here, not seats.
- Stale reads: receipt-json and parse-money were built against the old
pricing.py. Merge codes-ci first, then rerun the tests after each later merge. - New worktrees branch from the remote default branch, so push the merged branch (or set
worktree.baseRefto"head") before wave 2, or wave 2 won't contain wave 1.
--max-parallel 6: stillwaves: 4. More seats don't help while two tasks share a file.- Split along file boundaries. In a copy of
samples/parallel_tasks.json, make region-wa writetinyapp/regions.pyandtests/test_regions.py, then run--tasks <copy>. With--max-parallel 3it's still 4 waves, but region-wa's reason becomesno free seat (raise --max-parallel). With--max-parallel 4it reaches the lower bound of 3 waves. The split moved the constraint from footprints to seats. - Break it: make codes-ci depend on
version-bump. The planner exits 2 witherror: dependency cycle: codes-ci -> version-bump -> docs-refresh -> codes-cirather than produce a schedule. - On a real feature: ask Claude in plan mode for each task's write and read files as JSON in this format, and pass it with
--tasks my_tasks.json --repo /path/to/repo. Where does your first merge point land?
- Plan parallel work around files, not headcount. A shared file costs a wave, and a hotspot such as
tinyapp/__init__.py(three writers) is worth deferring to the merge points. - A write-read overlap is the one git won't flag. The merge order and the reruns in step 5 are there to catch it.
-psessions never clean up their worktrees and keep Claude Code's lock until a later session's stale-lock sweep, so cleanup isgit worktree unlock, thengit worktree remove(worktrees).- Agent teams are experimental and disabled by default (
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1), so the planner picks them only for tasks marked"kind": "coordinate"(agent teams).