Checked · 2026-10-19 · Claude Code 2.1.299 idle compaction

Claude Code idle compaction: trigger conditions, threshold and how to turn it off

To turn off idle compaction, put "idleCompaction": false in settings.json (the key needs 2.1.290 or later), or use the Idle compaction row in /config. Idle compaction arrived in Claude Code 2.1.299 (published 2026-10-14) as default behaviour: a conversation whose context has reached the token threshold (200,000 by default) and that is left idle for about 54 minutes with the computer awake is compacted shortly before its prompt cache expires; coming back, the conversation shows `Compacted while idle, before the prompt cache expired`, and your next message sends a summary instead of the whole conversation. As of 2026-10-19, the latest on npm is 2.1.303 (published 2026-10-18).

Updated 2026-10-19

One key for Claude, GPT and leading Chinese models, billed per token, up and running in minutes.

#default behaviour#idle test#token threshold#one line to disable

Trigger conditions, threshold and how to turn it off

when it applies

Default behaviour since 2.1.299

The docs state that idle compaction is on by default for conversations that meet the conditions. The switch is `idleCompaction` in settings.json, default true, scope Any file.

idle test

How long the session must be idle

The idle test is that about 54 minutes have passed since the last request and your computer is awake at that point; the context must have reached the token threshold, default 200,000, changeable with the environment variable `CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS`, and values below 100000 are raised to 100000.

The preconditions

The preconditions the docs list

The preconditions are an interactive terminal session, the conversation running on the one-hour prompt cache lifetime, Claude Code being able to fetch feature flags, the context having reached the threshold, and the machine being awake after a long idle spell.

turning it off

The ways the docs give

Set "idleCompaction": false in settings.json (2.1.290 or later); on an earlier version set autoCompactEnabled: false; the environment variable `DISABLE_AUTO_COMPACT=1` turns idle compaction off along with auto-compaction, and the manual /compact stays available. Since 2.1.302 there is also an Idle compaction row in /config.

What idle compaction actually does

It turns a conversation you walked away from into a summary, and the old cache prefix is no longer reused. The docs state that idle compaction happens shortly before the prompt cache expires and that your next message then sends a summary instead of the whole conversation. Another note in the same documentation says that compaction builds a new cache prefix, while /rewind truncates back to a prefix that is already cached. Cache writes and cache reads are accounted for separately, each at its own rate; the difference between the cache write rates of the different lifetimes is on the /prompt-caching-cost-2026 page.

Official changelog and docs as of 2026-10-19

Checked on 2026-10-19 against the Claude Code changelog, the settings reference and the environment variables page: 2.1.299 (published 2026-10-14) added idle compaction in the terminal together with `CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS` for moving the threshold; 2.1.302 (published 2026-10-16) added an Idle compaction row to /config, and the notice after an idle compaction now says how to turn it off; the latest on npm is 2.1.303 (published 2026-10-18).

The releases and the dates

2026-10-14

Claude Code 2.1.299 is published, and the changelog records the arrival of idle compaction in the terminal: from this release on, a conversation that meets the conditions is compacted automatically.

2026-10-16

Claude Code 2.1.302 is published, and the changelog records an Idle compaction row in /config, with the notice after an idle compaction saying how to turn it off.

2026-10-19

As of 2026-10-19 the latest on npm is 2.1.303 (published 2026-10-18), and the switch and the trigger conditions in the settings reference have not changed.

What the docs state and what they leave open

Confirmed (word for word in the official pages)

① Idle compaction is on by default for conversations that meet the conditions; ② about 54 minutes have passed since the last request, and your computer is awake at that point; ③ the context has reached the token threshold, default 200,000; ④ values below 100000 are raised to 100000; ⑤ an earlier version ignores the key, and the docs tell you to turn off autoCompactEnabled instead; ⑥ a notice in the conversation says the compaction happened before the cache expired; ⑦ compaction builds a new cache prefix, while /rewind truncates back to a prefix that is already cached; ⑧ the prompt cache has a five-minute and a one-hour lifetime, and cache writes cost more with the one-hour lifetime

What the docs leave open

The docs do not say how idle compaction affects the exact cache charges, whether the idle test will change with the version, or which of idle compaction and auto-compaction happens first when both apply: the settings reference gives the switch and the conditions for each, but no order.

Keep the default or turn it off

Keep the default

The default is exactly that: a conversation that meets the conditions is compacted, a notice in the conversation says the compaction happened before the cache expired, and the next message sends a summary. The threshold can be moved with `CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS`. The conditions themselves depend on the cache lifetime: the official TTL table lists five minutes for the main conversation in the usage credits, API key, or cloud provider column, so the one-hour condition does not hold there (for a one-hour main conversation cache you set promptCacheTtl to 1h yourself).

Turn it off

The four ways are listed above: the switch in settings.json, autoCompactEnabled on an earlier version, the environment variable that switches off auto-compaction as well, and the switch row in /config. With it off, the conversation stays until you run /compact yourself or the context nears the limit.

The order to check idle compaction in

① Check the version: the "idleCompaction" key is only read from 2.1.290 on. ② Confirm it is this: the notice in the conversation that says the compaction happened before the cache expired is the mark of idle compaction, while a manual /compact is a different thing. ③ Check the conditions: interactive terminal session, one-hour cache lifetime, context at the threshold, and an awake machine after a long idle spell — all of them have to hold. ④ To turn it off: the idle compaction switch in settings.json, or the Idle compaction row in /config. ⑤ To move the threshold: `CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS` takes a positive whole number, and values below 100000 are raised to 100000.

Connecting Claude Code with a QCode key

As the QCode environment variables page has it: ANTHROPIC_BASE_URL filled in up to the /api prefix (https://api.qcode.cc/api), the key in ANTHROPIC_AUTH_TOKEN (it starts with cr_ and Claude Code sends it as a Bearer token), and tools that only accept ANTHROPIC_API_KEY can use the same key. QCode.cc is prepaid: you top up a balance, then buy a plan or a pack, and the purchase is paid from that balance; 5 concurrent requests, the same models as personal plans; billed per token, per-model rates are listed on /models. Not ready for a monthly plan? Pay-as-you-go Packs start at $4 for a one-time quota you use within 7 to 90 days.

Frequently asked questions

Which version added idle compaction?

2.1.299. The official changelog records the arrival of idle compaction in the terminal in that release, together with `CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS` for moving the threshold. On npm the stable dist-tag still points at 2.1.292, so an install through the stable channel may not have this behaviour yet; the latest is 2.1.303 (published 2026-10-18).

Why is part of the context gone when I come back?

Most likely idle compaction: the docs say your next message then sends a summary instead of the whole conversation. The preconditions are an interactive terminal session, the context at the threshold, and an awake machine after a long idle spell. A manual /compact swaps the conversation for a summary too.

How do I turn it off?

Put "idleCompaction": false in settings.json to switch it off; on an earlier version set autoCompactEnabled: false. The environment variable `DISABLE_AUTO_COMPACT=1` switches idle compaction off together with the auto-compaction that kicks in near the limit, and the manual /compact stays available.

Does it change what I pay?

It changes how the cache is written and read: the docs say compaction builds a new cache prefix, while /rewind truncates back to a prefix that is already cached; the prompt cache is accounted separately as cache_creation_input_tokens and cache_read_input_tokens, the former billed at the cache write rate and the latter at the cache read rate. Per-model cache prices are on the /prompt-caching-cost-2026 page.

Why does idle compaction not trigger when I connect with an API key?

The official TTL table lists five minutes for the main conversation under usage credits, API key, or cloud provider, while one of the conditions for idle compaction is that the conversation runs on the one-hour prompt cache lifetime — so with an API key that condition usually does not hold. For a one-hour main conversation cache the docs ask you to set promptCacheTtl to 1h yourself (needs 2.1.242 or later).

What did the official side change most recently?

There is now an Idle compaction row in /config, so idle compaction can be switched off and back on at any time, and the changelog says the notice after an idle compaction now tells you how to switch it off. The rest of the mechanism is unchanged: the threshold, the idle test and the cache lifetime are still the conditions the docs list.

Sources

Official sources: the Claude Code changelog (raw.githubusercontent.com/anthropics/claude-code/main/CHANGELOG.md, fetched and checked 2026-10-19), the official settings reference, environment variables page and prompt caching page (code.claude.com/docs/en, fetched and checked 2026-10-19), and the @anthropic-ai/claude-code release records on npm (registry.npmjs.org, fetched and checked 2026-10-19: 2.1.299 published 2026-10-14). On the QCode side: the Environment variables and Endpoints and API formats pages on docs.qcode.cc (fetched and checked 2026-10-19), and the pay-as-you-go page on qcode.cc in five languages (fetched and checked 2026-10-19).

Run Claude Code on a pack

Not ready for a monthly plan? Pay-as-you-go Packs start at $4 for a one-time quota you use within 7 to 90 days.

Not sure where to start?

Try it for a week

Week Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $8.57/month, about half the price per $1 of quota compared with the Month Pack ($5 of quota per day)