Skip to content
← Back to Glossary

Compaction

ai-engineering context-window agent-design
This content is not yet available in Português. View original →

Compaction

The process of summarizing older context to free tokens when the context window fills up.

↑ Contents

Definition

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.

↑ Contents

Source

  • 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.”
↑ Contents