CLAUDE_CODE_AUTO_COMPACT_WINDOW

Updated by

CLAUDE_CODE_AUTO_COMPACT_WINDOW sets the context size in tokens at which auto-compact summarizes the conversation; minimum 100,000, capped at the model's context window. Default: auto, a window tuned for the model, never above its context window. Values: Token count of 100000 or more; k and M suffixes (200k, 1M) need v2.1.304+. A bare number is tokens, not thousands. Values below 100k are raised to 100k; unparseable values are ignored. Added between v2.1.77 and v2.1.79 and still present in v2.1.332. It is listed in the official reference.

StatusPresent in v2.1.332
AddedAdded between v2.1.77 and v2.1.79
Defaultauto, a window tuned for the model, never above its context window
ValuesToken count of 100000 or more; k and M suffixes (200k, 1M) need v2.1.304+. A bare number is tokens, not thousands. Values below 100k are raised to 100k; unparseable values are ignored
CategoryContext and compaction
Official docsListed
Checked againstv2.1.330

How to set it

For one session, export it in the shell that starts Claude Code:

export CLAUDE_CODE_AUTO_COMPACT_WINDOW=400k
claude

400k compact later than the default on a 1M-context model.

To apply it to every session, add it to the env object of a settings file:

// ~/.claude/settings.json
{
  "env": {
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "400k"
  }
}

Known issues

  • A bare number is read as tokens, so CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 means 200 tokens and Claude Code raises it to the 100k minimum with a warning. /autocompact 200 means 200,000; for the variable write 200k or 200000. Source: docs: model config.
  • The variable beats /autocompact, --autocompact and the autoCompactWindow setting, and /autocompact only reports the override. The status line's used_percentage is measured against the full model window, so it does not show when compaction will run. Source: docs: model config.
  • One value applies to the main session and every subagent. A subagent's autoCompactWindow frontmatter can lower its own window but never raise it above the variable. Source: issue #90347.

Release notes that mention it

Related variables

Frequently asked questions

What does CLAUDE_CODE_AUTO_COMPACT_WINDOW do?

Sets the context size in tokens at which auto-compact summarizes the conversation; minimum 100,000, capped at the model's context window.

What is the default value of CLAUDE_CODE_AUTO_COMPACT_WINDOW?

Auto, a window tuned for the model, never above its context window.

What values does CLAUDE_CODE_AUTO_COMPACT_WINDOW accept?

Token count of 100000 or more; k and M suffixes (200k, 1M) need v2.1.304+. A bare number is tokens, not thousands. Values below 100k are raised to 100k; unparseable values are ignored.

Which Claude Code version has CLAUDE_CODE_AUTO_COMPACT_WINDOW?

Added between v2.1.77 and v2.1.79 and still present in v2.1.332.

How do I set CLAUDE_CODE_AUTO_COMPACT_WINDOW?

Export it before starting Claude Code (export CLAUDE_CODE_AUTO_COMPACT_WINDOW=400k), or add it to the "env" object in ~/.claude/settings.json to apply it to every session. 400k compact later than the default on a 1M-context model.

All variables, searchable: Claude Code environment variables.