OmniscioGuidesClaude Code glossaryCompaction
Compaction in Claude Code: what it is and what survives
Compaction is Claude Code's answer to a full context window: instead of ending the session, it replaces the conversation so far with a summary and carries on.
What compaction is
The context window is the working memory for a session. It holds the conversation history, the file contents Claude has read, command output, your CLAUDE.md, auto memory, loaded skills and the system instructions. All of it shares one limit, so a long session fills it eventually.
Claude Code compacts automatically as you approach that limit, so a full context window does not end your session. Both the automatic pass and /compact summarize the conversation; only /compact lets you steer what the summary keeps.
The reason a summary is needed at all: the model has no memory between requests, so Claude Code re-sends the context on every turn, and a conversation that keeps growing would eventually stop fitting.
What survives compaction, and what does not
Anthropic documents each mechanism, and the list is short enough to plan around.
| Mechanism | After compaction |
|---|---|
| System prompt and output style | Both still apply |
| Project-root CLAUDE.md and unscoped rules | Re-injected from disk |
| Auto memory | Re-injected from disk |
| Skill descriptions | Rebuilt from your current skills and re-injected, on Claude Code v2.1.304 or later |
| The plan Claude wrote in plan mode | Re-injected from disk |
| Git status snapshot | A fresh one is read from your repository |
Rules with paths: frontmatter, and nested CLAUDE.md files | Reloaded on demand |
| Files Claude read or edited | Up to five are re-read, most recently modified first |
| Invoked skill bodies | Re-injected, capped at 5,000 tokens per skill and 25,000 in total |
| Background commands and subagents | Keep running; Claude is reminded which ones are still going |
| Context that hooks added earlier | Summarized with the rest of the conversation |
| SessionStart hooks matching the compact source | Run again, and their output is added to the compacted context |
| Instructions given only in the conversation | May not survive |
Two details are easy to miss. A file over 5,000 tokens comes back as a path reference rather than its contents, and a path-scoped rule is summarized away with the rest of the conversation, then reloaded only when Claude next reads, writes or edits the file its paths: frontmatter matches.
So a rule worth keeping for the rest of the session belongs in the project-root CLAUDE.md, or in a rule file with no paths: frontmatter.
How to compact on purpose
Waiting for the automatic pass is fine, but running it yourself at a break in the work keeps the summary under your control, because you choose the focus.
/compact focus on the auth bug fixRun with no argument, /compact replaces the history with a summary. With instructions, the summary keeps what you chose instead of what the automatic pass guesses matters.
Two neighbours are worth knowing. /rewind can summarize part of the conversation from a selected message, and /autocompact with a token count such as /autocompact 500k sets how full the window gets before the automatic pass runs.
When compaction keeps happening
If a single file or tool output is so large that context refills immediately after each summary, Claude Code stops auto-compacting after a few attempts and shows an error rather than looping.
Anthropic's documented recovery is four steps: have Claude read the oversized file in smaller chunks, run /compact with a focus that drops the large output, move the large-file work to a subagent, or run /clear if the earlier conversation is no longer needed.
After a resume
A resumed session opens at a Conversation compacted row and continues from the last summary, the messages that summary left unsummarized, and everything since. The messages the summary replaced are not loaded again.
Related terms
- Context window: the memory compaction frees up.
- Checkpoint: a restore point taken at each prompt, and
/rewindcan summarize from one. - CLAUDE.md: the project-root instructions re-injected after a compaction.
- Session: the conversation being summarized.
- Back to the glossary.
The full guide to this term is the Claude Code context window: what loads before you type, what each read costs, and when the window fills.
Spot the session that is about to compact
The features page lists what Omniscio does with several Claude Code sessions at once, which is where a long-running one is easiest to watch.