What each harness does when the conversation outgrows the context window: when it compacts, what it keeps, and how you can steer it.
When it happens
| Question | Claude Codechecked at 2.1.299 |
|---|---|
| Automatic compaction, and when | Yes. Without a configured window, Claude Code compacts as the conversation reaches the model's context limit; models running a native 1M window (Fable, Sonnet 5+, Haiku 5.5, Opus 4.7+) compact at about 967K tokens, and Sonnet 4.6 / Opus 4.6 without Since v2.1.290 it also compacts a terminal conversation of 200K+ tokens left idle about 54 minutes on the one-hour prompt cache, just before the cache expires ( On a model ID it doesn't recognise (such as a gateway alias) it compacts at the window it assumes for that ID; correct it with Subagents compact independently as their own context fills. 2.1.314 publisher adds idle compaction in VS Code and Claude Desktop Code tabs for idle conversations over 200K tokens; the prepared summary is used on the next message if prompt cache expired. Telemetry-off subscribers and third-party providers are included once one-hour prompt caching is on. This is a host-specific idle path, not a replacement automatic token threshold. 2.1.321 fixes tool-definition overcounting and background-subagent reports lost around compaction. Documentation only. 2.1.326 publisher notes repair summary generation on Bedrock/Vertex/Foundry and with telemetry off. 2.1.327 repairs teammate compaction using the lead model/window and preservation of a tool call/result after an output-limited reply. 2.1.328 rebuilds the system prompt for automatic compaction as manual /compact does. No runtime probe. |
| Change the trigger or turn it off | Set the auto-compact window (100K to 1M tokens, capped at the model's window) with A subagent can compact earlier with Turning auto-compact off also turns off idle compaction; set 2.1.302 adds an Idle compaction row in /config to turn the idle pass off or back on, alongside the existing idleCompaction setting. Published changes also fix stopping a turn during compaction causing Prompt is too long. Before 2.1.304, suffixes could be parsed as a small integer and clamped to 100K. The 2.1.304 changelog says k and M suffixes now work, with warnings for out-of-range or ignored values. 2.1.311 publisher notes: settings-file and mod $.env.set DISABLE_COMPACT values can disable compaction but cannot re-enable it; teammates and rewind summary actions now honor DISABLE_COMPACT. No runtime probe. 2.1.312 publisher notes: a subagent's |
| Compact by hand | Run |
| See how full the context is | Run The status line percentage is measured against the model's full window, so it no longer shows when compaction will run once you set a smaller auto-compact window. |
What it does
| Question | Claude Codechecked at 2.1.299 |
|---|---|
| What replaces the conversation | Claude Code sends a separate request to the session's model with the same system prompt, tools and history plus a summarisation instruction, and replaces the message history with the structured summary it returns (you see "Conversation compacted"). The request inherits the session's extended-thinking setting and uses your fallback model chain, but never falls back to a model with a smaller context window. Startup context such as CLAUDE.md and memory is then reloaded from disk around the summary. In 2.1.301, switching to a smaller model window can first summarize the conversation with the previous model. The release also fixes repeated compaction when a gateway reports a different model name. These are published changes, not a new measured threshold. |
| What survives | The system prompt and output style still apply; project-root CLAUDE.md, unscoped rules, auto memory and the plan-mode plan are re-injected from disk, and a fresh git status is read. Claude Code re-reads up to five recently modified files it read or edited (files over 5,000 tokens come back as a path only), re-injects invoked skill bodies capped at 5,000 tokens each and 25,000 total, keeps the task list, and reminds Claude of running background commands and subagents. Path-scoped rules and nested CLAUDE.md files are summarised away until a matching file is touched again, and the skill listing is not re-sent. Recent turns are folded into the summary rather than kept verbatim, except in overflow recovery, which can keep the newest exchanges or your newest prompt word for word. Before 2.1.304, /reload-skills was the documented way to restore the catalog after compaction; the 2.1.304 release changes this behavior as described below. 2.1.304 resends the skill list after compaction; /reload-skills sends only new or changed skills. This listing is separate from restoring invoked skill bodies. 2.1.309 loads only the beginning of oversized nested CLAUDE.md files to avoid repeated compaction. Exact prefix size is unverified. 2.1.311 publisher notes fix stale MEMORY.md and CLAUDE.md immediately after automatic compaction when edited earlier in the session. This corrects freshness, not the independently documented reinjection budgets. |
| Trimming without summarising | Yes. As the context fills, Claude Code clears older tool outputs first and only summarises if that isn't enough, and when a request would exceed the image or PDF limits it drops a batch of the oldest images and PDFs. There is no setting to tune or disable this clearing. |
| The full history afterwards | Yes. The session JSONL in With Transcripts are deleted after |
Shaping it
| Question | Claude Codechecked at 2.1.299 |
|---|---|
| Customise the summary or hook in | Pass instructions to Blocking an automatic compaction that was triggered to recover from an overflow makes the request fail with the original error. |
| When a request overflows anyway | If the API rejects a request as too long ( A single-exchange conversation can't be compacted; the error explains whether your content or the system prompt, tools and attachments fill the request.
2.1.304 fixes prompt/context-limit errors after interrupting compaction of a conversation rejected as too long, according to the release notes. 2.1.305 reports truncated summary coverage to cloud sessions/teammates; 2.1.306 fixes unrelated API errors being replaced by prompt-too-long and unnecessary compaction; 2.1.307 fixes some large PDF/image/tool-result thrashing. These are publisher fixes, not newly measured thresholds. 2.1.311 usually retries a missing summary once before replacing history. 2.1.310 fixes dense-text overflow recovery retaining too much; 2.1.311 compacts and continues standard-context requests exceeding 200K instead of stopping with a 1M-credit error. Publisher evidence, not a new universal trigger. |