R03 - Fix rounds and compaction
Purpose: When a wave lead should resume a builder for review findings and when it should start a fresh one, and what Claude Code’s compaction and prompt cache settings do for builders, reviewers and leads. Measured over the V1-M2-walking-skeletonV1-M2-walking-skeleton: Walking skeletonwb-vmd boots a fixture VM bundle in its confined process, wb-guestd answers over vsock, a data disk made on the host holds the homes, and wb shell opens a PTY as a project user, with its output through the terminal fi… runs I307I307 (closed): Run 2026-10-16 (V1-M2-walking-skeleton, lane any)Size 4, 1 wave, lane any, milestone V1-M2-walking-skeleton (default: first open milestone in the version page's order with ready work for the lane)., I314I314 (closed): Run 2026-10-16 (V1-M2-walking-skeleton, lane any)Size 4, 1 wave, lane any, milestone V1-M2-walking-skeleton (default: first open milestone in the version page's order with ready work for the lane)., I323I323 (closed): Run 2026-10-16 (V1-M2-walking-skeleton, lane mac)Size 4, 5 waves, lane mac, milestone V1-M2-walking-skeleton (default: first open milestone in the version page's order with ready work for the lane)., I340I340 (closed): Run 2026-10-17 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-17)., I367I367 (closed): Run 2026-10-20 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-20). and waves 1 and 2 of I384I384 (closed): Run 2026-10-22 (V1-M2-walking-skeleton, lane mac)/wave --waves 5 --lane mac --merge (2026-10-16 to 2026-10-22). Issue I386I386 (closed): Fix rounds and compaction: when to resume a builder, and how agents should compactWhen a review sends findings back, the wave lead resumes the original builder..
Requirements: none. This note is about the agent harness, not the product.
Method
Section titled “Method”- Transcripts. The session transcripts of the six run sessions
under
~/.claude/projects/for this repository: 48 builders, 46 code reviewers, 23 security reviewers and 18 wave leads. This note’s own builder and its lead are left out. Short Python scripts read theusageof every API call, deduplicated by message ID, and the time stamps. A resume is a message from the lead that starts a new turn of a finished builder. - Round kinds. A
must-fixround follows aneeds changesreview, a fold round follows an approve. The lead’s message says which. Background-task notices, rebase items and the three continuations after a turn limit are counted apart. - Warm or cold. A call is cold when it reads less than half its
context from the cache. The cache write and read counts come from
the API’s
usagefields. - Cost. In input-equivalent tokens: one base input token of the model is 1. For Opus 5.5 a 5-minute cache write is 1.25, a 1-hour cache write 2, a cache read 0.05 and an output token 5. Fable 5.1 reads at 0.025 (Anthropic’s pricing page). Every agent in the runs ran on Opus 5.5 except the security reviewers, which ran on Fable 5.1. 1M input-equivalent tokens on Opus 5.5 is $4 at list price. The maintainer’s plan usage is assumed to scale the same way, which the note doesn’t check.
- Next check. The reviews and
re-checked:comments on each pull request, from GitHub. - Options. Claude Code’s documentation at
code.claude.com/docs, and the settings and version on the maintainer’s Mac. Each claim below names its page.
Results
Section titled “Results”Fix rounds
Section titled “Fix rounds”Idle is the minutes since the builder’s last API call, context is the builder’s context at its first call of the round, and calls, cost and minutes cover the round. PR360PR360 (merged): feat(swift): wb-dev-bundle and mise run vm:* tasks for test VM bundleswb-dev-bundle is a dev-only Swift executable in packages/wraithbox-swift, promoted from the X18-vsock-handoff host tool. was built in the I340I340 (closed): Run 2026-10-17 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-17). session the day after the run, in an attended wave.
| All 42 rounds | |
|---|---|
must-fix rounds, fold rounds |
15, 27 |
| Cold, warm | 29, 13 |
| Context at resume, median and largest | 195k, 550k |
| Rounds at 200k or more, under 100k | 20, 6 |
| Calls per round, median | 21.5 |
| Minutes per round, median | 9.5 |
| Cost, total and median | 27.7M, 508k |
| Share of all builder cost (81.0M) | 34% |
- The cache. Every round that came within 5 minutes of the builder’s last call was warm, and every round after 6 minutes or more was cold. A cold round pays its whole context as a cache write. The lead sends most findings after both reviews are back, so 29 of the 42 rounds were cold.
- Quality. All 15
must-fixrounds were approved at the next review, and every fold round got are-checked:comment without another round. Resumed builders at 300k to 550k did no worse than those under 150k. The data has no failed fix round to explain, so it doesn’t show that a large context harms a fix. - Fresh builders. No fix round went to a builder spawned for it.
The closest is PR326PR326 (merged): feat(swift): wb-vmd boots and stops its slot's VM, confinedwb-vmd boots and stops the VM in its slot's bundle, confined to that bundle, behind the device-set check of #160.: a builder spawned only to rebase it took the
round 2
must-fixfindings at 86k of context, and round 3 approved. Two fresh builders on an existing branch, one of them a fix for a failingneeds-vmtest, made their first edit after 23 and 26 calls, at 57k and 66k of context, for 117k and 127k of cost, in 2 to 4 minutes. - Turn limits. The builders of I161I161 (closed): wb-vmd: confined process that boots and stops the work VM's bundleThe remaining VM spikes (X06-guest-xcode, X08-data-disk, X20-shared-homebrew, X04-tls-inspection, #142, #154, #155, #158) each rebuild boot code on a throwaway branch., I164I164 (closed): wb-vmd: connect to a guest port and hand off the descriptor, end-to-end hello, wb-dev-vmAfter #161 and #163, a VM boots and wb-guestd listens, but the host can't reach it. and I289I289 (closed): wb-diskfmt: format a VM's new data disk on the host, data disk records, and `wb vm reset-data`A VM needs a data disk before it first boots. hit their 200-turn limit and were resumed at once, warm, at 433k to 513k. The continuations cost 6.3M together. Each then had a cold review round at 465k to 550k (PR326PR326 (merged): feat(swift): wb-vmd boots and stops its slot's VM, confinedwb-vmd boots and stops the VM in its slot's bundle, confined to that bundle, behind the device-set check of #160., PR373PR373 (merged): feat(vmd): ConnectGuest hands off the guest connection, with the host receiver and wb-dev-vmwb-vmd now serves ConnectGuest: it opens a vsock connection to a guest port below 1024 and sends the descriptor to the host in one HandoffMessage on fd 4. and PR352PR352 (merged): feat(hostd): wb-diskfmt formats a VM's new data disk, with records and wb vm reset-datawb-diskfmt formats a VM's new data disk on the host, the one exception SEC15-no-guest-disk-mount makes. above), which cost 5.7M together.
Resume or start fresh: a cost model
Section titled “Resume or start fresh: a cost model”Most of a fix round’s cost is the context the builder carries. A
resumed round pays its context C once as a cache write (cold) or a
read (warm), then reads it again on each further call. A fresh builder
pays an orientation of about 120k and then reads a context of about
60k on each call. The work itself costs the same either way. Under
that model, reading and writing the context the builders already had
cost 18.4M of the 27.7M the 42 rounds cost.
| Rule | 5-minute cache, today | 1-hour cache |
|---|---|---|
| Always resume | 18.4M | 10.5M |
| Resume under 100k, else fresh | 7.5M | 8.8M |
| Resume under 150k, else fresh | 7.5M | 7.8M |
| Resume under 200k, else fresh | 8.9M | 7.6M |
| Always fresh | 7.8M | 9.7M |
With a fresh builder that orients at 80k instead of 60k, resuming under
150k costs 8.1M on today’s cache. Of the limits in the table, 150k is
within 0.2M of the cheapest under both cache lifetimes. Both lifetimes
matter because Claude Code ignores the agent frontmatter’s 1h cache
while the subscription draws on usage credits. On the 5-minute cache,
150k costs 1.4M less than 200k, and on the 1-hour cache 200k saves
only 0.2M. A fresh builder adds
2 to 4 minutes to a round that takes 9.5 minutes at the median.
The lead can see the size: a builder’s completion notice has a
<subagent_tokens> field, which matched the builder’s last context within
3k on the PR385PR385 (merged): feat(hostd): wb vm start, stop and status over wraithbox.hostd.v1Adds StartVM, StopVM and GetVMStatus to HostService in the existing proto/wraithbox/hostd/v1/hostd.proto. builder (213,072 against 210,279).
Cold rewrites in every role
Section titled “Cold rewrites in every role”The cache also goes cold inside a builder’s own run. 118 builder calls rewrote 23.9M tokens of context. All but five of them, which rewrote 0.1M together, came after an idle gap of 5 to 25 minutes:
| Before the cold call | Rewrites | Tokens | Idle minutes, median |
|---|---|---|---|
A CI watch (ci-watch, gh run watch) |
41 | 9.7M | 8 |
| A resume by the lead | 31 | 6.8M | 12 |
| Another Bash command | 22 | 3.8M | 7 |
mise run ci |
9 | 1.5M | 9 |
| Edits, VM, Swift and docs tasks, other | 15 | 2.0M | 7 |
A one-hour cache turns each rewrite with a gap under 60 minutes into a read, and makes every other cache write cost 2 instead of 1.25:
| Role | Cost | Cold rewrites | Saved by 1 hour | Extra writes | Net |
|---|---|---|---|---|---|
| Builder | 81.0M | 118, 23.9M | 28.6M | 6.3M | -22.3M (-28%) |
| Code reviewer | 11.9M | 30, 2.7M | 3.2M | 2.7M | -0.5M (-4%) |
| Wave lead | 9.4M | 71, 4.0M | 4.5M | 1.4M | -3.1M (-33%) |
| Security reviewer | 5.3M | 22, 0.8M | 1.0M | 1.9M | +0.9M |
| General-purpose agents | 3.8M | 17, 0.4M | 0.5M | 1.4M | +0.9M |
Every builder rewrite had a gap under 60 minutes. The lead’s rewrites follow its waits for agents, up to 127 minutes.
Compaction in the runs
Section titled “Compaction in the runs”- No subagent compacted. None of the 491 subagent transcripts in
this repository’s project folders on 2026-10-22 has a
compact_boundaryrecord. The largest builder context was 587k. 20 of the 48 builders passed 200k, 9 passed 300k and 3 passed 400k. - The maintainer’s sessions compacted 14 times, all by a typed
/compact./compactwas typed 20 times, never with instructions. The compactions ran at 146k to 443k (median 260k), left 6.5k to 16k, and took 32 to 120 seconds. One was in a run, in I367I367 (closed): Run 2026-10-20 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-20). while the lead of wave 5 ran. Two were in the I340I340 (closed): Run 2026-10-17 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-17). session the day after that run, and the rest in attended sessions. - What happened next. In the four compactions checked (the I367I367 (closed): Run 2026-10-20 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-20).
and I340I340 (closed): Run 2026-10-17 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-17). sessions, and an attended session on I379I379 (closed): wb-guestd: update at start from the guest tools disk, and the guest side of the clock (the rest of M2.6)The implementation plan gives package M2.6 (#163) "tools-disk update, clock", and #288 is blocked by M2.6 for both: "wb-guestd updates itself from the tools disk at start (S06-12-guest-agent, "Update at start"), and…), the next ten
tool calls read state
back from GitHub, the run’s
.scratch/files or task output, and went on with the next step. None of them redid work. The other ten weren’t checked.
So the runs don’t show a builder, reviewer or lead losing something to compaction, because none of them compacted.
Claude Code’s options
Section titled “Claude Code’s options”On the maintainer’s Mac: Claude Code 2.1.302, "model": "opus" (Opus
5.5) and "autoCompactEnabled": false in ~/.claude/settings.json.
Main sessions write their cache with the one-hour lifetime and
subagents with five minutes: in the I384I384 (closed): Run 2026-10-22 (V1-M2-walking-skeleton, lane mac)/wave --waves 5 --lane mac --merge session the main conversation
wrote 235k tokens to the one-hour cache and none to the five-minute
one, and its subagents 6.0M to the five-minute cache and none to the
one-hour one.
| Option | What it does | Source |
|---|---|---|
| Context window | Opus 4.7 and later run with a 1M window by default. | model-config, “Extended context” |
| Default threshold | Models with a native 1M window compact at about 967K. | model-config, “Default auto-compact thresholds” |
autoCompactEnabled |
Turns automatic compaction off or on. The documentation doesn’t say whether it covers subagents. | settings-reference, index |
/autocompact, autoCompactWindow, --autocompact, CLAUDE_CODE_AUTO_COMPACT_WINDOW |
Set how full the window gets before compaction, 100K to 1M, per model, per launch or for every model. The variable takes precedence over the others. | model-config, “Set the auto-compact window” |
autoCompactWindow in agent frontmatter |
Compacts one subagent earlier, as a plain integer from 100000 to 1000000. Needs 2.1.296. The variable above overrides it. | sub-agents, “Set the auto-compact window for one subagent” |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
Applies to subagents as well. | sub-agents, “Auto-compaction” |
/compact <focus> and a # Compact instructions section in CLAUDE.md |
Tell the summary what to keep. | costs, “Manage context proactively” |
SessionStart hook matching compact |
Adds the hook’s output to the compacted context. | context-window, “What survives compaction” |
PreCompact hook, matcher manual or auto |
Can block a compaction with decision: "block". |
hooks, decision control table |
| What survives | The project CLAUDE.md is re-read from disk. Up to five recently changed files are read again, and the rest is a summary. |
context-window, “What survives compaction” |
| Compacting a subagent at a chosen point | None of the pages read documents a way. /compact is typed at the prompt, and the frontmatter has only autoCompactWindow. |
sub-agents, frontmatter reference |
| Cost of a compaction | The summary request reads the history, from the cache when warm, uncached after the cache lifetime. | prompt-caching, “Compacting the conversation” |
| Subagent cache lifetime | Five minutes by default, also on a subscription. A resumed subagent can read the cache its first run warmed. | prompt-caching, “Subagents and the cache” |
experimental: cacheTtl: 1h in agent frontmatter |
One-hour cache for that subagent. Needs 2.1.248, and is ignored while the subscription draws on usage credits. | sub-agents, frontmatter reference, and prompt-caching, “Choose the TTL yourself” |
subagentPromptCacheTtl, CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL |
The same for every subagent, workflow and helper request, compaction included. | settings-reference, subagentPromptCacheTtl |
A larger window changes when compaction runs, not what a resumed round costs: that cost scales with the context the builder carries, at any window size.
The settings weren’t tried on a sample fix round. A builder can’t spawn agents, and an agent file’s frontmatter applies to agents spawned after the change.
Limits
Section titled “Limits”- 42 rounds by 35 builders. The model’s orientation cost comes from two fresh builders, and its work cost is assumed equal for a fresh and a resumed builder. A fresh builder that re-reads more files, or that redoes a choice the review didn’t question, costs more than the model says.
- No fix round failed, so the data can’t tell whether a fresh builder fixes better or worse. The rule below rests on cost alone.
- The one-hour estimate replays the same calls with other prices. It assumes every call would have been the same.
- Costs are API list prices. The maintainer’s plan may count usage differently.
Recommendations
Section titled “Recommendations”- A one-hour cache for builders and wave leads. Set
experimental: cacheTtl: 1hin.claude/agents/builder.mdandwave-lead.md. It would have saved about 28% of builder cost and 33% of lead cost: their cold rewrites follow waits for CI, reviews and agents, all under 60 minutes for builders. Leave the reviewers and other agents at five minutes, where it saves little or costs more. The frontmatter is per agent, so.claude/settings.jsonstays as it is. After the change, a builder’s transcript should showephemeral_1h_input_tokensin itsusage. - Resume a builder under 150k, else start a fresh one. The lead
reads
<subagent_tokens>from the builder’s last notice. Under 150k it resumes the builder. At 150k or more it stops it and spawns a fresh builder on the same branch, with the pull request, the posted reviews and the same findings message as its brief, plus “read the pull request’s Choices made, and don’t revisit a choice the review didn’t question”. On the 42 rounds this rule costs 7.5M against 18.4M today, and 7.8M against 10.5M with the one-hour cache. - Keep resuming after a turn limit. A builder that stops at its turn limit has work in its context that isn’t in a commit or a pull request yet. Its three continuations were warm.
- No compaction setting. Replaced by “Follow-up: compaction for
builders” below, which turns compaction on with a 200k window for
builders. The reasoning this note first gave: no builder, reviewer or
lead compacted, and the largest builder stopped at 587k, below the
967K default. A lower
autoCompactWindowwould summarize builders in the middle of their work, with an effect the runs can’t measure, and the fix-round rule already caps the largest resumed contexts. WithautoCompactEnabledoff, if that setting covers subagents, a builder that reaches the 1M window stops with a context-limit error instead of compacting.
Follow-up: compaction for builders
Section titled “Follow-up: compaction for builders”Issue I392I392 (closed): Compaction: turn on auto-compaction for the project, a 200k window and compaction instructions for buildersBuilders never compact, and about half of a builder's context is its own thinking, which stays in context for the whole run., decided by the maintainer on 2026-10-22.
Why no builder compacted. ~/.claude/settings.json on the
maintainer’s Mac has "autoCompactEnabled": false. In Claude Code
2.1.302 that setting gates every window. While it’s false, Claude
Code ignores autoCompactWindow in settings and in agent frontmatter.
Where a builder’s context goes. A measurement on 2026-10-22 split the final context of the builders of I286I286 (closed): wb vm start, stop and status over a first wraithbox.hostd.v1 contractThe user can't start or stop a VM. and I374I374 (closed): Project resolution: a .git directory whose core.worktree names another project's treeThe security review of #372 (#292) found that a downloaded .git directory whose core.worktree names another project's working tree resolves to its own key, so SEC08-proj-isolation holds for the key and the identity. in run I384I384 (closed): Run 2026-10-22 (V1-M2-walking-skeleton, lane mac)/wave --waves 5 --lane mac --merge, and of six builders from the runs I314I314 (closed): Run 2026-10-16 (V1-M2-walking-skeleton, lane any)Size 4, 1 wave, lane any, milestone V1-M2-walking-skeleton (default: first open milestone in the version page's order with ready work for the lane). to I367I367 (closed): Run 2026-10-20 (V1-M2-walking-skeleton, lane mac)Approval: the maintainer typed /wave --waves 5 --lane mac --merge in this session (2026-10-20)., estimated as characters divided by 4.
| Range over the eight | |
|---|---|
| Final context | 103k to 586k |
Fixed start (system prompt, tools, AGENTS.md, agent file) |
17k to 18k |
| Tool output | 20% to 29% |
| The builder’s own commands and edit contents | 9% to 20% |
| The rest, mostly thinking (inferred: transcripts keep only thinking signatures) | 44% to 58% |
Compaction replaces the history, thinking included, with a summary.
mise and go test output is small, because builders already filter it
with tail and grep, so tuning commands saves under 1%.
The plan.
.claude/settings.jsonsets"autoCompactEnabled": trueand"autoCompactWindow": 500000. Main sessions, leads and reviewers compact at 500k. The decision in I392I392 (closed): Compaction: turn on auto-compaction for the project, a 200k window and compaction instructions for buildersBuilders never compact, and about half of a builder's context is its own thinking, which stays in context for the whole run. puts the leads and reviewers of these runs under about 60k when they end, a figure this note didn’t measure. If that holds, in practice the 500k window applies to main sessions..claude/agents/builder.mdsetsautoCompactWindow: 200000in its frontmatter. Claude Code 2.1.302 describes that key as one that only lowers the window the subagent would otherwise inherit.- The body of
builder.mdhas a## Compact Instructionssection, for builders only. The summary request tells the model to follow summarization instructions it finds in the context, with that heading as its example. It adds what the standard summary doesn’t already keep: the issue, branch, worktree and pull request, the issue’s decisions and the pull request’s “Choices made”, where each review finding stands, the “Done when” items still open, and not to revisit a choice a review approved.AGENTS.mddoesn’t get the section, because only builders are expected to compact, and a lead needs other things kept. - No
idleCompactionkey. In 2.1.302 that setting can only turn idle compaction off, andtrue“does not turn idle compaction on”, so atruethere would do nothing and mislead a reader. - The builder’s rule to stop after a compaction is gone. A builder carries on from the summary and reads back from the branch, the pull request and the issue what the summary doesn’t hold.
The PreCompact hook. Its input doesn’t name the subagent type in
2.1.302. The schema lists the common agent_id and agent_type fields,
but the PreCompact input is built without the subagent’s context, so
agent_id is absent and agent_type is set only in a main session
started with --agent. A hook can’t add builder-only instructions, so
the plan has none.
How to check it. Not yet confirmed: that the project setting
overrides the user’s false, and that the summary request of a
subagent includes its system prompt, which holds the section. The next
builder that passes 200k shows both. Its transcript has a
compact_boundary record, and its summary keeps the items of the
section. A main session that passes 500k compacts. Whoever runs the
next wave checks this and comments the result on I392I392 (closed): Compaction: turn on auto-compaction for the project, a 200k window and compaction instructions for buildersBuilders never compact, and about half of a builder's context is its own thinking, which stays in context for the whole run.. I392I392 (closed): Compaction: turn on auto-compaction for the project, a 200k window and compaction instructions for buildersBuilders never compact, and about half of a builder's context is its own thinking, which stays in context for the whole run. is closed only
after that comment.
Status: Measured 2026-10-22 over 42 fix rounds of V1-M2-walking-skeletonV1-M2-walking-skeleton: Walking skeletonwb-vmd boots a fixture VM bundle in its confined process, wb-guestd answers over vsock, a data disk made on the host holds the homes, and wb shell opens a PTY as a project user, with its output through the terminal fi…. PR389PR389 (merged): docs(research): R03-fix-rounds-compaction, when to resume a builder and how agents compactAdds docs/research/R03-fix-rounds-compaction.md, measured from the session transcripts of runs #307, #314, #323, #340, #367 and waves 1 and 2 of #384, and the GitHub reviews of each pull request. applies the recommendations in commit 28ab7e2, and merging it accepts them. Follow-up 2026-10-22: I392I392 (closed): Compaction: turn on auto-compaction for the project, a 200k window and compaction instructions for buildersBuilders never compact, and about half of a builder's context is its own thinking, which stays in context for the whole run. turns compaction on, with builders at 200k, and is closed after the check that follows the merge