Compact earlier or never: Claude Code's /autocompact, autoCompactWindow, and CLAUDE_AUTOCOMPACT_PCT_OVERRIDE

Claude Code Published:

How to change when Claude Code auto-compacts: /autocompact and autoCompactWindow, the --autocompact flag, the percent override, their precedence, and autoCompactEnabled.

Verified on Sep 10, 2026 These tools change quickly. Please also check the latest official documentation.
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_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_AUTOCOMPACT_PCT_OVERRIDE changes not the window but the percentage of it at which compaction fires. 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_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_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.
Can I turn auto-compact off completely?
Yes, set autoCompactEnabled to false in settings.json. Manual /compact still works.

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.