Claude Code — autoCompact Configuration
Control when Claude Code compresses its context window and how to reduce token waste from noisy tool output.
Why / When to Use
autoCompact fires at 95% context by default. For small model windows (e.g. 32K DeepSeek) this leaves almost no room for the response — adjust the threshold or disable entirely.
Core Concept / Commands
Adjust the threshold
Add to settings.json under the env block:
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "70"
}70% fires compaction at ~70% of the context window, giving the model breathing room before the limit.
Disable autoCompact entirely
claude config set -g autoCompactEnabled falseOr via environment variable:
export DISABLE_AUTO_COMPACT=trueCollapse blank lines to save tokens
Verbose tools (test runners, linters) often emit multiple blank lines. Each \n is a token.
Collapse runs of 3+ newlines to 2:
import re
re.sub(r'\n{3,}', '\n\n', text)Small per-command, but stacks across a full session.
Key Options / Variants
| Variable | Default | Effect |
|---|---|---|
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | 95 | % of context window at which compaction fires |
DISABLE_AUTO_COMPACT | unset | Set to true to disable entirely |
claude config set -g autoCompactEnabled false | — | Persists disable to ~/.claude.json |
Gotchas
- At 95% default + 32K window → compaction fires at ~30K, leaving only ~2K for the response.
- 70% on 32K → fires at ~22K, giving ~10K headroom.
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEgoes in theenvblock ofsettings.json, not as a top-level key.
Source
Conversation: “Analyzing GitHub issue resolution” — 2026-05-16