2buildDocumentationGitHub
2build / DocumentationRead Markdown (.md) View source

Token cost in a session

Where the tokens of an autopilot or review-pr run go once a session is running, what every session pays before it starts work, what was changed on 2026-10-25, and how to check the changes. The session and prompt-cache side (cold sessions, ticket boundaries, Foreman wakes) is in foreman-cache-economics.md; this document covers what that one does not.

Every figure comes from /bbs:token-audit, whose script (.claude/skills/token-audit/scripts/token_audit.py) reads local Claude Code, Codex and OMP session logs:

bash
python3 .claude/skills/token-audit/scripts/token_audit.py usage --since 2026-10-15 --project babysit-worktrees --harness claude
python3 .claude/skills/token-audit/scripts/token_audit.py context --repo <repo>

Figures are weighted tokens: input 1, 5-minute cache write 1.25, 1-hour cache write 2, cache read 0.1, output 5. Because output is included, the totals are higher than the input-equivalent totals in foreman-cache-economics.md (681.6M here against 476.9M there for the same 136 sessions). Shares are comparable within one report; they are not prices.

Baseline: worker sessions, 2026-10-15 to 2026-10-25

136 Claude Code worker sessions (babysit-worktrees projects), 681.6M weighted.

MetricValue
Main thread / subagents81% / 19%
Main thread by componentcache read 53%, 1h cache write 17%, output 11% (of the total)
Subagents by component1h cache write 10%, cache read 6%, output 2%
Context at the first request, median57.8k
Peak context, median265k
Turns per session, median152
Compactions148
Models, main threadOpus 50%, Sonnet 31%
Models, subagentsSonnet 19% (already set by CLAUDE_CODE_SUBAGENT_MODEL=sonnet)

Main thread by active skill:

SkillShare
qa20%
review-pr18%
autopilot18%
no skill yet (Foreman phase integration and setup)11%
plan-draft6%
browse5%

Subagents: review-pr's correctness angles A, B and C cost 7% between them (355k–459k per run); the cleanup, altitude and conventions finders cost about 2.5%; the verifiers about 4%.

Friction found in the same window:

SignalCountCause
bbs autopilot verification begin/record rejected~230subject changed after review-pr --fix (44), "already owns" an open attempt (42), empty log (25), missing --attempt (22), wrong gate name (18), cwd outside the checkout (11), extra results keys (5)
--help lookups644agents guessing flags the skill did not state
Orca heartbeats584removed in v1.107
Reviews repeated on the same ticket with the full fan-out22 of 68no rule for what a second review should target; one ticket was reviewed 6× on its whole web/ diff

What the baseline says

  1. The main thread is the cost. Cache reads of a ~165k context, over ~150 turns, are most of every run. A cheaper subagent model can only touch the 19%. Trimming skill text saves 1–2%.
  2. The one-hour subagent cache TTL cost ~4%. subagentPromptCacheTtl: "1h" made each short-lived subagent write its prefix at 2× instead of 1.25×, and most subagents never live long enough to read it back.
  3. Friction costs turns, and turns cost context. Every rejected verification call and --help lookup is a turn that re-reads the whole context.
  4. Repeated reviews were full reviews. About 7.5% of cost went to review runs that re-read a whole ticket diff to check a small fix.

Background context: what every session loads

Measured with token_audit.py context in the kiem-lai checkout (the 2build-consuming repo) on 2026-10-25.

ItemBeforeAfter
Claude Code skill listing (user, project, plugins)≈26.3k chars ≈ 7.5k tokens≈10.4k chars ≈ 3k tokens
claude.ai synced skills (anthropic-skills:*), almost all unused10.0k chars0.1k (skillOverrides)
User skills (~/.claude/skills), 10 of 14 unused in 30 days5.9k chars3.2k (5 removed, 4 name-only)
Project ops/content skills4.0k chars0.4k (disable-model-invocation: true on 17 of 19)
2build/.claude/skills relisted as 2build:* when work touches files under 2build/+6.5k charsunchanged (see below)
Stale skill-root copies without SKILL.md20
Auto-memory MEMORY.md25.1 KB / 174 lines (over the 24.4 KB read limit)16.0 KB / 137 lines

The listing is part of the cached prefix, so it is re-read on every turn: 4.5k tokens less is about 2–3% of the main-thread cost of a 150-turn run, in every repo that loads these roots.

Changes made on 2026-10-25

#ChangeWhereTargets
1Removed subagentPromptCacheTtl (back to the 5-minute default)user ~/.claude/settings.json1h subagent writes, ~4%
2Tiered review subagents: cleanup finders (Reuse, Simplification, Efficiency, Conventions) on the light tier; correctness angles, Altitude, verifiers and sweep on the mid tier; never above the session's model; inherit when the harness has no model selector (Codex, OMP); a routed model that is unavailable reruns on the inherited one, so no finder or vote is lostreview-pr/SKILL.md §5subagent share
3Delta re-review: each review gate snapshots its tree with a temporary index (GIT_INDEX_FILE, the real index is untouched) and stores it as review_tree. A later review on the same base, requirement and plan targets git diff <review_tree> <now> with the previous report as context. It falls back to the whole ticket diff when the base, requirement or plan changed, or when the delta is most of the diffautopilot/SKILL.md § Current-session gatesrepeated full reviews, ~7.5%
4Verification playbook: exact gate names, data.id, one open attempt per ticket, the three-key results file, --fix failing the attempt as expected, "already owns" recoveryautopilot/references/verification.mdrejected calls, ~2%
5/bbs:token-audit skill and script, so the next audit is one command and needs no re-derivation.claude/skills/token-audit/, tests/test_token_audit.shmeasurement
6Effort medium for the main modeluser ~/.claude/settings.jsonoutput and thinking
7Background context trimmed (table above): ops skills manual-only, unused skills removed (copies in ~/Backups/agent-skills-2026-10-25/), synced and artifact-* skills off by skillOverrideskiem-lai .claude/skills/*/SKILL.md, user settingsper-turn context

Tests: tests/test_autopilot_review_delta.sh drives the delta-review protocol against the real bbs binary; tests/test_autopilot_in_session_planning.sh pins the review-pr §5 and autopilot contracts; tests/test_token_audit.sh checks the script against synthetic Claude Code, Codex and OMP logs.

Checked and not done

LeverEstimateWhy not
Auto-compact window 300k → 200k~10% of main thread2.4× more compactions; it trades recall for cost, and forced compaction was removed on purpose. User decision.
Batch verifiers (several findings per verifier)~2%breaks the tuned one-finding, one-vote design
Shorter skill text1–2%not worth the risk to tuned prompts, which are sent word for word
Light tier for correctness anglespart of 7%correctness is where findings come from; judge by findings, not tokens
Hide the nested 2build:* relisting6.5k chars when touching 2build/no setting found that disables a nested project skill root; a per-name skillOverrides on 24 names would also hide bbs:*

Re-check

After a week of runs on the new skills:

bash
python3 .claude/skills/token-audit/scripts/token_audit.py usage --since <date> --project babysit-worktrees --harness claude
MetricBaselineExpectChange it tests
sub:write_1h share10%~0; 5-minute writes appear instead at a lower weight1
Subagent share19%lower; cleanup finders on the light model in by model2
review-pr share of the main thread18%lower; second reviews name a review_tree3
Errored bbs autopilot verification calls~230a handful4
--help lookups per session4.7lower4
First-turn context, median57.8klower by the trimmed listing (~4k)7
Output share of the main thread11%lower6

Watch for the cost of each lever as well: findings a light-tier finder missed (compare review reports before and after), delta reviews that missed a regression outside the fix, and ops skills nobody remembers to call by /name.