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. While it's set, the status line's used_percentage measures against the model's full context window, so it doesn't tell you when compaction will run. Outside scripts and cloud environments, the command, which saves per model, is easier.
/autocompact 500k
Sources
Get notified when a new tip lands
Tip alerts only go out in the app. Install it and turn notifications on.