How to set Claude Code's auto-compact window env var with k and M suffixes
Claude Code summarizes earlier conversation once it fills the auto-compact window. Starting with 2.1.304, released October 19, the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable also accepts k (thousands) and M (millions) suffixes. In earlier versions, 200k silently ran with the 100K minimum window.
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=200k
The range is 100000 to 1000000 tokens, capped at the model's context window. Values out of range or unreadable now show a warning.
A number without a suffix is read as tokens. /autocompact 200 means 200,000 tokens, but CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 means 200 tokens and is clamped to the 100K minimum.
The variable takes precedence over the /autocompact command, the --autocompact flag and the autoCompactWindow setting. Since 2.1.336 (December 3), the status line's used_percentage also measures against this auto-compact window, so it tracks when compaction will run. Earlier versions measured against the model's full context window. Outside scripts and cloud environments, the command, which saves per model, is easier.
/autocompact 500k
If you don't set a window, models that run with a 1M context window (the Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.7 and later) compact at about 367K tokens from 2.1.334 (December 1), up from about 967K in earlier versions. If you keep one session open all day, every question resends that whole conversation, so set a smaller window to compact earlier. To return to the window tuned for your model, pass auto.
/autocompact 400k
/autocompact auto
Sources
- Claude Code changelog 2.1.304 (2026-10-19)code.claude.com ↗
- Model configuration: Set the auto-compact windowcode.claude.com ↗
- Environment variables: CLAUDE_CODE_AUTO_COMPACT_WINDOWcode.claude.com ↗
- Model configuration: Default auto-compact thresholdscode.claude.com ↗
- Claude Code changelog 2.1.334 (2026-12-01)code.claude.com ↗
Get notified when a new tip lands
Tip alerts only go out in the app. Install it and turn notifications on.