CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
Updated by Alex Sorokoletov
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE sets when auto-compaction fires, as a percentage of the usable context window. It can only make compaction earlier. Default: about 83% of a 200k window (167,000 tokens): 13,000 tokens before the context window minus a 20,000-token reply reserve. Values: a percentage above 0 and up to 100; decimals count as percent, so 0.8 means 0.8%; other values are ignored. Present since v2.1.69 or earlier and still present in v2.1.332. It is listed in the official reference.
Full guide: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: Complete Guide to Claude Code Auto-Compaction Control
| Status | Present in v2.1.332 |
|---|---|
| Added | Present since v2.1.69 or earlier |
| Default | about 83% of a 200k window (167,000 tokens): 13,000 tokens before the context window minus a 20,000-token reply reserve |
| Values | a percentage above 0 and up to 100; decimals count as percent, so 0.8 means 0.8%; other values are ignored |
| Category | Context and compaction |
| Official docs | Listed |
| Checked against | v2.1.330 |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70
claude70 compacts at about 126,000 tokens of a 200k window, so long tool output still fits after the summary.
To apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "70"
}
}Known issues
- A value above the default point has no effect: the threshold is the lower of your percentage and the default. On a 200k window anything above about 92 changes nothing. To compact later, raise the window with CLAUDE_CODE_AUTO_COMPACT_WINDOW instead. Source: issue #31806.
- The percentage applies to the window that CLAUDE_CODE_AUTO_COMPACT_WINDOW or /autocompact sets, minus the reply reserve, not to the model's full context window. With a 1M window, 50 compacts near 490,000 tokens. Source: CLAUDE_CODE_AUTO_COMPACT_WINDOW.
- An open report says the variable stopped taking effect after v2.1.220. In v2.1.330 the auto-compact threshold still reads it. Source: issue #82761.
Release notes that mention it
- Claude Code "Auto-compact will soon summarize older messages": What /context Is Telling You
- Claude Code "Compacted while idle": What Idle Compaction Does and How to Turn It Off
- Claude Code v2.1.126 — `project purge`, Gateway Model Picker, and What's Actually New
- CLAUDE_CODE_ATTRIBUTION_HEADER: Fix Bedrock 400 Errors & Prompt Caching Issues
- CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: Complete Guide to Claude Code Auto-Compaction Control
- Claude Code v2.1.75 — 2 New Environment Variables: Auto-Compact Window & Plugin Options
- 165 Environment Variables in Claude Code 2.1.69 — What Changed in 50 Versions
- Why Your Claude Code Sessions Keep Dying (And How to Fix Them)
Related variables
CLAUDE_AFTER_LAST_COMPACT: Request only conversation logs after last compaction.CLAUDE_CODE_AUTO_COMPACT_WINDOW: Sets the auto-compact window in tokens, 100k to 1M, capped at the model's context window.CLAUDE_CODE_AUTO_MODE_COMPACT_THREAD_RULE: When set, enables the compact thread rule for auto-mode project threads; while off, thread handling stays on the original path.CLAUDE_CODE_AUTO_MODE_PRIOR_ASSISTANT_CONTEXT: Feeds prior assistant turns into the decision, so the classifier can see the reasoning behind an edit.CLAUDE_CODE_AUTO_MODE_SIBLING_CONTEXT: Includes sibling files (or sessions) when classifying.CLAUDE_CODE_DISABLE_1M_CONTEXT: Disable extended 1M token context window.CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP: Disable skipping pre-compaction checks.CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS: Max tokens for file read output.
Frequently asked questions
What does CLAUDE_AUTOCOMPACT_PCT_OVERRIDE do?
Sets when auto-compaction fires, as a percentage of the usable context window. It can only make compaction earlier.
What is the default value of CLAUDE_AUTOCOMPACT_PCT_OVERRIDE?
About 83% of a 200k window (167,000 tokens): 13,000 tokens before the context window minus a 20,000-token reply reserve.
What values does CLAUDE_AUTOCOMPACT_PCT_OVERRIDE accept?
A percentage above 0 and up to 100; decimals count as percent, so 0.8 means 0.8%; other values are ignored.
Which Claude Code version has CLAUDE_AUTOCOMPACT_PCT_OVERRIDE?
Present since v2.1.69 or earlier and still present in v2.1.332.
How do I set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE?
Export it before starting Claude Code (export CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70), or add it to the "env" object in ~/.claude/settings.json to apply it to every session. 70 compacts at about 126,000 tokens of a 200k window, so long tool output still fits after the summary.
All variables, searchable: Claude Code environment variables.