See what Claude Code keeps when it compacts
Compaction has a bad reputation. It gets treated as something to avoid, a sign a session went on too long, or a reason to start fresh before it happens. Part of that is because it’s a black box: when a Claude Code conversation compacts, all the app shows is a “compacted” marker. It doesn’t show the summary Claude wrote, what came back after it, or what was lost.
Knowing what compaction does makes it less of a mystery, and you can configure and steer it like the rest of Claude Code.
What’s in context after a compaction
In order from the top of the context, based on Anthropic’s list of what survives and what session transcripts show:
| Part | After compaction |
|---|---|
| System prompt, tools, output style | Unchanged |
Project-root CLAUDE.md, unscoped rules, auto memory |
Reloaded from disk |
Nested CLAUDE.md files and path-scoped rules |
Reloaded when the agent works in that directory again |
| The summary | New, written by Claude from everything before the compaction |
| Recently read or edited files | Up to five re-read; files over 5k tokens kept by path only |
| Invoked skills | Re-attached, 5k tokens each and 25k total, oldest dropped first |
| Skill descriptions, the plan, git status | Reloaded |
| Background commands and subagents | Keep running; Claude gets a reminder of which ones are running |
SessionStart hooks matching compact |
Run again, and their output is added |
| The end of the conversation | Kept word for word |
| Everything else said before the compaction | Gone, except what the summary kept |
The last two rows are the easiest to misunderstand. Claude Code doesn’t keep the last few turns, only the tail of the current one: the latest assistant reply and whatever came right after it. If the agent was mid-task, it’s the tool calls still running and their results.
The summary
Summaries follow the same outline each time:
- Primary Request and Intent
- Key Technical Concepts
- Files and Code Sections
- Errors and fixes
- Problem Solving
- All user messages
- Pending Tasks
- Current Work
- Optional Next Step
They’re usually a few thousand tokens, roughly 2k to 4.5k.
“All user messages” doesn’t mean all of them. Claude writes that section like the rest, so some messages are quoted and others are paraphrased or folded together. In a long session, a later summary may list only the messages since the previous compaction, with older ones reduced to a line in Primary Request and Intent.
Each compaction summarizes a conversation that starts with the previous summary, so anything one summary drops is gone from every summary after it. The full transcript is still on disk, but Claude only sees it if it reads it.
Seeing it
The compaction viewer is a plugin I built that shows what Claude Code doesn’t. It adds a panel beside the conversation, in the terminal or the desktop app. The overview breaks down what’s in context after a compaction, matching the table above:

In this demo session, context went from 168k tokens to about 22.4k, and most of what’s left is the system prompt and tools. The summary itself is 377 tokens.
The diff between compactions shows what got dropped. Between the demo’s second and third compaction, “Tailwind for styling” disappeared from Key Technical Concepts, along with a fixed bug from Errors and fixes:

To install it, run this at a Claude Code prompt:
/plugin install compaction-viewer --marketplace afterimaginary/claude-plugin-context-inspector
Open it with /compacted, or with the N× badge in the footer once the conversation has compacted.
Configuring when it runs
By default, Claude Code picks an auto-compact window tuned for the model. You can change it:
/autocompact 500ksets the window for the current model and saves it./autocompact autogoes back to the default.autoCompactWindowin settings applies to every model, as a token count of at least 100k.claude --autocompact 500ksets it for one launch.CLAUDE_CODE_AUTO_COMPACT_WINDOWsets it in scripts and cloud environments, and overrides the rest.CLAUDE_AUTOCOMPACT_PCT_OVERRIDEcompacts at a percentage of the window, like50. It can only make compaction happen earlier.autoCompactEnabled: falseturns auto-compaction off, along with idle compaction./compactstill works.
Auto-compaction can also prepare the summary in the background before the window fills. When it reuses that summary, compacting is almost instant instead of taking about a minute.
Steering what it keeps
/compact focus on the API changesadds your own instructions to a manual compaction.- A “Compact instructions” section in
CLAUDE.mdapplies to every compaction. - A
PreCompacthook’s output is added to the summary instructions, and the hook can block a compaction.
The most reliable way to keep something is to put it in a file. CLAUDE.md, memory, the plan and recently edited files come back after every compaction. A decision that only exists in chat depends on the summary keeping it. If something is already gone, my backread plugin lets the agent search the transcript from before the compaction.