Claude Code Compact: What Survives /compact
Long Claude Code sessions end the same way: the context window fills and Claude Code compacts the conversation into a summary. Usually you keep working. Sometimes a rule you gave an hour ago is gone. This guide explains Claude Code compact from Anthropic's own docs and changelog, read on November 6, 2026, when the latest release was 2.1.318. It shows when auto-compact triggers and what a compaction keeps. The later sections cover steering the summary and how CLAUDE.md and auto memory fit in.
What is Claude Code compaction, in one sentence?
Claude Code compaction replaces a session's message history with a structured summary, then reloads your instruction files and memory from disk.
Anthropic's glossary describes it as automatic summarization near the limit, with the same command available by hand. The command reference lists /compact with optional focus instructions for the summary. The session then continues from the summary. Anthropic's best practices page now says running out is rare on current models, because most have a 1M-token window and compaction happens near the top of it.
How does /compact differ from /clear and /rewind?
These are the three ways to shrink a conversation.
| /compact | /clear | /rewind, then summarize | |
|---|---|---|---|
| What happens to history | Replaced by a summary | Gone from context. A new conversation starts | Only the part you pick is summarized |
| Continuity | Same conversation, from the summary | None. Resume the old one with /resume | Same conversation |
| Token cost | A large request: it reads the whole conversation to summarize it | Costs nothing | Not stated. A plain rewind reuses the cached prefix |
| Best for | A natural break inside one long task | Switching to unrelated work | Dropping a dead end you went down |
| CLAUDE.md and auto memory | Re-read from disk | Loaded fresh | Not stated in the docs |
Sources: the costs guide on what /compact and /clear cost, and the prompt caching page on rewinding. The context window guide describes the rewind menu's "Summarize from here" and "Summarize up to here" options.
The cost of /compact comes from how the summary is built. Claude Code sends a separate request with your whole history. While the prompt cache is warm, that request reads most of it from cache. After a long break the cache has expired, and the same /compact reprocesses everything at full price. Anthropic's advice is to compact at a natural break, and to rewind when you abandon a path.
When does Claude Code auto-compact?
Auto-compact is on by default. The settings reference lists it as autoCompactEnabled, which you can also toggle in /config. Where it triggers depends on the model, according to the model configuration docs:
- Models with a native 1M window compact before it fills, at about 967K tokens. These include the Fable models, Sonnet 5 and later, Haiku 5.5, and Opus 4.7 and later.
- Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary. So does any model when you set CLAUDE_CODE_DISABLE_1M_CONTEXT to 1.
- Other sessions compact when the conversation reaches the model's context limit. Cloud sessions compact as they approach it.
You can move the trigger. Run /autocompact 500k to set the window for the current model. The setting is saved and applies to later sessions too. The command accepts 100K to 1M tokens, and /autocompact auto returns to the default. The CLAUDE_CODE_AUTO_COMPACT_WINDOW variable overrides it. Behind an LLM gateway that rejects requests over 200K tokens, Anthropic says to set that variable to 200000.
Compaction can also happen while you are away. Idle compaction arrived in the terminal in version 2.1.299 on October 14, 2026. Per the settings reference, it compacts a conversation of at least 200,000 tokens that sits idle for about an hour on the one-hour prompt cache. Your next message then sends the short summary, so a cold history is not reprocessed. Set idleCompaction to false if you would rather come back to the full conversation.
To turn compaction off, the environment variable list has two switches. DISABLE_AUTO_COMPACT stops automatic and idle compaction for one session but leaves /compact available. DISABLE_COMPACT stops both.
What survives compaction, and what is lost?
The context window guide has a table for each kind of content. What came from a file on disk mostly comes back. What existed only in the conversation is summarized.
Reloaded after compaction:
- The system prompt and output style still apply.
- Project-root CLAUDE.md and rules without a paths field are re-injected from disk.
- Auto memory is re-injected from disk.
- Skill descriptions are rebuilt from your current skills (version 2.1.304 or later).
- The plan Claude wrote in plan mode is re-injected.
- Up to five files Claude read or edited are re-read, most recently modified first. A file over 5,000 tokens comes back as a path reference without its content.
- Invoked skill bodies return, capped at 5,000 tokens per skill and 25,000 in total. The oldest are dropped first, and truncation keeps the start of each file.
Summarized away, or reloaded only later:
- Your conversation and Claude's replies. The how Claude Code works page says the summary keeps your requests and key code snippets, but detailed instructions from early in the conversation may be lost.
- Context that hooks added earlier.
- Nested CLAUDE.md files in subdirectories and rules with a paths field. They come back only when Claude touches a matching file again.
Background commands and background subagents keep running through a compaction.
How do you control what /compact keeps?
Anthropic documents four levers, from lightest to strongest.
A focus line is the lightest. Type /compact focus on the auth bug fix and the summary keeps what you name.
For the automatic passes, add a standing instruction to the project-root CLAUDE.md. The costs guide shows a section headed "Compact instructions" that tells Claude what to keep, such as test output and code changes. Because the root CLAUDE.md is reloaded after every compaction, the instruction is always in front of Claude.
A SessionStart hook with the compact matcher goes further. Claude Code runs it after compaction and adds its output to the new context. Our Claude Code hooks guide has an example.
The strongest fix is moving the rule out of the conversation altogether. Anthropic's memory docs give three reasons an instruction disappears after /compact. It was given only in conversation. It sits in a nested CLAUDE.md that has not reloaded. Or it is a path-scoped rule that has not matched a file since. The fix in each case is to put it in the root CLAUDE.md or drop the paths field.
How do subagents keep the main context small?
A subagent works in its own context window. Its file reads and tool calls stay there, and only a summary comes back to your conversation. Delegating a large search or a long log read keeps that output out of your window, so your own compaction comes later.
Subagents compact on their own as their window fills, and a main-conversation compaction leaves their transcripts alone. Version 2.1.296, released October 9, 2026, added an autoCompactWindow field to subagent definitions, per the changelog. It lets one subagent compact earlier than the main conversation. The docs say to write it as a plain integer such as 200000. In frontmatter "200k" is read as 200, which is out of range and ignored. The field can only lower the window, never raise it.
Version 2.1.316, released October 31, added CLAUDE_CODE_SUBAGENT_EFFORT. It sets the effort level for subagents that do not name one, where they previously inherited the session's level. The variable is in the changelog but not yet on the environment variable page.
What changed in recent Claude Code releases?
Three recent changelog entries matter for everyday use.
- Before 2.1.311 (October 26), a standard-context session could stop with "Usage credits required for 1M context" once a request went past 200K tokens. The changelog lists this as a fix: Claude Code now compacts the conversation and continues.
- The same release fixed Claude seeing old MEMORY.md and CLAUDE.md content right after an automatic compaction, when those files had been edited earlier in the session.
- Version 2.1.312 (October 27) fixed Claude overwriting a very large CLAUDE.md, rules file or included file in a subdirectory after seeing only its start. Write now asks Claude to read the whole file or edit in place.
Very large instruction files cause their own trouble. Anthropic's memory docs suggest keeping each CLAUDE.md under 200 lines and moving narrow guidance into path-scoped rules.
How does compaction relate to CLAUDE.md and auto memory?
Both are files, so both outlive the summary. Per the prompt caching page, the root CLAUDE.md is read once at session start and held in memory. An edit you make mid-session applies only after the next /clear, /compact or restart.
Auto memory works the same way. Claude writes notes to a memory folder per project under ~/.claude/projects. The first 200 lines or 25KB of MEMORY.md load at the start of every conversation. They are re-injected after compaction. The docs also say auto memory is machine-local and not shared across machines or cloud environments.
A fact survives compaction only if it is in a file. Claude Code does keep the full session as a transcript on disk, according to the sessions docs. A resumed session continues from the last summary. The messages that summary replaced are not loaded again.
The bottom line
Put anything Claude must always follow in the project-root CLAUDE.md, including a short "Compact instructions" section. Run /compact with a focus at natural breaks and /clear between unrelated tasks. Send large reads to subagents. If you are on Claude Code older than 2.1.311, update, because those fixes change what you see right after a compaction.
How do you keep what Claude Code learns across machines and agents?
Compaction manages one session. On Tuesday, Claude Code learns that your integration tests need a local database started first, and auto memory saves a note. On Wednesday you open the same repo on your laptop. The note is not there, and Codex never had it. Auto memory is machine-local, and only Claude Code reads it.
| Claude Code compaction and auto memory | memU | |
|---|---|---|
| Scope | One session, then a memory folder per project | One memory shared across sessions, agents and devices |
| Who can read it | Claude Code on this machine | Every supported host, including Claude Code, Codex and Cursor |
| What it works from | The live context, plus notes Claude chose to save | The session transcripts Claude Code already writes to disk, which your agent distills into Markdown |
| Skills | Skills you write and maintain yourself, reloaded after compaction | Reusable skills distilled from agent history, as Markdown |
If you only use Claude Code on one machine, a good CLAUDE.md and auto memory are enough. Compaction already reloads both. Nothing needs installing, and the files stay on your disk.
To try the hosted version, get an API key from memu.so and send Claude Code one message:
Read https://memu.pro/SKILL.md, follow its instructions to install and configure memU, API Key is
YOUR_MEMU_API_KEY.
The self-hosted setup and the per-host support matrix are in the memU GitHub repository. For running one memory across several coding agents, see our guide to sharing memory between coding agents. More on the design is at memu.pro.
FAQ
What does /compact do in Claude Code?
It replaces the conversation history with a summary to free context. Then it reloads the project-root CLAUDE.md and auto memory from disk, plus up to five recent files. You can add focus instructions, such as "/compact keep the API changes", to control what the summary keeps.
When does Claude Code auto-compact?
On models with a native 1M window, at about 967K tokens by default. Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary. You can change the point with /autocompact, and a long idle session can also be compacted before its prompt cache expires.
Does CLAUDE.md survive compaction?
The project-root CLAUDE.md does, because Claude Code re-reads it from disk afterward. Nested CLAUDE.md files and path-scoped rules are summarized away and reload only when Claude works on a matching file again.
Should I use /clear or /compact?
Use /clear when you switch to unrelated work, because it costs nothing and gives Claude a clean context. Use /compact when you want to continue the same task with less history.
How do I stop Claude Code from compacting automatically?
Set autoCompactEnabled to false in settings, or DISABLE_AUTO_COMPACT to 1 for one session. Manual /compact still works. DISABLE_COMPACT turns off both automatic and manual compaction.