Running AI coding agents for days: rotating sessions cut cost per step by about half
One of my projects, a driving-theory course with video lessons, was produced mostly by AI coding agents running for days on the DGX. Not one long conversation: a manager session and several worker lanes, for example one for pictures and shipping, others for videos in the other languages. This post is about the single change that made that sustainable: rotating sessions, and what the session logs say about it.
The problem with a session that never ends
A coding agent keeps its whole conversation in context. The longer it works, the more it carries into every single step. Each tool call re-reads that history. So cost per step rises with context size, and quality tends to drift as old, half-relevant material piles up.
In a multi-day production run, the sessions just kept growing. From the logs, before I changed anything:
- average context was 380 to 500k tokens
- peaks reached 611 to 718k tokens
- relative cost per step was 46 to 63
"Relative cost per step" is my own unit, taken from the logs, so read it as a ratio and not as money.
The change: hand over before the context grows
The rule is simple. Each session hands over to a fresh one before its context becomes large. The fresh session starts small, with the state it needs and nothing else.
The handover has two parts.
A state file. The outgoing session writes down what is done, what is running, what is blocked and why, which files matter, and which decisions were taken. It is written for a reader who has none of the conversation.
A read-back. This is the part that matters most. The new session does not just accept the file. It restates the state in its own words. The old session, which is still alive, reads that restatement and corrects it. Only after the corrections does the new session take over.
What it measured
After rotation, from the same kind of logs:
- average context 175 to 215k tokens, peaks 250 to 350k
- cost per step 21 to 26 for workers
- cost per step 31 to 34 for the manager
Compared with the old 46 to 63, that is about 45 to 60 percent cheaper per step.
That figure is before counting the handover itself. Writing the state file and doing the read-back costs something too. I estimate it at 10 to 15 percent. So the real saving is smaller than the headline, but still large, and the sessions stay sharper because they are not hauling a mountain of stale history.
The managers are sessions too
The manager role is not special. It is a session with the same growth problem, so it rotates as well, with a slightly higher cost per step because it carries the overview of all lanes.
What it cost, honestly
Rotation is not free in ways beyond tokens.
One manager killed itself. It ran a kill by pattern, and the pattern also matched its own process. Handing over the role cleanly would have avoided a session that had to be recovered afterwards.
One read-back found 12 disagreements. The new session restated the state and the old one marked twelve places where the picture was wrong. Some were small. Some were things like which pictures were approved and which were not, the kind of mistake that would have shipped quietly if the new session had trusted the file.
I count both as the system working. The read-back exists precisely to catch what a state file cannot: the writer's own assumptions.
Lessons
- **Rotate by size, not by time.*Hand over before the context grows, not after it is already expensive.
- **A state file is not enough.*The read-back catches what the writer forgot they assumed.
- **Keep the old session alive until the correction is done.*It is the only one who knows what is missing.
- **Write the state for a stranger.*If it depends on the conversation, the new session cannot use it.
- **Measure from the logs.*Context size per step and cost per step are in the session logs; I did not have to guess.
- **Count the handover cost.*The estimate is 10 to 15 percent, and the saving is still real.
- **Give the manager the same rule.*It is a session too.
- **Be careful with kills by pattern.*One manager ended itself that way.
Where this stops working
Rotation helps when the work can be described in a file. Some work cannot: a half-formed intuition about why a render looks wrong is hard to write down. For that I keep the session going a little longer and accept the cost. The aim is not the smallest context at all costs, it is the smallest context that still contains what the next step needs.
The reason I trust the numbers is simple: both sets come from the same logs, measured the same way, on the same kind of work. The change itself cost me almost nothing to try, one file and a discipline. If you run agents for more than a day, try it before you optimise anything else.