12One agent

Compaction

When the context window fills, summarize the conversation and continue from the summary.

Anthropic, Cognition, OpenAI

nears the limitwritesstartsMessagehistoryModelSummaryNew contextwindow
How to read this

The problem

A long task needs more tokens than the context window holds.

Long-horizon tasks require agents to maintain coherence, context, and goal-directed behavior over sequences of actions where the token count exceeds the LLM’s context window.
AnthropicEffective context engineering for AI agentsSep 29, 2025

Therefore

Compaction is the practice of taking a conversation nearing the context window limit, summarizing its contents, and reinitiating a new context window with the summary.
AnthropicEffective context engineering for AI agentsSep 29, 2025
To support long-running interactions, you can use compaction to reduce context size while preserving state needed for subsequent turns.
OpenAICompaction

In use

Claude Code

In Claude Code, for example, we implement this by passing the message history to the model to summarize and compress the most critical details.
AnthropicEffective context engineering for AI agentsSep 29, 2025

Where it breaks

A summary can drop a detail that turns out to matter later.

The art of compaction lies in the selection of what to keep versus what to discard, as overly aggressive compaction can result in the loss of subtle but critical context whose importance only becomes apparent later.
AnthropicEffective context engineering for AI agentsSep 29, 2025
This is hard to get right. It takes investment into figuring out what ends up being the key information and creating a system that is good at this.
CognitionDon’t Build Multi-AgentsJun 12, 2025

Sources

  1. Effective context engineering for AI agentsPrithvi Rajasekaran, Ethan Dixon, Carly Ryan, and Jeremy Hadfield, Anthropic, Sep 29, 2025
  2. Don’t Build Multi-AgentsWalden Yan, Cognition, Jun 12, 2025
  3. CompactionOpenAI

Added Nov 14, 2026