// The guide
Claude Code auto-compact: the threshold setting that actually exists.
If you searched for a way to make Claude Code compact earlier, you probably found the same tip we did: add "autoCompactThreshold": 80 to your settings.json. We tried it. It does nothing. So we read the code Claude Code actually ships and found the knob that does work. Here it is, with the honest caveats.
Everything below was verified on Claude Code v2.1.211 by reading the shipped binary, not by quoting other blog posts. Version matters; re-check after big updates.
Auto-compact in one minute
Claude Code works inside a fixed context window. As a session grows, the window fills. When it gets close to full, auto-compact kicks in: the conversation is summarized, the summary replaces the history, and the session continues with room to breathe.
The catch is timing. By default, compaction fires near the ceiling. At that point the summarizer is working under pressure, with a nearly full window, and the summary loses more nuance than an earlier, deliberate one would. If you have ever watched Claude Code come back from a compact slightly dumber about your task, that is why.
So the question is legitimate: how do you move the trigger earlier?
The tip that doesn't work
A widely shared tip says to put this in settings.json:
{ "autoCompactThreshold": 80 }
That key does not exist as a setting. In the 2.1.211 binary, the string autoCompactThreshold appears only as an internal telemetry field — a name the app uses when reporting metrics, not a setting it reads. Nothing in the settings loader looks for it.
The trap is that it fails silently. settings.json accepts unknown keys without complaint, so you add the line, nothing breaks, and you assume it worked. It didn't. Your threshold never moved.
What's officially documented
The official settings docs give you exactly two switches, both on/off:
autoCompactEnabledin settings.json. Boolean, defaulttrue. Set it tofalseand auto-compact never fires.- The
DISABLE_AUTO_COMPACT=1environment variable. Same effect.
No threshold. Officially, auto-compact is all or nothing.
The knob that actually exists
The binary reads an environment variable the docs never mention:
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=40
It takes a value from 1 to 100. The verified semantics: the auto-compact threshold becomes floor(context window × n / 100) tokens, capped at the internal default (the window minus 13,000 tokens). So 40 means auto-compact triggers at roughly 40% of the context window used, instead of near the top.
To make it permanent, put it in the env block of ~/.claude/settings.json:
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "40"
}
}
Or export it in your shell profile. Either way it takes effect on new sessions, not the one currently running.
How the engine decides: warn, compact, blocked
Under the hood, Claude Code computes a level from the current token count. Three levels matter:
- warn — you are within 20,000 tokens of the threshold. The status line starts nudging you.
- compact — the threshold is reached. Auto-compact fires (if enabled).
- blocked — you are near the hard ceiling of the window. No more room.
The percentage in the status line and these levels are consistent with each other, so what you see is what the engine acts on. Lowering the override moves the whole ladder down: you get warned earlier and compacted earlier, far away from the blocked zone where summaries are at their worst.
The honest caveats
- This is undocumented. Inside the binary the variable is named as a test override. It can change or disappear in any release, without notice. It works on 2.1.211; re-verify after you update.
- Lower is not better. Every compact costs a summarization pass and loses some nuance. Set it too low and you compact constantly, paying that price over and over. 40 to 70 is a sane range. We run 40.
- It only moves the automatic trigger. It does not change the window size, and it does not make summaries better. It just buys them room.
The better habit: /compact on your terms
The override is a safety net, not a strategy. The best compaction is the one you run yourself: type /compact at a natural breakpoint — a task finished, findings written to a file, state saved. A deliberate compact with everything persisted beats any automatic one that lands mid-task, whatever the threshold.
The pattern that works: finish a chunk of work, persist what matters to disk, then compact. The override exists for the sessions where you forget.
We hit all of this while building Klyr, which gives Claude Code a memory that lives outside the context window — so what your assistant knows about you survives every compact, every session, every machine. Compaction is exactly the moment a stock assistant forgets; it is the moment Klyr is built for.
New to Claude Code entirely? Start with our non-developer guide first.
FAQ
Does autoCompactThreshold in settings.json work?
No. In Claude Code 2.1.211 that string exists only as an internal telemetry field name. The settings loader never reads it. It fails silently, which is why the tip keeps spreading.
How do I make Claude Code auto-compact earlier?
Set the environment variable CLAUDE_AUTOCOMPACT_PCT_OVERRIDE to a value from 1 to 100, for example 40. The threshold becomes that percentage of the context window. Put it in the env block of ~/.claude/settings.json to make it persistent. New sessions only.
Is CLAUDE_AUTOCOMPACT_PCT_OVERRIDE official?
No. It is undocumented and internally marked as a test override. It works on version 2.1.211, verified by reading the shipped binary. It may change or disappear in any release.
What value should I use?
40 to 70. Lower means earlier, better-quality compaction but more frequent summarization, and every summary loses some nuance. We run 40.
How do I disable auto-compact completely?
Set autoCompactEnabled to false in settings.json, or set the environment variable DISABLE_AUTO_COMPACT=1. Both are official. You will then hit the context ceiling with no safety net, so compact manually.
What do the warn, compact and blocked levels mean?
Internal levels Claude Code computes from your token count: warn means you are within 20,000 tokens of the auto-compact threshold, compact means the threshold is reached and auto-compact fires, blocked means you are near the hard ceiling of the window.