You leave an agent on a long refactor and go make coffee. When you come back there is a line in the log you did not write: context compacted. The agent is still working, apparently fine. Ten minutes later it opens a file it already opened, runs a suite it already ran, and asks you again something you answered an hour ago. Nothing crashed. The account it wrote of its own history is accurate, and short, and you can read it in twenty seconds. The trouble is not what that account says. The trouble is everything it stopped saying.

Compaction is a ruling, not a summary

Picture a judge deciding what a jury is allowed to hear. The court record keeps everything — every exhibit, every objection, every witness who was heard at length and turned out not to matter. The ruling does not erase any of it. It only fixes what the twelve people who have to decide will have in front of them when they decide. That is compaction. The word makes it sound like tidying. It is a ruling about what the model will no longer be able to look at.

Harnesses make that ruling in several ways, and they mix them. One asks a model to rewrite old turns as a shorter block. One masks or drops observations that have gone stale, like the output of a tool call from forty steps ago, without rewriting anything. One reduces the whole trajectory to its decisive moves. One pins the opening tokens in place and slides a window over the recent turns. The interesting result is that the clever option does not win: the paper called The Complexity Trap found simple observation masking as efficient as full model summarization for managing an agent’s context. The value was never in the prose. It was in the selection.

Which is why timing matters more than style. Compact late, when the window is already full, and you are not compressing anymore — you are losing whatever did not fit. The work on proactive context management makes the same point from the other side: rule early, on purpose, while there is still room to choose.

What left the room stays one question away

A ruling you cannot appeal is a bad way to run a long job. So the second half of the design is a way back to the material — not inside the context, outside it. On-demand retrieval indexes the raw stuff where it lands, chunked by heading into a searchable store, and lets the model ask it questions. The numbers are the argument. Pulling one documentation page in costs 5.9 KB of window; indexing it once and querying for the cleanup pattern costs 261 bytes, a 96 percent saving, and returns the passage rather than a truncation. Multi-term queries get reranked by proximity, so asking about session continuity surfaces the paragraph where those words sit together, not the page where they happen to both appear.

This is where the decision gets real. An agent you can leave alone all afternoon is an agent that can re-ask. Without that, every compaction is one-way, taken by a summarizer at a moment you were not present for, and the failure shows up much later as work redone. With it, the same compaction is cheap. Watch the freshness, though: these indexes carry a time to live — a day by default, longer for stable specs, shorter for a changelog you want re-checked — and an index left too long serves old content with a straight face.

The best material never enters the room

The strongest move is upstream: keep the raw data out from the start. Sandboxing tool output runs the call in a separate process and lets only its printed result into the conversation. Counting functions across fifty files is 700 KB of reading, or 3.6 KB if a script does the counting and prints the number. A browser snapshot goes from 56.2 KB to 299 bytes. Across a session, 315 KB of raw output becomes 5.4 KB. Note what this is not: the subprocess still inherits the host filesystem, so it buys you window, not safety.

The same instinct applies to your own instructions. One swollen CLAUDE.md gets read once and ignored; specs split by scope and injected per task mean an agent adding a payment endpoint loads the API standard and that task’s brief, and never sees the frontend conventions. It is the agent loop staying legible deep into a long job instead of only at the start.

Compaction is not the model forgetting. It is someone deciding what it will never see again — so make the decision on purpose, and leave the rest one question away.