Measuring Context Compaction in a Coding-Agent Fleet: When It Fires and What It Costs
Coding-agent harnesses summarize a conversation and start over when its prompt gets too long. In one day of gateway data we found 91 such resets for our most-used model, most of them between 240,000 and 250,000 prompt tokens, each leaving about 29,691 tokens behind. Here is how we detected them, how often they fired and what the summary calls cost.
A coding agent’s conversation grows with every step: each tool call and its output is appended, and the whole history goes out again with the next model call. Agent harnesses cap that growth with compaction. When the prompt nears a limit, the harness asks the model to summarize the work so far, then continues from the summary and a few recent messages in place of the full history.
Our gateway records, for every call, the conversation it belongs to, the number of messages in the request and the provider’s token counts. Compaction shows up in that metadata as a sudden collapse in message count that stays collapsed. We took the 24 hours from 31 October, 16:00 UTC, 33,021 calls, and looked at the two models that carry most agent work: an OpenAI model driven by a Codex-style harness (13,434 calls) and an Anthropic model driven by Claude Code (9,586 calls).
within one conversation and model, ordered by time:
previous call has >= 50 messages
this call has < 30% of the previous call's messages
the next 3 calls each have < 50% of the previous call's messagesWhere compaction fired
Show the data
| compactions | |
|---|---|
| <150k | 3 |
| 150–200k | 8 |
| 200–225k | 13 |
| 225–240k | 14 |
| 240–245k | 22 |
| 245–250k | 28 |
| 250k+ | 3 |
The most-used model’s conversations compacted 91 times in the window, in 25 of its 55 conversations; one conversation compacted 16 times. The last call before a reset had a median prompt of 241,083 tokens. 53 of the 91 resets came after a prompt of 240,000 tokens or more, and 80 after 200,000 or more. The largest prompt sent to the model by any call in the window was 252,835 tokens, and only 5 calls exceeded 250,000.
After a reset, the next call carried a median of 29,691 tokens in 10 messages, down from 378 messages before. In conversations that compacted more than once, the median stretch between resets was 113 model calls and 91 minutes (10th percentile 29 minutes, 90th 411, over 66 intervals).
The prompt-size distribution has a ceiling
Show the data
| calls | |
|---|---|
| <25k | 197 |
| 25–50k | 844 |
| 50–75k | 1.3k |
| 75–100k | 1.6k |
| 100–125k | 1.5k |
| 125–150k | 1.8k |
| 150–175k | 1.9k |
| 175–200k | 1.8k |
| 200–225k | 1.6k |
| 225–250k | 945 |
| 250k+ | 5 |
Calls spread almost evenly between 50,000 and 225,000 prompt tokens, thin out in the last band and stop at 250,000. The median call carried 144,117 tokens.
Our inference, from the shape rather than a per-conversation fit: a long conversation climbs from about 30,000 tokens to about 245,000 and resets, over and over. If it climbs at a steady rate, its calls spread evenly across that range, with a midpoint near 137,000 tokens, close to the median we measured. The low bands hold more than that pattern predicts because short conversations that never compact also live there.
What the summary calls cost
The call just before each reset looks different from its neighbors. Its prompt is about the same size as the call before it, while its output is much longer: a median of 2,677 output tokens against 494 for the call before. 73 of the 91 wrote at least 1,000 tokens. We take that call to be the summary request, inferred from its shape; the metadata does not label it.
- Waiting time. Summary calls took a median of 54.8 seconds, against 4.2 seconds for the first call after the reset. Together they took 1.5 of the model’s 43 call-hours in the window, 3.5%.
- Output tokens. They wrote 254,892 of the model’s 4.93 million output tokens, 5.2%.
- Prompt tokens. Each summary call sends the full history one more time, about 240,000 tokens. After the reset, calls start again from about 30,000 tokens and grow back toward the threshold.
The Claude Code conversations
The same rule found 68 resets in 20 of 62 Claude Code conversations. In 52 of them the call before the reset wrote at least 1,000 tokens: a median of 6,755 output tokens in 56.7 seconds, from a median of 274 messages down to 1. The other 16 resets had no long call before them; we did not check whether they were cleared sessions or another kind of restart.
We could not measure where Claude Code compacts. Anthropic’s API reports prompt tokens without the cached part, which our metadata stores in the same column as OpenAI’s full prompt count, so the stored prompt sizes for this model are near zero. The message counts still show the resets. Claude Code lets the operator set the compaction window, so its trigger point depends on configuration.
What we would do with this
Our inference from this data, rather than measured results:
- Treat the compaction threshold as the effective context size of an agent. The model may accept a larger prompt, but in this window almost no call exceeded 250,000 tokens, and the median call carried about 144,000.
- Expect a one-minute pause at each compaction. Agents that run long tasks hit one about every hour and a half here; interactive users notice it, and timeouts on a whole agent turn should allow for it.
- Put what must survive a reset somewhere the harness re-reads, such as instruction files, tickets or plan notes, instead of relying on the summary. Ten messages and a few thousand tokens of summary replace several hundred messages of history.
- Store a compaction marker, and cached-token counts per provider, at the gateway. Both would replace the shape-based detection used here with a direct measurement.
Limits of this account: one day from one development fleet. Compactions are inferred from message-count drops, and summary calls from output length; neither is labeled in the data. Conversations that started before the window or were still running after it are partly observed, which shortens the measured stretches between resets. Prompt sizes come from one provider’s token counts and include cached tokens. We did not inspect message content, so we have not evaluated what the summaries kept or lost.