CLAUDE_AUTOCOMPACT_PCT_OVERRIDE

Updated by

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

StatusPresent in v2.1.332
AddedPresent since v2.1.69 or earlier
Defaultabout 83% of a 200k window (167,000 tokens): 13,000 tokens before the context window minus a 20,000-token reply reserve
Valuesa percentage above 0 and up to 100; decimals count as percent, so 0.8 means 0.8%; other 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_AUTOCOMPACT_PCT_OVERRIDE=70
claude

70 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

Related variables

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.