<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tahir Nazir</title>
    <description>The latest articles on DEV Community by Tahir Nazir (@its-tahir).</description>
    <link>https://dev.to/its-tahir</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2312639%2F0f7e5aaa-e4e6-4d54-b03c-8d1c3e14e77a.png</url>
      <title>DEV Community: Tahir Nazir</title>
      <link>https://dev.to/its-tahir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/its-tahir"/>
    <language>en</language>
    <item>
      <title>Claude Code 'Compacted While Idle'? How to Turn It Off (and When You Shouldn't)</title>
      <dc:creator>Tahir Nazir</dc:creator>
      <pubDate>Thu, 15 Oct 2026 08:53:10 +0000</pubDate>
      <link>https://dev.to/its-tahir/claude-code-compacted-while-idle-how-to-turn-it-off-and-when-you-shouldnt-58gf</link>
      <guid>https://dev.to/its-tahir/claude-code-compacted-while-idle-how-to-turn-it-off-and-when-you-shouldnt-58gf</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.its-tahir.com/blog/claude-code-compacted-while-idle" rel="noopener noreferrer"&gt;its-tahir.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To stop Claude Code's "Compacted while idle" summaries, add &lt;code&gt;"idleCompaction": false&lt;/code&gt; to your settings (version 2.1.290 or later).&lt;/strong&gt; It's a cost-saving feature, not a bug, and the details below include the exact conditions that trigger it — which I took from Claude Code's own code, because the official docs don't describe the feature yet.&lt;/p&gt;

&lt;p&gt;You left a long Claude Code session open over lunch. When you came back, this was waiting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Compacted while idle, before the prompt cache expired
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You never ran &lt;code&gt;/compact&lt;/code&gt;. You were nowhere near the context limit. But the exact instructions you'd given, the reasons behind decisions, and the approach you'd agreed on have been replaced by a summary.&lt;/p&gt;

&lt;p&gt;You're not imagining it. Anthropic switched the feature on from its side around version 2.1.286, with no release note and, until this week, no way to turn it off. The &lt;a href="https://github.com/anthropics/claude-code/issues/98747" rel="noopener noreferrer"&gt;GitHub issue&lt;/a&gt; about it describes one user returning to find &lt;strong&gt;seven of their twenty&lt;/strong&gt; open sessions compacted overnight.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Claude Code says "compacted while idle"
&lt;/h2&gt;

&lt;p&gt;It's about the &lt;strong&gt;prompt cache&lt;/strong&gt;. This section covers only the part idle compaction depends on; for how caching, context size and idle sessions add up to your overall usage, see &lt;a href="https://www.its-tahir.com/blog/why-claude-code-uses-so-many-tokens" rel="noopener noreferrer"&gt;why Claude Code uses so many tokens&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Every message you send carries your whole conversation with it. To keep that affordable, the API caches the conversation so it doesn't have to be reprocessed each turn. But the cache expires after a period of inactivity. Anthropic's caching docs explain that after a long enough gap, &lt;em&gt;"the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably"&lt;/em&gt; slower.&lt;/p&gt;

&lt;p&gt;On a Claude subscription, the main conversation gets a &lt;strong&gt;one-hour&lt;/strong&gt; cache. So if you have a 300,000-token session and walk away for 61 minutes, your first message back pays to reprocess all 300,000 tokens — against your plan's usage limits.&lt;/p&gt;

&lt;p&gt;Idle compaction gets ahead of that. Just &lt;strong&gt;before&lt;/strong&gt; the prompt cache expires, the conversation is summarised — that's what "compacted while idle" means. When you come back, you're paying for the short summary, not the full history.&lt;/p&gt;

&lt;p&gt;It's a real saving, and people asked for it. A &lt;a href="https://github.com/anthropics/claude-code/issues/66115" rel="noopener noreferrer"&gt;feature request from June&lt;/a&gt; wanted exactly this, and the community had already built add-ons to do it, such as &lt;a href="https://github.com/davidar/claude-idle-compact" rel="noopener noreferrer"&gt;claude-idle-compact&lt;/a&gt;. The complaint is that it arrived switched on, silently, for everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The exact rules, from the code
&lt;/h2&gt;

&lt;p&gt;There's nothing about this feature in Anthropic's docs or changelog yet, so I downloaded the Claude Code 2.1.290 package and read the code that decides when it runs.&lt;/p&gt;

&lt;p&gt;Idle compaction only fires when &lt;strong&gt;all&lt;/strong&gt; of these are true:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Condition&lt;/th&gt;
&lt;th&gt;Detail&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Anthropic has it switched on&lt;/td&gt;
&lt;td&gt;A server-side flag sets it to off, log-only, or compact&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto-compact is on&lt;/td&gt;
&lt;td&gt;Turning off &lt;code&gt;autoCompactEnabled&lt;/code&gt; also stops idle compaction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You haven't opted out&lt;/td&gt;
&lt;td&gt;The new &lt;code&gt;idleCompaction&lt;/code&gt; setting isn't &lt;code&gt;false&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The cache lasts &lt;strong&gt;one hour&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;It skips sessions on the five-minute cache&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The context is &lt;strong&gt;200,000 tokens or more&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;The default threshold — never lower than 100,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You've been away long enough&lt;/td&gt;
&lt;td&gt;It fires &lt;strong&gt;90%&lt;/strong&gt; of the way to the cache expiring, so about 54 minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nothing else is happening&lt;/td&gt;
&lt;td&gt;No turn running, no newer request, not near your rate limit, and the cache still warm&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things in that table answer the questions people ask most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Why does it only happen to some of my sessions?"&lt;/strong&gt; The 200,000-token threshold. Short sessions are never touched. An Anthropic collaborator confirmed in the issue thread that it currently applies &lt;em&gt;"only for larger contexts (200k+)"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Why don't I see it on my work API key?"&lt;/strong&gt; The one-hour rule. On an API key or a cloud provider, the main conversation defaults to the five-minute cache, so idle compaction doesn't run unless you've set &lt;code&gt;promptCacheTtl&lt;/code&gt; to &lt;code&gt;1h&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"I'm on 2.1.285 and still got it."&lt;/strong&gt; The idle-compaction code and its server switch are already in &lt;strong&gt;2.1.285&lt;/strong&gt; — I checked that package too. What changed around 2.1.286 was Anthropic switching it on. &lt;strong&gt;Downgrading isn't a reliable way out.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to turn it off
&lt;/h2&gt;

&lt;p&gt;On &lt;strong&gt;Claude Code 2.1.290 or later&lt;/strong&gt;, add this to &lt;code&gt;~/.claude/settings.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"idleCompaction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also works in a project's &lt;code&gt;.claude/settings.json&lt;/code&gt;, a local settings file, or managed settings — useful if you want it off for one long-running project but not others.&lt;/p&gt;

&lt;p&gt;The setting's own built-in description, from the code, is precise: &lt;em&gt;"Set to false to stop Claude Code from compacting a long conversation while the session is idle. Setting it to true does not turn idle compaction on."&lt;/em&gt; In other words, &lt;code&gt;false&lt;/code&gt; opts you out, but &lt;code&gt;true&lt;/code&gt; can't force it on — Anthropic's server switch still decides that.&lt;/p&gt;

&lt;p&gt;This leaves normal &lt;strong&gt;auto-compaction&lt;/strong&gt; alone. That's the one that kicks in when you're about to hit the context limit mid-task, and most people want to keep it. (If auto-compaction keeps firing and the context refills straight away, that's a different problem — &lt;a href="https://www.its-tahir.com/blog/why-claude-code-is-slow-hanging-or-eating-memory" rel="noopener noreferrer"&gt;what "Autocompact is thrashing" means&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't use the older workaround.&lt;/strong&gt; Before 2.1.290, the only way to stop idle compaction was to turn off auto-compaction entirely — &lt;code&gt;autoCompactEnabled: false&lt;/code&gt; or &lt;code&gt;DISABLE_AUTO_COMPACT=1&lt;/code&gt;. Both still work, but they also remove the safety net at the context limit. Now that there's a dedicated setting, there's no reason to pay that price.&lt;/p&gt;

&lt;h2&gt;
  
  
  Or: make it rarer instead
&lt;/h2&gt;

&lt;p&gt;If you like the cost saving but only want it for genuinely huge sessions, there's a second control. It isn't documented anywhere yet, but it's in the 2.1.290 code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;500000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That raises the threshold from 200,000 to 500,000 tokens, so mid-sized sessions are left alone while the biggest still get compacted. You can't go below 100,000 — the code raises any lower value to that floor.&lt;/p&gt;

&lt;p&gt;Treat it as you would any undocumented setting: it's useful today, but it could change or disappear in any release.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should leave it on
&lt;/h2&gt;

&lt;p&gt;It's worth saying plainly: for a lot of people, this feature is a good trade.&lt;/p&gt;

&lt;p&gt;If you open a session, work on one task, and walk away when it's done, nothing of value is lost. The summary keeps what Anthropic's docs list — &lt;em&gt;"your requests and intent, key technical concepts, files examined or modified with important code snippets, errors and how they were fixed, pending tasks, and current work."&lt;/em&gt; And you stop paying to re-send a huge, finished conversation every time you check back in.&lt;/p&gt;

&lt;p&gt;It hurts when the &lt;strong&gt;conversation itself is the work product&lt;/strong&gt;: long sessions where you've built up precise instructions, agreed conventions, or an orchestrator that coordinates subagents. That's who's been hit hardest in the issue thread. The summary keeps the gist and drops the exact wording — and for that kind of work, the exact wording is what matters.&lt;/p&gt;

&lt;p&gt;A rough rule: &lt;strong&gt;if you'd be annoyed to re-explain it, turn idle compaction off.&lt;/strong&gt; If you'd just start a fresh session anyway, leave it on and let it save you usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  If it already happened
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The verbatim conversation isn't in the session any more&lt;/strong&gt;, but it isn't gone. Claude Code saves the full transcript to disk under &lt;code&gt;~/.claude/projects/&lt;/code&gt;, one file per session. People in the issue thread rebuilt their context from those files. Open the transcript, find the instructions you'd given, and paste the important ones back in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protect standing instructions from now on.&lt;/strong&gt; Compaction replaces the conversation, but Anthropic's docs list what reloads automatically afterwards: the system prompt, &lt;strong&gt;CLAUDE.md&lt;/strong&gt;, memory and MCP tools, plus a re-read of up to five of the most recently modified files. Anything you'd hate to lose — conventions, project rules, "never touch this folder" — belongs in CLAUDE.md, not only in the chat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you use hooks&lt;/strong&gt;, one change landed alongside the setting. Idle compactions used to reach &lt;code&gt;PreCompact&lt;/code&gt; and &lt;code&gt;PostCompact&lt;/code&gt; hooks labelled &lt;code&gt;manual&lt;/code&gt;, as if you'd typed &lt;code&gt;/compact&lt;/code&gt; yourself. According to the Anthropic collaborator in the thread, from 2.1.290 they're labelled &lt;code&gt;auto&lt;/code&gt;. A hook still can't tell an idle compaction from one at the context limit, but at least it no longer looks like something you did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Want it off?&lt;/strong&gt; &lt;code&gt;"idleCompaction": false&lt;/code&gt; in settings, Claude Code 2.1.290 or later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Want it rarer?&lt;/strong&gt; &lt;code&gt;CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS&lt;/code&gt; above 200,000 (undocumented, minimum 100,000).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On an older version?&lt;/strong&gt; Update — downgrading won't help, and disabling auto-compact costs you the context-limit safety net.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lost context?&lt;/strong&gt; The full transcript is under &lt;code&gt;~/.claude/projects/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Want instructions to survive any compaction?&lt;/strong&gt; Put them in CLAUDE.md.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;'Compacted while idle, before the prompt cache expired' is a cost-saving feature: Claude Code summarises a long session just before its one-hour cache expires, so your next message doesn't reprocess the whole history.&lt;/li&gt;
&lt;li&gt;In the 2.1.290 code it needs a one-hour cache, at least 200,000 tokens of context and about 54 minutes of inactivity — and Anthropic's server-side switch decides whether it runs at all.&lt;/li&gt;
&lt;li&gt;"idleCompaction": false in settings.json (2.1.290+) turns it off while keeping normal auto-compaction at the context limit.&lt;/li&gt;
&lt;li&gt;The code is already in 2.1.285, so downgrading isn't a reliable fix; CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS can raise the threshold instead (undocumented, minimum 100,000).&lt;/li&gt;
&lt;li&gt;The full transcript survives on disk under ~/.claude/projects/, and anything in CLAUDE.md reloads after every compaction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For other Claude Code errors, from SSL failures to 529s, &lt;a href="https://www.its-tahir.com/blog/claude-code-troubleshooting" rel="noopener noreferrer"&gt;the full list of Claude Code errors and fixes&lt;/a&gt; groups them by cause.&lt;/p&gt;

&lt;p&gt;If you're wondering where the usage actually goes in a long session, &lt;a href="https://www.its-tahir.com/blog/why-claude-code-uses-so-many-tokens" rel="noopener noreferrer"&gt;why Claude Code uses so many tokens&lt;/a&gt; breaks it down. Building long-running agent workflows that keep their footing across compactions is part of the work I do — &lt;a href="https://www.its-tahir.com/work" rel="noopener noreferrer"&gt;see recent projects&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why does Claude Code say 'Compacted while idle, before the prompt cache expired'?
&lt;/h3&gt;

&lt;p&gt;Claude Code summarised a long conversation shortly before its one-hour prompt cache was due to expire, so your next message doesn't have to re-send the whole uncompacted context at full price. In the 2.1.290 code it only does this for sessions on a one-hour cache with at least 200,000 tokens of context, roughly 54 minutes after the last activity, and only when Anthropic has the feature switched on server-side.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I turn off idle compaction in Claude Code?
&lt;/h3&gt;

&lt;p&gt;Add "idleCompaction": false to a settings.json file — your user settings at ~/.claude/settings.json, or a project, local or managed settings file. It needs Claude Code 2.1.290 or later, and it leaves normal auto-compaction near the context limit switched on. Setting it to true does not force idle compaction on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I get my context back after an idle compaction?
&lt;/h3&gt;

&lt;p&gt;Not inside the session — the summary replaces the verbatim conversation. The full transcript is still saved on disk under ~/.claude/projects/, so you can re-read the exact instructions from there. To protect standing instructions in future, keep them in CLAUDE.md, which reloads automatically after every compaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does downgrading Claude Code stop idle compaction?
&lt;/h3&gt;

&lt;p&gt;Not reliably. The idle-compaction code and its server-side switch are already present in 2.1.285, before most people noticed the behaviour. Whether it runs is controlled from Anthropic's side, so the dependable way out is the idleCompaction setting in 2.1.290 or later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/anthropics/claude-code/issues/98747" rel="noopener noreferrer"&gt;Idle compaction silently discards working context; no opt-out (anthropics/claude-code #98747)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/anthropics/claude-code/issues/66115" rel="noopener noreferrer"&gt;Feature request: auto-compact on idle timeout to prevent cache expiry cost (anthropics/claude-code #66115)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.claude.com/docs/en/prompt-caching" rel="noopener noreferrer"&gt;Prompt caching: cache lifetime — Claude Code docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.claude.com/docs/en/context-window" rel="noopener noreferrer"&gt;Manage context — Claude Code docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.claude.com/docs/en/settings-reference" rel="noopener noreferrer"&gt;Settings reference — Claude Code docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/davidar/claude-idle-compact" rel="noopener noreferrer"&gt;claude-idle-compact — community mod (davidar)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.its-tahir.com/blog/claude-code-compacted-while-idle" rel="noopener noreferrer"&gt;its-tahir.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>troubleshooting</category>
      <category>costoptimization</category>
      <category>aiagents</category>
    </item>
  </channel>
</rss>
