WTF is Compaction?
When a session nears the context limit, the agent replaces older turns with a summary so it can keep going.
Also called: context compaction, auto-compact
TL;DR
Long agent sessions would simply stop when the context window fills. Compaction squashes the earlier conversation into a short summary and continues. It is lossy by design: anything the summary left out is gone, which is why agents sometimes forget an instruction from an hour ago.
How it works
Typically triggered automatically at a threshold of the context window. The harness asks the model (or a cheaper one) to summarise the transcript so far, preserving goals, decisions, open tasks and key file paths, then restarts the conversation with that summary plus recent turns. Related techniques: clearing old tool results, writing durable notes to files or memory before compacting, and tool-result truncation. Security note: compaction can drop standing safety instructions, so system prompts are usually re-injected rather than summarised.
Origin
- Coined / introduced by
- Coding-agent harnesses
- When
- 2025
- Story
- Shipped quietly in coding agents during 2025 and was named as a general context-engineering technique by AI labs soon after.