writingmaclulich.com

How much does your coding agent’s compaction cost, and would a fresh start be cheaper?

The argument in 32 seconds. Compaction is measured on one head agent, and the fresh start is a projection.

Five steps to test a fresh start against compaction on your own agent

  1. Measure what your agent restarts with after a compactionMine restarts at about 145k tokens of a 300k window, and only 5k of that is the summary.
  2. Count the restart on every call, not just the handover69% of what my head agent sent over four days was the restart it had started from.
  3. Replay your own calls before you change a settingFour days of my calls, replayed: a fresh start at 200k projects to $405, against $529 for compaction at 300k.
  4. Keep the agent’s state outside the conversationMine was already in an inbox, git and a plan. The handover added four pieces on top.
  5. List how it could fail, and set the bar, before you switchFive ways mine could fail, each with how I’ll see it, and a bar set first: restarts under about 90,000 tokens, cost per call down at least 15%.
From one of my head agents in Claude Code, to 28 October: compaction is measured, and every fresh-start cost is projected from replaying its calls.

Check what your agent restarts with after compaction

If you run a coding agent for days at a time and let it compact its own context, this is for you. The story starts when Alexander Yue argued recently that a fresh session, with the old conversation saved to a file it can search, beats compaction.

To check it, I started with my own agent. I run several coding agents on each project, and the head agent plans the work, hands it to the others through a mailbox, and merges what comes back.

It’s one Claude Code session that runs for days. At my cap of 300,000 tokens, Claude Code compacts it: the model summarises the conversation, the session clears, and it carries on from the summary.

One agent, 30 days: 151 compactions, each restarting at half the window

151
compactions in 30 days, 36 on the busiest day
145k
tokens at restart, out of a 300k window
5k
of those tokens were the summary
70 min
spent waiting while 50 summaries were written
My head agent on one project, Claude Opus 5.5 in Claude Code, over the 30 days to 28 October. Restart sizes are medians, measured from its session transcripts.

The restart was the surprise. I measured the first call after each of 149 compactions and split it by where each part came from.

The summary is 5k of a restart of about 145k

System prompt and tool definitions35k
Instructions, skill list and tool list, attached again45k
The last 91 messages, kept word for word34k
Skills the session had loaded, attached again24k
Files it had read4k
The summary5k
Medians over 149 compactions of one head agent. Attachment sizes are estimated at four characters per token, so the rows don’t add up exactly to the 144k median the API reported.

A fresh session starts at about 70,000 tokens: the system prompt, tools, instructions and skill list. Compaction brings back about 75,000 more, mostly recent messages and the skills it had loaded.

Do the same split on yours. What matters is how much of the restart sits above what a fresh session would load anyway, which for me was about 75,000 tokens.

Count what the restart costs on every call

Each call to the model sends the whole context again. Most of it comes from the prompt cache at a tenth of the price, but it’s still billed.

So after a compaction, every call starts from 145,000 tokens and grows. On a busy day the head climbs to the limit and compacts up to 36 times.

69% of what the head sent was the restart it had started from

7,203
calls in four days
213k
tokens of context per call, on average
145k
of that was the restart
$529
for the four days
My head agent, 25–28 October, after I lowered its cap from 500,000 to 300,000 tokens. Dollars at Anthropic’s API list prices, including cache reads and writes.

Waiting costs time too. A third of my summaries were written on the spot rather than ahead, each holding the agent up for a median of 86 seconds.

Yue measured the handover itself, on a session of about 400,000 tokens. Searching a saved log took 15 seconds and $0.10, against 29 seconds and $0.17 for compaction with a warm cache.

His numbers are about the moment of the handover. Mine are about every call after it, which turned out to be the bigger cost, so I now price every call rather than the handover alone.

Replay your own calls before changing settings

To compare settings without waiting weeks, I replayed those four days, keeping every real call and what it added to the context, and changing only the restart size and limit.

Replaying the same four days, a fresh start at 200k costs about a quarter less than compaction at 300k

Compaction at 500k$64535 resets
Compaction at 300k, what ran$52992 resets
Fresh start at 300k$46250 resets
Fresh start at 250k$43465 resets
Fresh start at 200k$40591 resets
Fresh start at 150k$394154 resets
7,203 calls from one head agent, 25–28 October, priced at API list rates. A fresh start is modelled at 75k tokens. Projected, not measured.

A bigger window was the most expensive setting. With more room, the head spends longer at high context before each reset, and every one of those calls is large.

I picked 200,000 because it resets about as often as compaction does now. Each fresh session gets the same room to work in, and starts with half the load.

At the same reset rate, a fresh start carries half the restart

Compaction at 300kFresh start at 200k
Restart145k75k
Average call213k138k
Resets9291
Cost$529$405
One head agent over four days. Compaction is what ran. The fresh start is replayed from the same calls and is a projection.

A second project’s head agent agrees. Replaying its October, a fresh start at 200,000 costs 25% less than compaction at 300,000. Replay your own calls the same way before you change a setting.

Keep the agent’s state outside the conversation

Rigby, the small supervisor I wrote to run my agents, already covered most of what a fresh start needs. The head keeps its state outside the conversation: in its inbox, in git and in the plan it works from.

I wrote about that in how to make git the system of record for your AI coding agents. A fresh session could already find out what every agent was doing without the old conversation.

Most of the handover was already there. I added four pieces

Already in RigbyAdded for the handover
The head’s state on disk: inbox, git, planA trigger at 200,000 tokens
A hook that runs at every turn endThe saved log, with a note on where the head was
A way to type into the agent’s terminalA check that the head is idle and its own work has finished
Auto-compaction, kept as the backstopA daily record of what its context costs

Before you start fresh, check that a new session could find out what every agent is doing without the old conversation. Mine could, so the handover only needed four more pieces, and it only ever runs between turns.

List the failures and set the bar first

The replay prices the calls. It can’t tell me whether a fresh session does the job as well as a compacted one, and that’s where this could fail.

Five ways a fresh start could fail, and how I’ll see each one

What could go wrongHow I’ll see it
It forgets what it was doing, and I have to repeat myselfI check each handover’s first moves, and note every repeat
It cuts off work that was still runningResults that arrive with no one waiting for them
It sends work to an agent that already has itDuplicate dispatches after each handover
It keeps digging through the old log, or redoes work it forgotSearches of the log per session, in the daily record
It costs less per call but gets less doneCost per merged unit of work, two weeks either side

Forgetting was my first worry. So the note carries my last messages and its own last replies, and it reads them before it touches anything.

Cutting work off is the second. The handover never happens mid-turn: if anything new arrived after the turn ended, Rigby skips and tries at the next one. I checked that rule against 7,620 real turn ends.

It also waits while the head has its own agents, shells or test runs going. A fresh session would get their results without knowing why it asked for them.

Rigby now writes one line per agent per day, read from the session transcripts, so the comparison won’t rest on my impression.

Every day, one line per agent records what its context cost

  1. Costcalls, tokens, and dollars at list prices
  2. Restartscompactions and handovers, and the size of the first call after each
  3. Waitinghow long each summary written on the spot held the agent up
  4. Lookupshow often a fresh session searched its saved log

The second project stays on compaction until the first clears a bar I set before switching it on.

What the first project has to show before the second one switches

  1. Smaller restartsunder about 90,000 tokens, and cost per call down at least 15%
  2. No less doneas much work merged, and as much passing review first time
  3. Nothing lostno lost work, no duplicate dispatches, no repeated instructions
  4. Few lookupsit finds what it needs without reading the old log whole

And if it all goes wrong, compaction is still on at 300,000 tokens as the backstop, and one setting turns the handover off.

How far to trust it

The compaction numbers are measured on one agent. The fresh start is a projection from replayed calls, and whether it does the work as well is the open question.

Update, 12 November 2026: in its first 40 fresh starts, 1 to 4 November, the head restarted at 78,000 tokens, under my 90,000 bar.

Calls cost about the same, so it missed the 15% cut per call I asked for. It needed fewer of them instead: 30.5 per task, down from 39.5. The numbers are in the rework article.

What’s measured, what’s projected, and what I don’t know yet

  1. MeasuredCompaction on one head agent: restart sizes from 149 compactions, and costs from 7,203 calls over four days. Attachment sizes are estimated at four characters per token.
  2. ProjectedEvery fresh-start cost, replayed from those same calls at list prices with a restart of 75k tokens. A second project’s October replay costs 25% less.
  3. Not known yetWhether a fresh session does the job as well. It has run on one project’s head agent since 29 October, and its first handover was skipped, correctly, because the head had already started another turn.

Try a fresh start on one agent first

To try this on one agent, save its old conversation to a file with a note on top, and start the new session with a message that points at it. Mine are below, shortened.

The saved log opens with a note on where the head was: my last messages, its last three replies and the skills it had loaded. Then comes the old conversation, one line per message, so a search lands on the right moment.

The saved log, note first (illustrative, shortened)

## Where you were
Skills this session loaded: cross-rig-loop, rigby-fix
The operator's last messages, oldest first:
  #412 10-27 04:31:07 operator: Ship the export fix once both reviews pass.
Your last replies, oldest first:
  #413 10-27 04:31:15 you: Both reviews passed. Merging the export fix.
## The conversation, oldest first
[#412 10-27 04:31:07 operator] Ship the export fix once both reviews pass.
[#413 10-27 04:31:15 assistant] Both reviews passed. Merging the export fix.
[#414 10-27 04:31:16 tool Bash] git merge --no-ff export-fix
[#415 10-27 04:31:19 result] Merge made by the 'ort' strategy.
[#521 10-27 05:02:44 mailbox] The parser agent finished its unit and asks for review.

The new session’s first message tells it to read that note, check its inbox and git, and search the log only when it needs something.

The fresh session’s first message (simplified)

RIGBY HANDOVER: session 3f2a ended at 214,880 tokens.
You are the head, in a fresh session replacing a compaction.
First read where you were: the note at the top of history/3f2a.txt.
Then check your inbox, your agents, git status, git log
and the plan you were on.
The rest of that file is the old conversation, one entry per line.
Search it with rg when you need something from before.
Never read it whole.
Carry on from there. If that work is finished, wait for mail.

Change the names and the checks to match your setup, and leave one agent on compaction until this one clears your bar.

How the handover works

The handover happens between turns, never during one

  1. Turn endswith more than 200,000 tokens of context
  2. Save the loga note on where it was, then one line per message
  3. Check it’s idlenothing new arrived, and none of its own work is still running
  4. Start freshthe first message says where the log is and how to search it

So, will it work? On paper, yes. I’ll compare the two weeks either side of the switch and update this post with what happened.