Team board: catch collisions while they're cheap

Read a task board and the hook-logged activity of four parallel claude --worktree sessions. Raise each alert at the moment it could have fired, replay the kit's real footprint guard on the same edits, and end with a merge plan a human runs. Session background: collision detection, intervention, worktrees and merge points.

  • Python 3.9+
  • standard library only
  • offline: board/board.json and board/events.jsonl
  • the guard runs in a temp directory

The board (a lab format) gives each task an owner, a worktree, a footprint of files and its dependencies. The events are hook payloads in the documented shapes (SessionStart, PostToolUse, Stop, TaskCompleted), each wrapped with the time it was logged. The script parses the sample repo with ast, so only two edits to the same function count as a collision; two edits to the same file don't.

python3 autonomy-3/team_board.py
┌────────────────────────────────────┐
│ Team board: gift-cards as of 11:20 │
└────────────────────────────────────┘
[1] Board
pending                        in progress                         completed                         
─────────────────────────────  ──────────────────────────────────  ──────────────────────────────────
T6 reviewer (0 edits, last -)  T3 builder-c (2 edits, last 10:45)  T1 builder-a (2 edits, last 10:16)
                               T5 builder-a (1 edits, last 10:52)  T2 builder-b (3 edits, last 10:38)
                                                                   T4 builder-d (2 edits, last 10:21)
[2] Alerts, in the order they could have fired
   plan  PLAN      T2 and T4 both claim tinyapp/pricing.py and nothing orders them
         -> narrow one footprint, or make T2 depend on T4
  10:08  DEPENDS   builder-b edited tinyapp/cart.py for T2 while its dependency T1 is in progress
         -> pause gift-checkout until T1 completes, then rebase on T1's branch
  10:14  COLLISION tinyapp/pricing.py::apply_discount rewritten in codes-case (10:07) and gift-checkout (10:14)
         -> stop one session (claude stop <id>, or message the teammate); merge T4 first, then rebase T2 and rerun the check
  10:22  FOOTPRINT builder-b (T2) edited tinyapp/__init__.py, T5's file
         -> move the change into T5
  10:30  COLLISION tinyapp/__init__.py::module level rewritten in gift-checkout (10:22) and gift-export (10:30)
         -> stop one session (claude stop <id>, or message the teammate); merge T2 first, then rebase T5 and rerun the check
  11:20  STALLED   builder-c has been silent on T3 for 35 min (last activity 10:45)
         -> check it (claude attach <id> / claude logs <id>), then nudge or reassign
[3] Edits by file and function (from the PostToolUse log)
at     task  worktree       tool   file                     function                      
─────  ────  ─────────────  ─────  ───────────────────────  ──────────────────────────────
10:05  T1    gift-model     Write  tinyapp/giftcards.py     <new file>                    
10:07  T4    codes-case     Edit   tinyapp/pricing.py       apply_discount                
10:08  T2    gift-checkout  Edit   tinyapp/cart.py          Cart.total                    
10:10  T1    gift-model     Write  tests/test_giftcards.py  <new file>                    
10:14  T2    gift-checkout  Edit   tinyapp/pricing.py       apply_discount                
10:18  T4    codes-case     Edit   tests/test_pricing.py    DiscountTest.test_unknown_code
10:22  T2    gift-checkout  Edit   tinyapp/__init__.py      module level                  
10:30  T5    gift-export    Edit   tinyapp/__init__.py      module level                  
10:41  T3    gift-receipt   Edit   tinyapp/cli.py           receipt                       
10:45  T3    gift-receipt   Write  tests/test_cli.py        <new file>                    
[4] Prevention: the kit's footprint guard replayed on the same edits (PreToolUse, real hook)
at     worktree       file                     guard       why                                                                   
─────  ─────────────  ───────────────────────  ──────────  ──────────────────────────────────────────────────────────────────────
10:05  gift-model     tinyapp/giftcards.py     no opinion                                                                        
10:07  codes-case     tinyapp/pricing.py       no opinion                                                                        
10:08  gift-checkout  tinyapp/cart.py          no opinion                                                                        
10:10  gift-model     tests/test_giftcards.py  no opinion                                                                        
10:14  gift-checkout  tinyapp/pricing.py       no opinion                                                                        
10:18  codes-case     tests/test_pricing.py    no opinion                                                                        
10:22  gift-checkout  tinyapp/__init__.py      deny        tinyapp/__init__.py belongs to T5 (Export the gift card API, owner bui
10:30  gift-export    tinyapp/__init__.py      no opinion                                                                        
10:41  gift-receipt   tinyapp/cli.py           no opinion                                                                        
10:45  gift-receipt   tests/test_cli.py        no opinion                                                                        
  The guard follows the board. Where the plan lets two tasks own a file, it allows both edits: fix the plan.
[5] Merge plan (dependencies first, then completion order; a human merges)
#  task  branch (worktree)  completed    before merging                     after                    
─  ────  ─────────────────  ───────────  ─────────────────────────────────  ─────────────────────────
1  T1    gift-model         10:16        -                                  run the integration check
2  T4    codes-case         10:21        -                                  run the integration check
3  T2    gift-checkout      10:38        rebase on T4 first: same function  run the integration check
-  T3    gift-receipt       in progress  not ready                          wait                     
-  T5    gift-export        in progress  not ready                          wait                     
  after each merge: python3 -m unittest -q on the integration branch; stop at the first failure

wrote autonomy-3/out/team_board/report.json
alerts: 2 COLLISION, 1 DEPENDS, 1 FOOTPRINT, 1 PLAN, 1 STALLED
  1. The cheapest alert fires before any session starts: two tasks claim pricing.py and nothing orders them. The advice follows the merge plan below: narrow a footprint, or make T2 depend on T4.
  2. A collision is two worktrees rewriting the same function, apply_discount, seven minutes apart. The advice names the intervention and the merge order.
  3. Silence is a signal too. 35 minutes without activity on T3 means look at the session, then nudge or reassign it.
  4. Replayed on the same edit, the kit's PreToolUse guard would have denied the 10:22 edit outright and named the task that owns the file.
  5. The apply_discount clash gets through the guard, because the board lets both tasks own pricing.py. The guard can only enforce the plan you wrote.
  6. The merge plan: dependencies first, then completion order, with a rebase where two branches touched the same function. A human merges, and runs the check after each one.

Install the kit in a repo (from labs/):

cp -r autonomy-3/team_board/kit/.claude <repo>/          # merge settings.json by hand if you have one
FileWhat it does
.claude/settings.jsonRegisters the guard on PreToolUse for Edit|Write|NotebookEdit (timeout 10, "onFailure": "block"), and the logger on PostToolUse, SessionStart, Stop, TaskCreated and TaskCompleted.
.claude/hooks/footprint_guard.pyNo output for a file in this task's footprint, deny naming the owner for another task's file, ask for a file in no footprint, and deny when it can't read the board.
.claude/hooks/board_log.pyAppends every event to <repo>/.claude/team-board-events.jsonl, trimmed. It only observes, and exits 0 even when it can't write.
.claude/team-board.jsonThe board, in the lab format. Keep it current in the main checkout as the plan changes.

Then commit the hooks and settings.json so every worktree has them, add .claude/worktrees/ and .claude/team-board-events.jsonl to .gitignore, and start each task with claude --worktree <name>. To watch the team: python3 autonomy-3/team_board.py --board <repo>/.claude/team-board.json --events <repo>/.claude/team-board-events.jsonl --repo <repo>. Completion comes from the TaskCompleted hook, which fires only where the task tools exist: by default on Opus 4.7, Sonnet 4.6, Haiku 4.5 and earlier models. On newer models, start each session with CLAUDE_CODE_ENABLE_TODO_TOOLS=1, or the board never sees a task complete.

  • Rewind the clock: --at 10:15 shows what the lead could see then. Three builders are in progress, and the apply_discount collision is already on the board, a minute after it happened. --at 10:21 (exercise 3) adds T1 and T4 as completed and mergeable.
  • Exercise 1: in a copy of board/board.json, remove tinyapp/pricing.py from T2's footprint and pass it with --board. The PLAN alert goes away, a FOOTPRINT alert appears at 10:14, and the guard replay now denies the 10:14 edit: "tinyapp/pricing.py belongs to T4".
  • Exercise 2: instead, add "depends_on": ["T4"] to T2. The PLAN alert goes away and a second DEPENDS alert appears at 10:08, because T2 started while T4 was still in progress. The collision is still raised: an order on paper doesn't stop a session from starting early.
  • --stale-minutes 60 raises the silence threshold, and the STALLED alert disappears. Decide what silence means for your tasks before you trust the default.
  • Break it: --at 25:99 is refused ("--at takes HH:MM (on the last day in the log) or a full timestamp") and exits 2.
  • The earlier an alert fires, the cheaper the fix: PLAN before any session starts, FOOTPRINT on the first stray edit, COLLISION only once the work is already duplicated.
  • Worktrees keep sessions from overwriting each other's files. The real risk is the merge, two branches rewriting the same function, so plan the merge order.
  • The guard is defense in depth. A Bash command can still write anywhere the permission rules and sandbox allow, and the guard knows a session's task only from the input cwd, which moves when Claude runs cd.
  • Claude Code picks its own task ids, so the board matches tasks by task_subject.

Routing: a model and an effort level per task

Route eight work items by role, risk and complexity to a model alias and an effort level, clamp them with the org caps, estimate each route's cost against an all-Opus baseline, price a mid-session /model switch against a subagent, and write one subagent file per role. Session background: model choice, effort, cost and speed and roles.

  • Python 3.9+
  • standard library only
  • offline: routing/tasks.json and routing/policy.json

Each task has a role (explorer, planner, builder, reviewer, validator, triager), a risk, a complexity, and assumed turns and context. Risk raises both the model and the effort, complexity raises only the effort, and builders never drop below Sonnet. The costs use the list prices in common/llm.py and assumed output tokens per effort level, so they're illustrative.

python3 autonomy-3/routing.py
┌──────────────────────────────────────────────────┐
│ Routing: model and effort by role, risk and cost │
└──────────────────────────────────────────────────┘
  org caps: availableModels=['opus', 'sonnet', 'haiku']  maxEffortLevel=xhigh
  baseline: opus/high for everything
[1] Routes
task                role       model   effort  fallback  est. cost  baseline  saved
──────────────────  ─────────  ──────  ──────  ────────  ─────────  ────────  ─────
find-callers        explorer   haiku   low     sonnet    $0.008     $0.456    98%  
plan-gift-cards     planner    opus    xhigh   sonnet    $1.204     $1.004    -20% 
build-gift-cards    builder    sonnet  medium  opus      $0.936     $2.352    60%  
fix-typo            builder    sonnet  low     opus      $0.084     $0.246    66%  
migrate-rounding    builder    opus    xhigh   sonnet    $4.176     $3.376    -24% 
review-diff         reviewer   opus    xhigh   sonnet    $0.848     $0.688    -23% 
summarize-failures  validator  haiku   low     sonnet    $0.006     $0.324    98%  
label-issues        triager    haiku   low     sonnet    $0.028     $2.032    99%  
  total $7.29 vs $10.48 baseline (30% less). Illustrative: list prices from common/llm.py and assumed output tokens per effort level.
  The role table and the risk/complexity adjustments are this lab's heuristics. Documented: the aliases, the availableModels and maxEffortLevel caps, where each route is set, and the cache behavior.
  Aliases resolve per provider: on Bedrock and Agent Platform `sonnet` is Sonnet 4.5 and `haiku` is Haiku 4.5, and on Foundry `opus` is Opus 4.6 (no xhigh). Pin ANTHROPIC_DEFAULT_*_MODEL there (on Bedrock with us.anthropic.… inference-profile IDs) before trusting these prices.
[2] Why, and where to set it
  find-callers: explorer: haiku/low (lookups move down to Haiku)
      set in: .claude/agents/explorer.md (model: haiku, effort: low); overload fallback: --fallback-model sonnet
  plan-gift-cards: planner: opus/high (a wrong plan costs more than the tokens); complexity high: effort up one -> xhigh
      set in: .claude/agents/planner.md (model: opus, effort: high); for this task, override per invocation to opus/xhigh (per-invocation effort: v2.1.292+); overload fallback: --fallback-model sonnet
  build-gift-cards: builder: sonnet/medium (writing code stays on a strong model)
      set in: main session: claude --model sonnet --effort medium (set at the start, before the cache warms); overload fallback: --fallback-model opus
  fix-typo: builder: sonnet/medium (writing code stays on a strong model); low risk, low complexity: effort down one -> low
      set in: main session: claude --model sonnet --effort low (set at the start, before the cache warms); overload fallback: --fallback-model opus
  migrate-rounding: builder: sonnet/medium (writing code stays on a strong model); risk high: model and effort up one -> opus/high; complexity high: effort up one -> xhigh
      set in: main session: claude --model opus --effort xhigh (set at the start, before the cache warms); overload fallback: --fallback-model sonnet
  review-diff: reviewer: opus/high (a fresh, strong reader catches what the builder missed); risk high: model and effort up one -> fable/xhigh; availableModels doesn't allow fable: using opus
      set in: .claude/agents/reviewer.md (model: opus, effort: high); for this task, override per invocation to opus/xhigh (per-invocation effort: v2.1.292+); overload fallback: --fallback-model sonnet
  summarize-failures: validator: haiku/low (runs a check and reports; no judgment calls)
      set in: .claude/agents/validator.md (model: haiku, effort: low); overload fallback: --fallback-model sonnet
  label-issues: triager: haiku/low (many small, similar decisions; latency and cost dominate)
      set in: .claude/agents/triager.md (model: haiku, effort: low); overload fallback: --fallback-model sonnet
[3] Switching the main session (sonnet) vs a subagent, per task with another model
task                model change     /model mid-session (cache write)  subagent brief (cache write)
──────────────────  ───────────────  ────────────────────────────────  ────────────────────────────
find-callers        sonnet -> haiku  $0.004                            $0.001                      
plan-gift-cards     sonnet -> opus   $0.400                            $0.040                      
migrate-rounding    sonnet -> opus   $0.600                            $0.040                      
review-diff         sonnet -> opus   $0.250                            $0.040                      
summarize-failures  sonnet -> haiku  $0.003                            $0.001                      
label-issues        sonnet -> haiku  $0.002                            $0.001                      
  Each model has its own cache, so a mid-session switch re-writes the whole conversation; spawning a subagent doesn't touch the main session's cache.
  One session that plans and then builds: `--model opusplan` (opus in plan mode, sonnet for execution).
[4] Subagent files (copy into .claude/agents/ to use them)
  builder.md: tools: Read, Edit, Write, Bash, model: sonnet, effort: medium
  explorer.md: tools: Read, Grep, Glob, model: haiku, effort: low
  planner.md: tools: Read, Grep, Glob, model: opus, effort: high
  reviewer.md: tools: Read, Grep, Glob, model: opus, effort: high
  triager.md: tools: Read, Grep, Glob, model: haiku, effort: low
  validator.md: tools: Read, Bash, model: haiku, effort: low

wrote autonomy-3/out/routing/routes.json and 6 files in autonomy-3/out/routing/agents/
  1. Builders stay on Sonnet or better, however small the change. migrate-rounding is high risk and high complexity, so it moves up to Opus at xhigh.
  2. Routing saves 30% overall, but not on every task: the plan, the migration and the review cost more than the baseline, on purpose.
  3. Org caps win. Risk would push the reviewer up to Fable, but availableModels doesn't list it, so the route falls back to Opus.
  4. Switching the main session to Opus for the review re-writes 50k tokens of cache ($0.250), because each model has its own cache. A reviewer subagent starts from a $0.040 brief.
  5. One session that plans on Opus and builds on Sonnet doesn't need a switch at all: --model opusplan.
  6. The builder and validator lists include Bash and leave out Grep and Glob. On macOS, Linux and WSL a subagent gets those two back only when its tools list leaves out Bash, so these roles search through Bash.

The subagent files are ready to copy into .claude/agents/. The builder's:

cat autonomy-3/out/routing/agents/builder.md
---
name: builder
description: Builder for routed work: writing code stays on a strong model.
tools: Read, Edit, Write, Bash
model: sonnet
effort: medium
---

You are the team's builder. Do only that job and report back in under 200 words.
Cite files as path:line. If the task needs a different role, say so instead of doing it.
  1. The description is what Claude reads when it decides whether to delegate to this subagent.
  2. Only the tools the role will really have. Adding Grep and Glob here wouldn't bring them back by itself: the subagent would also have to drop Bash.
  3. The route itself, in frontmatter. A per-invocation override can still raise the effort for one task.
  • Tighten the org caps: --max-effort medium --models sonnet,haiku. The planner and reviewer drop to Sonnet at medium, migrate-rounding is clamped to Sonnet at medium, the builders lose their fallback, and the total falls to $3.13. Exercise 1 asks which of those routes then deserve a stronger model instead.
  • Break it: --models haiku. The three builder tasks show blocked ("availableModels allows nothing at or above the sonnet floor: blocked by policy"), and builder.md isn't written. A route that can't meet its floor is blocked, not quietly downgraded.
  • --main-model opus reprices the switches from an Opus main session. Moving to Sonnet for build-gift-cards costs a $0.225 cache write, against $0.020 for a subagent brief.
  • Exercise 2: put the num_turns and context size of one of your own result events into a copy of routing/tasks.json, pass it with --tasks, and compare the estimate with that run's total_cost_usd.

Run the find-callers route for real through your Claude Code login: claude -p, read-only, Haiku at --effort low, in a temp copy of the sample repo, capped at --max-turns 4 and --max-budget-usd 0.05 by default:

python3 autonomy-3/routing.py --real

The run recorded while building the labs (v2.1.303, on Bedrock) took 2 turns and one Grep call and cost $0.001866, about a quarter of the route's $0.008 estimate. The cap is checked against a client-side estimate that can overshoot by one response. Exercise 4 runs it twice, with --max-turns 2 and --max-turns 6, to see how num_turns and the cost move. Like every real lab run, it may leave an empty ~/.claude/projects/<temp dir>/memory/ folder behind.

  • Route at session boundaries: set the main session's --model and --effort at the start, and give roles their own subagent files, so no route pays for a cache rewrite.
  • Org caps clamp every route. maxEffortLevel takes the lowest cap from any source, and nothing can raise it.
  • Aliases resolve per provider, so pin ANTHROPIC_DEFAULT_*_MODEL on Bedrock, Agent Platform and Foundry before you trust any price here.
  • The estimate is a starting point. The one real run cost a quarter of it, which is why exercise 2 asks for your own numbers.