Compaction in 📝Claude Code is the harness's automatic summarization mechanism that compresses earlier conversation content when the session's token usage approaches the model's 📝context window limit, allowing the conversation to continue without manual restart.
When a Claude Code session grows long enough that the next turn would exceed the model's context window, the harness pauses and summarizes prior conversation history — older tool outputs, intermediate analysis, and lower-relevance turns — replacing them with a condensed summary block before continuing. The summary preserves what the agent has learned (decisions made, files read, approaches considered) while reclaiming token budget for new work.
Compaction is the difference between a session that runs to natural completion and one that hits a wall and forces a cold restart. For long-running work — debugging spanning hours, multi-file refactors, exploratory research — compaction extends usable session life by 2-5x depending on how much of the conversation was reclaimable tool outputs versus essential reasoning.
The trade-off is summarization fidelity: compacted history loses nuance that the full transcript preserved. Practitioners learn to anticipate compaction by writing critical context to durable memory — 📝CLAUDE.md as Infrastructure, 📝Memory (Claude Code), MythOS memos — rather than relying on conversation history alone. Where context preservation across deep tasks is load-bearing, 📝Claude Code Forked Sub-Agents offer an alternative that copies the full uncompacted parent context into a child agent.
