Compaction
ai-engineering context-window agent-design
Compaction
The process of summarizing older context to free tokens when the context window fills up.
↑ ContentsDefinition
As a session progresses, the context window accumulates tokens from conversation history, tool results, and file contents. When the window approaches its limit, the harness compacts: it clears older tool outputs first, then summarizes the conversation if needed. Instructions and key code snippets survive compaction. Detailed conversation history from earlier in the session may not. This is why persistent instructions belong in CLAUDE.md or AGENTS.md rather than in conversation messages.
↑ ContentsSource
- How Claude Code works — “It clears older tool outputs first, then summarizes the conversation if needed.”
- The Anatomy of an Agent Harness — describes context as a “precious and scarce resource” and compaction as active management against “context rot.”