Prompts & AI use

Context Compaction

AI-assisted editorial review:

A technique for running AI agents that summarizes a conversation as it approaches the context window limit, then uses the summary to continue work in a fresh context.

What does Context Compaction mean in simple terms?

AI has a limit on how much of a conversation it can hold at once. During long tasks you approach this limit, and if nothing is done, earlier content gets cut off or answer quality drops. Context compaction is a way to summarize the key points so far, such as decisions made and remaining problems, and continue the work in a new context. Coding agents like Claude Code run this process automatically, and users can also run it themselves with a command. Because details can be lost in the summary, it is a good idea to record important decisions separately in a document.

How can Context Compaction be explained with an analogy?

It is like a long meeting where you write the decisions so far on the whiteboard, clear away the old notes and continue while looking at the summary.

Where is Context Compaction used?

Case 1

Anthropic — Automatic compaction in Claude Code

In its context engineering guide published on September 29, 2025, Anthropic defined compaction as summarizing a conversation nearing the limit and starting a new context window.[1] Claude Code keeps architectural decisions, unresolved bugs and implementation details, discards redundant tool outputs, and then continues with the summary plus the five most recently accessed files.[1]
Result: Set out a design principle for keeping key context while continuing long coding tasks (per Anthropic's guide).[1]

Case 2

OpenAI and Anthropic — Offered as API features

OpenAI documents compaction as an API feature that shrinks context size while keeping the state needed for the next turn.[2] Anthropic also offers compaction as a beta feature that replaces older conversation content with a summary Claude writes on the server.[3]
Result: Gives developers an option for managing long conversations without building their own summarization logic (per each company's official documentation).[2][3]

Learning steps, limitations and developments

  1. During long tasks with AI, ask it from time to time to summarize the decisions made so far.
  2. Check the summary and fill in any missing decisions or conditions yourself.
  3. Write rules that must always hold in a separate instruction file, not in the conversation.
  4. If answers after compaction contradict earlier decisions, remind the AI of them.

Because compaction is a summary, the result depends on what is kept and what is discarded. Anthropic's guide also points out that compressing too aggressively can lose details that become important later.[1] It is one way to reduce context rot, where quality drops as context gets longer, but it is usually combined with external notes or retrieval that brings in only the information needed.

How has Context Compaction evolved?

2023—
Larger context windows
Models can read more at once, but limits still exist.
2025.09
Context Compaction
Summarizing a conversation and continuing in a new context is set out as an agent design principle.
2026
Offered as an API feature
Major providers offer compaction as an API feature.

Which concepts are related to Context Compaction?

  • Base concept
    Context WindowThe limit on how much a model can handle at once
  • Problem it addresses
    Context RotQuality dropping as input gets longer
  • Parent concept
    Context EngineeringThe broader practice of choosing only the information needed
  • Representative tool
    Claude CodeA coding agent that uses automatic compaction
  • Similar concept
    MemoryStoring information outside the conversation and recalling it

Context Compaction vs Memory

ComparisonContext compactionMemory
PurposeContinue the current conversationKeep information across conversations
MethodReplaces past content with a summaryStores information separately and recalls it when needed
When it runsWhen nearing the limitWhen there is information worth saving
Watch out forDetails may be lost in the summaryOutdated information lingers and causes confusion

Which sources explain Context Compaction?

  1. Anthropic — Effective context engineering for AI agents (2025-09-29) — https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
  2. OpenAI — Compaction (accessed 2026) — https://developers.openai.com/api/docs/guides/compaction
  3. Anthropic — Compaction overview (accessed 2026) — https://platform.claude.com/docs/en/build-with-claude/compaction