Compaction is when an agent takes a long stretch of conversation and replaces it with a shorter summary. The point is to reclaim room in the context window. Rather than carry every message, every file dump, and every command output verbatim, the agent condenses the older part of the history into a few paragraphs of "here is what we did and decided" and drops the raw detail.
Why you need it
A window is finite, and a busy session fills it fast. Once you are near the limit you have two options: lose the oldest messages entirely, or compress them. Compaction is the compress option. Done well, it keeps the thread of what matters (the goal, the key decisions, the current state) while shedding the bulky, finished detail that is no longer pulling its weight.
The tradeoff
Compaction is lossy on purpose, and that is the risk:
- What survives is whatever the summariser judged important, in its words.
- What vanishes is the exact wording, the specific line numbers, the subtle constraint you mentioned once.
If the summary drops a detail you were relying on, the agent will act as if you never said it. That is the failure mode to watch for. When it happens on its own it is called autocompact, and sometimes the cleaner move is clearing the window entirely and starting from a crisp restatement of the task.
Related terms
Context window
The context window is the maximum amount of text, measured in tokens, that a model can consider for a single request. It is a hard ceiling, and it is the main resource you manage when working with an agent.
Read definition →Autocompact
Autocompact is the agent compacting the context automatically when the window nears full. Convenient, but it can silently drop detail you cared about.
Read definition →Clearing
Clearing is deliberately wiping the context to start fresh. It is often the cleanest fix for a bloated or confused window.
Read definition →