Compaction is the process Claude Code uses to keep a long-running session going as the conversation approaches the limits of the model's context window. Instead of failing or silently dropping messages, Claude condenses earlier parts of the transcript — prior turns, tool calls, and file reads — into a compact summary, then continues with that summary plus the most recent activity in context.
You can trigger this manually with the /compact command, optionally adding instructions to steer what the summary keeps (for example, focusing on a specific area of the code). Claude Code can also auto-compact automatically when the context window nears its limit. There is additionally a more granular microcompaction behavior that clears older tool calls and their results incrementally, rather than summarizing the whole conversation at once. Because a summary is lossy, some fine-grained detail can be lost, so anything you want guaranteed to persist is better captured in CLAUDE.md or another file.
Compaction works alongside Claude Code's other context tools: persistent project instructions live in CLAUDE.md and memory, while compaction manages the live, in-session transcript. For the exact current behavior, triggers, and any settings that control it, check the official Claude Code documentation, since these details evolve across releases — you can track changes on the changelog.
Why it matters
Compaction is what lets you stay in a single Claude Code session through a long, multi-step task instead of starting over when the context fills up; knowing that it summarizes (and can therefore lose detail) helps you decide what to write into CLAUDE.md or a file so the important context survives, and when to run /compact yourself at a clean breakpoint.
Related terms
See Context Compaction in action across releases — browse the Claude Code changelog.
Get release alerts