Claude Code Auto-Compact Threshold: When It Compacts and How to Compact Earlier
When Claude Code compacts a conversation by default, the three settings that move that point (the auto-compact window, CLAUDE_AUTOCOMPACT_PCT_OVERRIDE and the off switch), idle compaction, and the same long task run twice with and without a 50 % threshold: one compaction against two, and both runs stopped before the end.
Google completes "claude code auto compact" with "threshold", "settings", "default" and "at 50", and "claude code compact threshold" with "set", "change" and "default auto compact threshold". People want to know when Claude Code summarizes its own conversation, and how to make it do it sooner.
Short answer: by default, Claude Code compacts when the conversation reaches the model's context limit, about 967K tokens on a model with a native 1M window. You make it compact earlier with a smaller auto-compact window, or with CLAUDE_AUTOCOMPACT_PCT_OVERRIDE, a percentage of that window. Earlier is not free: we ran the same long task twice, with and without a 50 % threshold, and counted what changed.
Everything below was checked on November 26, 2026, against Anthropic's documentation (code.claude.com, pages Model configuration, Environment variables, Settings reference and Context window) and Claude Code 2.1.318 installed on our machine.
When Claude Code compacts by default
Compaction replaces the conversation with a summary that Claude keeps working from, so a full context window does not end the session. Without any setting, the documentation gives these points:
- Models with a native 1M window, the Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.7 and later, "compact before the window fills, at about 967K tokens by default".
- Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary. So do the 1M models when you set
CLAUDE_CODE_DISABLE_1M_CONTEXT=1. - Cloud sessions compact as the conversation approaches the model's limit.
- A model ID Claude Code does not recognize, such as an LLM gateway alias, compacts at the context window Claude Code assumes for that ID.
That is why "the default threshold is 95 %" is only roughly true: on a 1M model, 967K tokens is about 97 % of the window, and the documentation never states it as a percentage.
Three settings move that point
The auto-compact window
The auto-compact window is how full the context can get before Claude Code compacts. You can set it four ways:
/autocompact 500ksaves a window for the current model in your user settings and applies it now./autocompact autoreturns to the window tuned for your model."autoCompactWindow": 200000in a settings file sets it for every model.claude --autocompact 300ksets it for one launch without changing what you saved.CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000in scripts and cloud environments. It takes precedence over the command, the flag and the setting.
The window is 100,000 tokens at least, and Claude Code caps it at the model's context window. One trap: in the variable, a number without a suffix is read as tokens, so CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 means 200 tokens and is treated as the 100k minimum, while /autocompact 200 means 200,000. Suffixes such as 200k work in the variable from v2.1.304.
The percentage: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
This variable sets "the percentage (1-100) of the auto-compact window at which auto-compaction triggers". The documentation suggests lower values "like 50 to compact earlier", and it applies to both main conversations and subagents.
export CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70
claude
To keep it, put it in the env block of ~/.claude/settings.json. It only works one way: the variable can't raise the threshold, so a value above the default percentage is ignored.
The off switch
"autoCompactEnabled": falsein a settings file, or the matching row in/config, turns automatic compaction off.DISABLE_AUTO_COMPACT=1does the same for a session, overrides the setting and also stops idle compaction./compactstays available.DISABLE_COMPACT=1disables all compaction,/compactand the rewind menu's summarize options included.
Idle compaction runs while you are away
A second kind of compaction does not wait for a full window. Idle compaction summarizes a long conversation you stepped away from, before its prompt cache expires, and you see a line that starts with Compacted while idle, before the prompt cache expired when you come back.
It is on by default when all of these are true: an interactive terminal session, the VS Code chat panel, or the desktop app's Code tab on your machine or over SSH; autoCompactEnabled on; the conversation on the one-hour prompt cache; a context of at least 200,000 tokens; and about an hour since the last request. CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS changes that size, 100,000 at least. To turn it off, set "idleCompaction": false, or change the Idle compaction row in /config.
We ran the same task twice
The documentation says what each setting does. We wanted to see what compacting earlier changes in a real run.
The task. Twelve generated log files, 411 KB in total, about 15,000 tokens each once read. The prompt, identical in both runs: read the files one at a time, from 01 to 12, write one line per file with the busiest node of its summary line, then answer from memory a question about a release codename written in file 01, without reading it again.
The setup. Claude Code 2.1.318, Haiku 5.5, started with claude -p, the Read tool only, no MCP server, a fresh copy of the files in a throwaway folder, on November 26, 2026. Both runs set CLAUDE_CODE_AUTO_COMPACT_WINDOW=100000, so that compaction happens inside a short run instead of after a million tokens. Run A: nothing else. Run B: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50.
| Run A: window 100,000 | Run B: same window, 50 % | |
|---|---|---|
| Compactions | 1 | 2 |
| Context when compaction started | 77,248 tokens | 46,601, then 47,980 tokens |
| Context right after | 15,971 tokens | 15,337, then 6,708 tokens |
| Time spent compacting | 10.0 s | 9.5 s + 7.9 s |
| Files done when the run ended | 5 of 12 | 4 of 12 |
| Question about file 01 | never reached | never reached |
| Wall time | 23 s | 29 s |
| List-price cost | 0.026 dollars | 0.023 dollars |
Three things came out of it.
The window is a ceiling, not the trigger. With a 100,000-token window and no percentage, the compaction started at 77,248 tokens, 77 % of the window, not at 100,000. Set a window and expect compaction a good margin before it.
The percentage does exactly what it says. At 50 %, compaction started at 46,601 and then 47,980 tokens, half the window, twice instead of once. Each compaction cost about 8 to 10 seconds and one model call to write the summary.
Both runs stopped before the end. After its compaction, the agent finished one more file and ended its turn: at file 5 in run A, at file 4 in run B. Neither reached the question about file 01. This is one run per setting, on a small model, in claude -p, so we do not claim it always happens. But it shows the real cost of compacting earlier: more summaries, so more chances that an instruction given once, at the start, does not make it through.
How to compact earlier without losing the plan
- Write the plan where a summary cannot drop it. A multi-step task belongs in a file the agent rereads, a checklist in the repository, not only in the first prompt.
- Tell compaction what to keep. A
# Compact instructionssection inCLAUDE.md, for example "When you are using compact, please focus on test output and code changes", applies to every compaction./compact focus on the auth bug fixdoes it for one. - Compact by hand at a natural break. Anthropic suggests running
/compactwith instructions before starting a long new task, which beats an automatic summary in the middle of one. - Pick a moderate value. 70 to 80 % keeps each turn's context smaller on a long session without summarizing every few files. We would keep 50 % and below for long automated runs whose plan lives in a file.
The PreCompact and PostCompact hooks, with the matchers manual and auto, let you run your own command before and after each compaction, for instance to log when it happens.
How we set it for every agent in AgentsRoom
We run most of our agents side by side in AgentsRoom, and setting an environment variable in each terminal does not scale to a dozen agents. The Compact earlier setting does it once: Settings > AI providers > Claude tab > Compact earlier, then Compact at, from 10 to 95 %, 75 % proposed when you turn it on. It is off by default. AgentsRoom adds CLAUDE_AUTOCOMPACT_PCT_OVERRIDE to the launch line of each Claude Code agent, from the next launch, whether you start the agent on the desktop or from your phone, and a value you export in your own shell wins.
Codex has its own threshold, in tokens, in the agent's context field. The other CLIs keep their own behaviour.
Compacting earlier is half of the problem. The other half is noticing that an agent has already lost the thread: Context Canary warns you when an agent stops writing its one-line status two turns in a row, with a button to restart it on a clean context. The token counter shows how full each session is getting.
Frequently asked questions
What is the default auto-compact threshold in Claude Code?
There is no single percentage. Anthropic's documentation, read on November 26, 2026, says that without an auto-compact window set, Claude Code compacts when the conversation reaches the model's context limit. Models with a native 1M window, such as Sonnet 5, Haiku 5.5 and the Fable models, compact before the window fills, at about 967K tokens. Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary, and so do 1M models when CLAUDE_CODE_DISABLE_1M_CONTEXT=1 is set.
How do I make Claude Code compact earlier?
Two ways. Lower the auto-compact window, the token count Claude Code lets the context reach: /autocompact 500k for the current model, "autoCompactWindow": 200000 in a settings file, claude --autocompact for one launch, or CLAUDE_CODE_AUTO_COMPACT_WINDOW in scripts (100,000 tokens minimum). Or set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE to a percentage of that window, from 1 to 100: the documentation suggests 50 to compact earlier. In AgentsRoom, the Compact earlier setting sets that percentage for every Claude Code agent.
Can CLAUDE_AUTOCOMPACT_PCT_OVERRIDE make Claude Code compact later?
No. The documentation says the variable can't raise the threshold, so a value above the default percentage is ignored. To give a conversation more room, you would need a larger auto-compact window, and Claude Code caps any window at the model's context window.
How do I turn off auto-compact in Claude Code?
Set "autoCompactEnabled": false in a settings file, or turn it off in /config. For one session, DISABLE_AUTO_COMPACT=1 does the same, overrides the setting and also stops idle compaction, while /compact stays available. DISABLE_COMPACT=1 goes further: it disables all compaction, /compact included.
What is idle compaction in Claude Code, and how do I turn it off?
Idle compaction summarizes a long conversation you stepped away from, so your next message sends a summary instead of the whole conversation. It is on by default when the session is interactive, auto-compaction is on, the conversation uses the one-hour prompt cache, its context has reached 200,000 tokens and about an hour has passed. Set "idleCompaction": false, or change the Idle compaction row in /config (v2.1.302 or later), to turn it off.
What does /compact do, and can I tell it what to keep?
/compact frees context by summarizing the conversation so far. You can pass focus instructions, such as /compact focus on the auth bug fix, and a Compact instructions section in CLAUDE.md tells every compaction what to preserve. Anthropic suggests running /compact with instructions before starting a long new task.
Download AgentsRoom
Run all your AI agents, on all your projects, from a single window.
Companion app: monitor your agents on the go
Bring your own: Claude, Codex, Antigravity CLI, or other AI provider.
Push bugs and requests straight to your public backlog.
Keep reading
How to Remove Co-Authored-By Claude From Your Git Commits
Claude Code signs your commits with a Co-Authored-By trailer and your pull requests with a Generated with Claude Code line. The setting that removes them, the file to put it in, and how to clean commits you already pushed.
Read the articleHow to Install Claude Code Skills from GitHub and Keep Them Updated
Three ways to install a Claude Code skill from GitHub: the plugin marketplace, a folder in ~/.claude/skills or .claude/skills, or a skill library linked to the repository. The exact commands, where each copy lives, how it gets updated, how Codex reads the same SKILL.md, and what we measured on Anthropic's own repository: 19 skills, 16 that copy over whole.
Read the articleClaude Code's Code Mode, Tested: 29% Fewer Tokens, Twice the Time
Code Mode is an experimental Claude Code setting in which Claude writes JavaScript that calls its tools, instead of calling them one at a time. How to turn it on, where it does not start, and the same 138-file link check run twice on Claude Code 2.1.331: same answer, 29% fewer input tokens, 31 seconds against 14.
Read the article