/autocompact 500k and CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE=50: make Claude Code compact earlier, or never

Claude Code Published: Updated:

/autocompact 500k sets autoCompactWindow, CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE=50 compacts at half the window, autoCompactEnabled: false turns it off. Defaults and precedence.

Verified on Oct 11, 2026 These tools change quickly. Please also check the latest official documentation. How articles are researched and verified
Contents
  1. The default point
  2. Changing the window size
  3. Compacting earlier, or not at all
  4. Summary

In a long session you have probably noticed the conversation get summarized without warning, and a recent instruction lose its edge. The opposite need is just as common: compact earlier, before the context fills, to avoid the performance drop that comes with a full window.

In short: the size of the auto-compact window can be set in three places, /autocompact, the --autocompact flag, and CLAUDE_CODE_AUTO_COMPACT_WINDOW; the percentage of that window at which compaction fires can be lowered with CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE; and autoCompactEnabled: false turns it off.

KEY POINT

What you will learn

  • The default compaction point, which differs by model
  • The three ways to change the window, and their precedence
  • The variable that only makes compaction earlier, and how to disable it

The default point

Without a window set, Claude Code compacts when the conversation reaches the model's context limit, with these exceptions.

SessionCompaction boundary
Native 1M models on the Anthropic API (Sonnet 5, Fable models, Opus 4.7 and later)before the window fills, about 967K tokens by default
Models running at 200K (Sonnet 4.6 / Opus 4.6 without extended context, Opus 4.8 / Opus 5 on Bedrock and similar)the 200K boundary
1M models with CLAUDE_CODE_DISABLE_1M_CONTEXT=1the 200K boundary
Cloud sessionsas the conversation approaches the limit
Model IDs Claude Code does not recognize, such as an LLM gateway aliasthe window Claude Code assumes for that ID

用語解説

Compaction: replacing the conversation history with a summary when the context fills. As of v2.1.198 the summarization request inherits the session's extended thinking setting. /compact does it manually; auto-compact does it for you.

Changing the window size

The window, meaning how full the context gets before compaction, can be set in three places.

MethodScopeNotes
/autocompact 500kthis session and later onessaved to user settings as autoCompactWindow; if a higher settings scope such as managed settings sets the key, the value is saved but the session keeps that scope's window
claude --autocompact 500kone launchoverrides the saved setting without changing it, and is not preempted by managed settings
CLAUDE_CODE_AUTO_COMPACT_WINDOW=500000while setbeats the command, the flag, and the setting; /autocompact reports the override

The command and the flag accept 100K to 1M tokens in any of these forms:

  • a plain token count such as 200000
  • a k or M suffix such as 500k or 1M
  • a bare number from 100 to 1000 meaning thousands, so 200 is 200,000

The environment variable accepts only the plain count. Whichever you use, Claude Code caps the value at the model's context window. /autocompact auto or claude --autocompact auto returns to the model-tuned default.

{
  "autoCompactWindow": 500000
}

Compacting earlier, or not at all

CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE changes not the window but the percentage of it at which compaction fires. Note the CLAUDE_CODE_ prefix: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is not a variable Claude Code reads. Give it 1 to 100; 50 compacts when the window is half full. It only lowers the threshold, so values above the default are ignored. It applies to the main conversation and subagents, and only in sessions that compact before the model's limit.

{
  "env": {
    "CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE": "60"
  }
}

To disable auto-compact entirely, set autoCompactEnabled to false.

{
  "autoCompactEnabled": false
}

If you turn it off, make manual /compact a habit

Disabling auto-compact does not give you more room; once the context fills, the conversation cannot continue. Plan to run /compact focus on the auth changes at natural breakpoints, or /clear when switching tasks.

What survives a compaction and what does not is covered in Managing context in Claude Code.

Summary

  • By default compaction runs when the conversation reaches the model's limit: about 967K for native 1M models, 200K for models running at 200K
  • Change the window with /autocompact (saved), --autocompact (one launch), or CLAUDE_CODE_AUTO_COMPACT_WINDOW (highest priority), from 100K to 1M
  • CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE sets the percentage of the window and only lowers it
  • autoCompactEnabled: false disables auto-compact; manual /compact still works
  • If disabled, compact manually with a focus, or /clear between tasks

FAQ

When does auto-compact run by default?
With no window set, when the conversation reaches the model's context limit. Native 1M models compact at about 967K tokens; models running at 200K compact at the 200K boundary.
What values does /autocompact accept?
100K to 1M tokens, written as 200000, 500k, 1M, or a bare number from 100 to 1000 meaning thousands.
Why doesn't claude_autocompact_pct_override work?
The name is wrong. The documented variable is CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE; the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE spelling is not recognized. It takes a percentage from 1 to 100, so 50 compacts when the window is half full, and it only ever lowers the threshold.
Can I turn auto-compact off completely?
Yes, set autoCompactEnabled to false in settings.json. Manual /compact still works.

Questions & answers

Q. Idle compaction never runs for me. A session well past 200K tokens sat idle for 70 minutes without being compacted, and it never happens in the desktop app's Code tab. What are the conditions?

Answer by the editorsSource: GitHub anthropics/claude-code Issue #103040

The settings reference turns idle compaction on by default only for conversations that meet all five of its conditions. Token count and idle time are two of them, so a conversation can satisfy both and still be excluded by another.

ConditionWhat it requires
SessionAn interactive terminal session
Prompt cacheThe conversation is on the one-hour TTL
Feature flagsClaude Code can fetch feature flags from Anthropic
SizeThe context has reached the threshold, 200,000 tokens by default
Idle timeAbout 54 minutes since the last request, with your computer awake at that point

The desktop app's Code tab is excluded by the first condition. The documentation names an "interactive terminal session" and says nothing about other session types.

The last condition is the one most easily missed: if the machine sleeps during those 54 minutes, nothing runs when it wakes.

A conversation that was actually compacted shows Compacted while idle, before the prompt cache expired, so that message tells you whether it ran.

To change the threshold or turn it off:

{
  "idleCompaction": false
}
# Lower the threshold to 150,000 tokens
export CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS=150000

CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS accepts a positive whole number and ignores anything else. Values below 100000 are raised to 100000, the lowest threshold. Both the key and the variable require Claude Code v2.1.290 or later; on an earlier version, setting autoCompactEnabled to false stops it. Turning auto-compact off turns idle compaction off with it.

From v2.1.302, /config has an Idle compaction row you can toggle.

For the auto-compact window itself, see Making Claude Code compact earlier, or never.

Primary sources

This article was drafted by AI from official documentation and reviewed by the site operator before publishing. Found a mistake? Let us know via the contact page.