Context Compaction
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?
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]
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
- During long tasks with AI, ask it from time to time to summarize the decisions made so far.
- Check the summary and fill in any missing decisions or conditions yourself.
- Write rules that must always hold in a separate instruction file, not in the conversation.
- 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?
Which concepts are related to Context Compaction?
- Base conceptContext WindowThe limit on how much a model can handle at once
- Problem it addressesContext RotQuality dropping as input gets longer
- Parent conceptContext EngineeringThe broader practice of choosing only the information needed
- Representative toolClaude CodeA coding agent that uses automatic compaction
- Similar conceptMemoryStoring information outside the conversation and recalling it
Context Compaction vs Memory
Which sources explain Context Compaction?
- Anthropic — Effective context engineering for AI agents (2025-09-29) — https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- OpenAI — Compaction (accessed 2026) — https://developers.openai.com/api/docs/guides/compaction
- Anthropic — Compaction overview (accessed 2026) — https://platform.claude.com/docs/en/build-with-claude/compaction
Tell us what you think
Your feedback helps us improve the content.