I was reading the v2.1.299 changelog one morning when a single line stopped me: a conversation over 200K tokens that sits idle for about 54 minutes gets compacted before its one-hour prompt cache expires. As an indie developer, I step away from a long session and come back to it almost every day — after lunch, after a call, after a walk to clear my head.
The first thing I want to say is that this is a feature, not a bug. But if Claude seems to have forgotten something you settled an hour ago, the cause may not be the model's mood. It may be this compaction.
Later releases widened where it runs, so I've rebuilt this piece against the current documentation (the idleCompaction entry in the settings reference and the "What survives compaction" section of the context window page) and the changelog, as of November 2026.
What is actually happening
Idle compaction replaces a long conversation with a summary while you're away. When you come back, your next message sends that summary instead of the whole conversation. The point is to spare you the wait and the cost of reprocessing everything once the one-hour prompt cache has expired.
According to the docs, it runs only when all five of these hold (checked against the official docs, November 2026):
| Condition | Detail |
|---|---|
| Session | An interactive terminal session, the VS Code extension's chat panel, or the desktop app's Code tab when the session runs on your machine or over SSH |
| Auto-compaction | autoCompactEnabled is on (the default) |
| Prompt cache | The conversation uses the one-hour cache TTL |
| Size | Context has reached the threshold (200,000 tokens by default) |
| Idle time | About an hour since the last request, with the computer awake the whole time |
The changelog said "about 54 minutes"; the docs say "about an hour." They describe the same intent — run just before the cache expires.
Short conversations, or sessions you keep nudging, are never touched. It's the conversations you've grown carefully over a long afternoon that qualify, which is exactly what makes it awkward.
How it changed between versions
The behavior has shifted several times since I first read about it, so which lines apply depends on the version you're on.
| Version | Change |
|---|---|
| 2.1.290 | First version that honors "idleCompaction": false and CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS |
| 2.1.299 | Idle compaction starts in the terminal |
| 2.1.300 | cache_creation_5m_tokens and cache_creation_1h_tokens added to the OpenTelemetry api_request event |
| 2.1.302 | An Idle compaction row in /config; the post-compaction notice says how to turn it off |
| 2.1.314 | Extended to VS Code and the desktop Code tab; also runs for subscribers with telemetry off, and on Bedrock, Vertex, Foundry and LLM gateways once the one-hour cache is on |
| 2.1.318 | Fixed a conversation being replaced by a reply that wasn't a summary |
| 2.1.332 | Fixed idle compaction being skipped for subscribers well under their weekly limit |
Three common misreadings
"It's a terminal thing." Not since 2.1.314. The VS Code chat panel and the desktop Code tab are covered too, and long editor sessions are precisely the ones that grow past the threshold.
"Raising the threshold will keep my sessions safe." The docs point out that a conversation on a 200K context window auto-compacts before it ever reaches 200,000 tokens. In practice, the default threshold is reached mainly by 1M-context sessions. Raising it to 400,000 only matters there; on a 200K window it changes nothing. If you actually want idle compaction on 200K conversations, you lower the threshold, to something like 150,000. The floor is 100,000 — anything smaller is raised to that.
"Compaction wipes my CLAUDE.md." The project-root CLAUDE.md, auto memory, and the plan written in plan mode are re-read from disk after compaction. What disappears is whatever lived only in the conversation, plus things that load on demand: rules with paths: frontmatter and CLAUDE.md files in subdirectories get summarized away with everything else.
Telling whether it happened
A compaction leaves a notice in the conversation, worded differently per surface:
- Terminal: a line starting with
Compacted while idle, before the prompt cache expired - VS Code chat panel: a notice containing
a summary written while you were away - Desktop Code tab: the same notice inside a row labeled with
Claude Code notice; switch to the Verbose view mode if you can't see it
If you missed the notice, the Prompt cache (main) line in the Session block of /usage is a secondary clue. Compaction is counted there as an "expected rebuild," so a count that went up while you were away means some compaction ran. Manual /compact and ordinary auto-compaction bump it too, though, so the notice text is what settles it.
Next, check which settings file is actually in effect. Settings live at three levels, and the precedence is local (.claude/settings.local.json), then shared project (.claude/settings.json), then user (~/.claude/settings.json).
The checking script in the first version of this article only looked at idleCompaction and the threshold. The docs, however, say idle compaction also stops when autoCompactEnabled is off or DISABLE_AUTO_COMPACT is set. The old script would leave you puzzled about why an "unset" config never compacts, so I added both:
#!/bin/bash
# Collect every setting that affects idle compaction, from the user, project and local levels plus the shell
echo "version: $(claude --version 2>/dev/null || echo 'claude not found')"
echo "shell env: DISABLE_AUTO_COMPACT=${DISABLE_AUTO_COMPACT:-unset}, CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS=${CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS:-unset}"
for f in "$HOME/.claude/settings.json" ".claude/settings.json" ".claude/settings.local.json"; do
[ -f "$f" ] || { echo "$f -> (missing)"; continue; }
# A missing key prints "unset", which means the default (true for both idleCompaction and autoCompactEnabled)
jq -r --arg f "$f" '"\($f) -> idleCompaction=\(if has("idleCompaction") then .idleCompaction else "unset" end), autoCompactEnabled=\(if has("autoCompactEnabled") then .autoCompactEnabled else "unset" end), min_tokens=\(.env.CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS // "unset"), DISABLE_AUTO_COMPACT=\(.env.DISABLE_AUTO_COMPACT // "unset")"' "$f"
doneRun it from the project root. Here is real output from Linux (bash 5.1, jq 1.6) against a sample folder with a different value at each level. Claude Code itself isn't installed on that machine, hence the version line:
version: claude not found
shell env: DISABLE_AUTO_COMPACT=unset, CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS=unset
/home/me/.claude/settings.json -> idleCompaction=unset, autoCompactEnabled=true, min_tokens=unset, DISABLE_AUTO_COMPACT=unset
.claude/settings.json -> idleCompaction=unset, autoCompactEnabled=unset, min_tokens=400000, DISABLE_AUTO_COMPACT=unset
.claude/settings.local.json -> idleCompaction=false, autoCompactEnabled=unset, min_tokens=unset, DISABLE_AUTO_COMPACT=unsetHere the local false sits at the highest level, so idle compaction never runs in this project, and the 400,000 threshold in the shared file has no effect. The script doesn't read managed settings or the --settings flag; if your organization deploys settings, check those as well.
Narrowing down the cause
When something feels forgotten, I walk this table from the top. Having a fixed order keeps me from poking at settings in a panic.
| Symptom | Likely cause | How to check | Fix |
|---|---|---|---|
| Right after returning, names and rejected options from before are gone | Idle compaction replaced the conversation with a summary | Look for a Compacted while idle notice (or its VS Code / desktop wording) | Move what you can't lose into CLAUDE.md; adjust the threshold or idleCompaction only if needed |
| You were gone briefly, yet context is missing | Ordinary auto-compaction near the limit, or a manual /compact | The notice isn't the idle one; check usage with /context | Keep the conversation smaller rather than touching idle settings |
| Long idle stretches, never compacted | A higher level sets false, or autoCompactEnabled is off, or DISABLE_AUTO_COMPACT=1 | Run the script above | Keep the value only at the level you intend |
No Idle compaction row in /config | Older than 2.1.302, or another settings source owns the key | claude --version; look for managed settings or --settings | Update, or change the key where it's set |
| Only your path-scoped rules stop applying after compaction | paths: rules and nested CLAUDE.md files are summarized away | Has Claude touched a matching file since the compaction? | Drop paths: or move the rule to the project-root CLAUDE.md |
Turn it off, move the threshold, or keep it and offload
You have three options, and each trades the weight of your first message back against how much detail you lose.
| Option | How | You gain | You pay | Good for |
|---|---|---|---|---|
| Turn it off | "idleCompaction": false, or the Idle compaction row in /config (2.1.302+) | Every detail stays | Your first message back reprocesses the whole conversation after the cache expires | Work where lost detail means redoing it |
| Move the threshold | CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS under env | Choose which conversations qualify by size | Raising it does nothing on a 200K window | 1M-context sessions you want kept up to a certain size |
| Keep it, offload the essentials | A work note in CLAUDE.md, or a SessionStart hook | The time and cost savings | A minute of effort before you step away | Most everyday work |
Moving the threshold looks like this — here, lowering it so 200K conversations qualify:
{
"env": {
"CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS": "150000"
}
}If I had to put my rule in one line: when in doubt, don't turn it off — move out only what you can't afford to lose. Switching it off entirely makes the first message after a break heavier the longer the conversation is.
I'll own a mistake here. The first version of this article suggested raising the threshold to 400,000 as the gentler alternative to switching it off. Rereading the docs later, I realized that on a 200K window the default threshold is never reached in the first place, so for many readers that setting did nothing at all. That one stung a little. Now I check which context window a conversation runs on before I write any setting for it.
Moving what you can't lose out of the conversation
Before touching settings, there's one more thing worth questioning: does the information you'd hate to lose exist anywhere other than the conversation?
I always move three kinds of things out:
- Options I rejected, and why (so the same idea isn't proposed again when I return)
- Files and directories that must not be touched
- Where the work stands — what's done and what's next
Option 1: a work note at the end of CLAUDE.md
The project-root CLAUDE.md is re-read after compaction, so anything there survives. Keep it apart from your permanent rules, in a small dated section, so it's easy to clear later:
## Work note (2026-10-20, delete when done)
- Rejected: regenerating every file on each build (diffs are enough)
- Do not touch: anything under scripts/legacy/
- Current state: log formatting is done; next is the retry cap on failureThe lowest-effort habit is to ask, right before stepping away, "write the current work note to the end of CLAUDE.md." I go deeper into what belongs in CLAUDE.md and at what granularity in designing CLAUDE.md.
Option 2: a separate notes file, read back after compaction
Sometimes CLAUDE.md is shared with a team and you'd rather not mix in personal notes. In that case, keep the note in something like .claude/work-notes.md and read it back with a SessionStart hook on the compact matcher. This is the "re-inject context after compaction" pattern from the official hooks guide, with a file read in place of a fixed string:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "cat \"$CLAUDE_PROJECT_DIR/.claude/work-notes.md\" 2>/dev/null || true"
}
]
}
]
}
}Put it in your personal .claude/settings.local.json and the team's settings stay untouched. The hook's stdout is added to the compacted context.
I want to be candid about one gap. The "What survives compaction" table describes compaction in general, and I haven't yet confirmed in my own setup that this hook fires after an idle compaction specifically. There's also the PreCompact hook, whose stdout becomes instructions for the summary (matchers manual and auto), but I haven't confirmed which matcher an idle compaction counts as. So for anything I truly need to keep, I still prefer Option 1 — the project-root CLAUDE.md. The broader hook design is covered in Claude Code hooks: design decisions.
What tends to trip you up next
After compaction, Claude Code re-reads up to five of the files Claude read or edited in the session, most recently modified first. Files over 5,000 tokens come back only as a path, shown as Referenced file. If you stepped away mid-edit on a large file, that's why you may need to say "read that file again" when you return.
Idle compaction is also tuned to the one-hour life of the prompt cache. If you want to design around caching more deliberately, see prompt cache TTL and directory-level decisions. Since 2.1.300, the OpenTelemetry api_request event lets you split cache writes by their 5-minute and 1-hour lifetimes.
If you do change the setting, I'd suggest running the same kind of work for a few days before and after, and jotting down two things: how long the first reply takes when you return, and how many assumptions went missing. I don't yet have enough of my own records to say that turning it off was worth it.
In place of a summary
Keep the assumptions you can't lose in a file, not in the conversation. I hold to that whether compaction is on or off that day.
For today, before you next step away, try writing just one work note into the project-root CLAUDE.md.