← All posts

Compact on idle or at a threshold: how Claude Code and Codex decide when to forget

We run Claude Code and Codex side by side on long sessions, and both eventually summarize their own history to make room. They now disagree about when to do it. Claude Code compacts on a clock: a big conversation you've left alone is summarized just before its prompt cache expires. Codex compacts on pressure: when the context nears the end of the window, or, if you turn it on, at the end of a turn once it passes a percentage you set.

A correction to the shorthand we started with: Codex does not compact at 70% by default. Seventy is the example value people give for an opt-in setting, model_post_turn_compact_threshold_percent. Left alone, Codex compacts at about 90% of the window.

Most of what follows comes from people reading the shipped code, not from vendor documentation, and both tools change weekly. Check your version before you rely on a number.

Claude Code: compact while you're away

Idle compaction arrived around Claude Code 2.1.290, in October 2026, separate from ordinary auto-compact. It fires when all of these hold:

  • the session is interactive in a terminal, not claude -p or the Agent SDK;
  • the conversation is on the one-hour prompt cache;
  • the context holds at least 200,000 tokens (CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS, which can't go below 100,000);
  • about 54 minutes have passed since the last request, a few minutes before the cache entry expires.

When you come back, the transcript says "Compacted while idle, before the prompt cache expired", and the agent carries on from a summary.

The reason is cache pricing. While the cache is warm, reading a 200K-token history back costs about a tenth of the normal input price. Once it expires, the next message writes the whole history to the cache again, and a one-hour cache write costs twice the normal price. Resuming cold costs roughly twenty times as much as compacting warm, before counting the tokens the summary itself takes to write. On a subscription the cost is quota rather than dollars, and Anthropic doesn't say how quota counts cache reads against writes.

Ordinary auto-compact still fires near the end of the window: at about 967K tokens on models with a 1M window, and at 200K on older models. On a 200K window, auto-compact usually runs before idle compaction can qualify, so in practice idle compaction is a feature of long sessions on 1M-window models.

You want to Setting
Turn off idle compaction only "idleCompaction": false in settings.json, or its row in /config
Raise the size it waits for CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS
Turn off automatic compaction DISABLE_AUTO_COMPACT=1 or "autoCompactEnabled": false
Turn off all compaction, /compact too DISABLE_COMPACT=1
Compact earlier while working autoCompactWindow in tokens, or CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (lowers only)

The feature began as a request to save money. Once it shipped on by default, the same thread filled with people who had lost long, detailed threads to a summary they never saw written; one called it "actively destructive to have this on by default". Another commenter estimated it saved about 0.5% of a week's usage.

Codex: compact when the context fills

Codex triggers on size:

  • Default: 90% of the context window, so 244,800 tokens on a 272K model.
  • Lowering it: model_auto_compact_token_limit can only bring the trigger earlier. To compact later, raise model_context_window.
  • Hard cap: at 95% Codex compacts regardless of settings. Nothing turns auto-compaction off.
  • Where it lands: before your next message, or in the middle of a turn when a tool result pushes the context over the limit.
  • At the end of a turn: model_post_turn_compact_threshold_percent, off by default, compacts after a finished reply once the context passes that percentage.

How it compacts differs too. On OpenAI's own models compaction runs on the server and returns an encrypted item: you can't read what was kept. Other providers get a readable summary written locally, which keeps your messages word for word and replaces the agent's replies and tool output. Codex's /compact takes no instructions; you can replace its prompt with compact_prompt.

Side by side

Claude Code, idle Codex
Fires ~54 min idle, 200K+ tokens, one-hour cache ~90% of the window, 95% always; optionally after a turn
Saves you The cost of resuming after the cache expires Running out of room
Lands While nobody is working At the limit, possibly mid-turn
Summary Readable Encrypted on OpenAI models, readable elsewhere
Off switch idleCompaction: false None; you can only move it earlier
Goes wrong when You come back to a summary you didn't see written It cuts into a multi-file change and drops the instruction it was following

Where compaction lands matters most

Claude Code's trigger answers when compaction is cheapest. Codex's answers when it can't be put off. Whether a long session survives depends on a third question: where in the work the summary falls.

The worst place is halfway through a change across several files, with the plan held only in context. Codex's default can land there, and its issue tracker has reports of summaries written mid-task that dropped the instruction being carried out. Idle compaction never lands there, because nobody is working. That, more than the money, is what it gets right. What it gets wrong is surprise: it fires on the sessions you kept open because their detail mattered, and you find out afterwards.

Codex's end-of-turn setting sits between the two. It compacts at a natural break, while you're there to see it, and 70% leaves room for the next turn's tool output. The price is more compactions over a long session, and each one loses something; OpenAI warns that repeated compactions make the model less accurate.

What we set

  • Claude Code, sessions we come back to (design threads, long debugging): "idleCompaction": false, and /compact focus on <what matters> ourselves before stepping away. A summary we steered beats one written while we were gone.
  • Claude Code, short or mechanical sessions: idle compaction on. The saving is real and there's little to lose.
  • Codex, long agent runs: model_post_turn_compact_threshold_percent around 70 to 80, so compaction falls between turns rather than inside a tool call. It goes at the top level of config.toml; some versions ignore compaction settings inside a profile.
  • Both: anything that has to survive goes in a file the agent reads again after compacting, CLAUDE.md or AGENTS.md, or in a Cydonia article or card, not only in the conversation.

Sources