D1 · Compaction
Family: Context and memory
When the context nears its limit, it is summarised and work restarts in a fresh window.
Principle
The history of a conversation close to the context limit is summarised, then a new window is started with that summary. The safest variant is to clear old tool results, which are bulky and rarely reread. The goal is to keep the smallest possible set of high-signal tokens.
The problem it solves
The longer the context grows, the lower the agent’s accuracy, until the window is full.
When to use it
- A long task, such as a coding agent, sees its history exceed the window or degrade accuracy.
- The history is mostly old, bulky tool results: clearing them is the safest form.
When to avoid it
- A summary might drop a detail the agent will need: first write the essentials to notes outside the context (D2).
- The task fits in the context window: there is nothing to compact.
Common pitfalls
The anti-patterns that misuse this pattern, best established first. Each sheet describes the symptoms, the public incidents and the remedies.
Context and memory
- AP28 · Raw or erased error history — Every failed attempt stays word for word in the history and invites more, or it disappears along with its lesson.
- AP26 · Context poisoning — A mistake written into the context becomes a fact, which the agent rereads and reinforces at every turn.
- AP29 · Destructive compaction — A summary that erases the original: the day a detail matters, there is no way left to get it back.
- AP30 · Cache-busting prefix — A timestamp or a reordered JSON at the top of the prompt, and every call pays full price for the whole context again.
Synonyms by vendor
- Compaction (Anthropic)
- Context editing (édition de contexte) (Anthropic (2025))
- Modèle de compression dédié (Cognition)
Neighbouring patterns
Sources
- Effective context engineering for AI agents — Anthropic, 2025-09-29
- Managing context on the Claude Developer Platform — Anthropic (Claude), 2025-09-29
Content reviewed on 2026-10-02