Omniscio

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.

The mechanisms Claude Code documents, and what happens to each after a compaction.
MechanismAfter compaction
System prompt and output styleBoth still apply
Project-root CLAUDE.md and unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Skill descriptionsRebuilt from your current skills and re-injected, on Claude Code v2.1.304 or later
The plan Claude wrote in plan modeRe-injected from disk
Git status snapshotA fresh one is read from your repository
Rules with paths: frontmatter, and nested CLAUDE.md filesReloaded on demand
Files Claude read or editedUp to five are re-read, most recently modified first
Invoked skill bodiesRe-injected, capped at 5,000 tokens per skill and 25,000 in total
Background commands and subagentsKeep running; Claude is reminded which ones are still going
Context that hooks added earlierSummarized with the rest of the conversation
SessionStart hooks matching the compact sourceRun again, and their output is added to the compacted context
Instructions given only in the conversationMay 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 fix

Run 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.

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.