Context compaction is the mechanism that automatically summarizes an agent's older conversation history into a compact block once the context crosses a token threshold, so a long-running agent can continue past what a single window could otherwise hold by carrying a distilled record forward instead of the full transcript.
How it works
As an agentic session runs, every turn adds to the context until it approaches the window limit. Compaction watches the input size and, once it crosses a set threshold, summarizes the older portion of the conversation into a compact block that becomes the new continuity point; on the requests that follow, the raw history before that block is dropped and the agent continues from the summary. By default the summary is what carries forward, so preserving specific recent messages verbatim is a deliberate step the caller takes rather than something that happens for free. The threshold and what the summary captures are the levers: a higher threshold compacts less often but leaves less headroom, and a summary keeps the thread of the work while necessarily discarding detail that did not make the cut. As a platform feature it runs on its own rather than being stitched together by hand, so the agent crosses the boundary without the caller assembling a fresh session.
Why it matters
Without compaction, a long agentic task ends when the window fills, which for real multi-step work is a hard ceiling reached well before the task is done. Compaction turns that ceiling into a soft boundary the agent crosses on its own, which is what lets an agent run across what would otherwise be many separate sessions as one continuous thread. The cost is fidelity, since compaction is lossy by construction, so a summary that drops a constraint, an earlier decision, or a piece of state the task later depends on degrades the run quietly, and nothing surfaces the loss unless the work checks for it. It also competes with the alternatives for the same job: durable memory written outside the window preserves what a summary would paraphrase, and clearing re-fetchable tool results reclaims room without touching the reasoning, so compaction is the right move when the value is in the thread of the conversation rather than in a single fact that has to survive word for word. Automatic compaction is convenient precisely because it is automatic, which is also its risk, since a boundary the system crosses without asking is one a builder can forget is there until a summary drops something it should have kept.
In practice
A coding agent works through a long change that spans far more steps than a single context window holds. Early on it established a constraint: one module must not import another. Many turns later the context has filled, so compaction summarizes the older history into a block and the agent continues from it. If the summary preserved that constraint, the agent keeps honoring it; if the summary paraphrased it away, the agent can violate it without ever seeing the original instruction again. Compaction carried the work past that point either way, and whether the run stayed correct came down to what it kept.
Practical considerations
Compaction is one of several ways to manage a filling window and is not always the right one: a fact that must survive verbatim belongs in durable memory rather than in a summary that may paraphrase it, and a window full of stale tool results is often better cleared than compacted. The threshold is a tuning knob, since compacting too eagerly discards context the task could still use and compacting too late leaves no room to recover. What survives a compaction is the high-leverage question, so a workflow that depends on an early decision should make that decision durable rather than trusting it to ride through every later summary. Because automatic compaction crosses the boundary without a prompt, a builder running long sessions should know that a configurable threshold governs when it fires, and treat a quiet quality drop late in a long run as a candidate symptom of a lossy compaction. The mechanism is a platform feature with its own controls, distinct from the broader practice of deciding what an agent should hold, which the context engineering discipline treats as a whole.
Related standards and prior art
- Anthropic: compaction · continuously updated automatically summarizes older conversation history into a compaction block when input tokens cross a threshold, so a session can continue past the context limit
- Anthropic: context engineering tools (cookbook) · continuously updated names compaction as distilling a full window into a high-fidelity summary so the agent can continue past its limit
Defined by Ready Solutions AI