Context Compaction
An agent’s transcript only grows. Every thought, every tool call and every result is appended, and a long run eventually reaches the edge of the context window. Context compaction is the move that buys more room: replace the older part of the conversation with a compressed account of it, and carry on from there.
What a compaction keeps
The operation is lossy on purpose, so the quality of an agent’s long runs depends on what the compactor treats as load-bearing:
- The goal as originally stated — the first thing to get paraphrased away and the worst thing to lose.
- Decisions already made and their reasons, so the agent does not reopen a settled question.
- Durable facts discovered by tools: a file path, a schema, an error that turned out to matter.
- Open threads — what was in progress at the moment of the cut.
Verbose tool output, superseded attempts and abandoned reasoning are what get dropped. Coding agents compact routinely; a long session in Claude Code survives by it.
Why it matters
Without compaction a run simply dies at the window limit, mid-task, with its work unfinished. With a careless one it keeps going but forgets why: a plan drifts because an early constraint fell out, or a step is repeated because the record of doing it is gone. Compaction is what separates a demo-length agent from one that can work for hours.
Context compaction is the replacement of an agent’s older conversation history with a compressed summary once the running transcript approaches the context window limit. It preserves the goal, settled decisions and durable findings while discarding verbose tool output and abandoned attempts, so a long run continues instead of failing at the limit. Compact badly and the agent keeps working but forgets the constraint that mattered.
Picture a notebook you are filling as you work, except you are only allowed one notebook. When it is nearly full, you tear out the early pages and write a short recap on the last clean one: what the job is, what I decided, what is still open. Then you keep going.
That is context compaction. Software working on a long task can only hold so much of its own history at once, so it periodically swaps the old detail for a summary.
It is the difference between an assistant that gives up halfway and one that works for hours — as long as the recap keeps the parts that mattered.