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

All anti-patterns

Synonyms by vendor

  • Compaction (Anthropic)
  • Context editing (édition de contexte) (Anthropic (2025))
  • Modèle de compression dédié (Cognition)

Neighbouring patterns

Sources

Content reviewed on 2026-10-02

Pattern catalogue