Repository navigation
Auto-compact idle threads before the prompt cache expires #14233
Replies: 3 comments
This comment was marked as spam.
This comment was marked as spam.
|
+1, and one finding that makes this T3's job rather than Claude Code's: Claude Code 2.1.286+ now does this natively ("Compacted while idle, before the prompt cache expired"): at ~90 % of the 1 h TTL (~54 min idle), context ≥ 200k (
So it has to be a server-side sweep in T3, and most pieces already exist (commit
Rough size: 250–400 LOC across 6–8 files including tests. Open risk worth measuring first: the process is gone by then, so the compaction runs on a resumed process. It only hits the warm cache if the resumed request prefix (system prompt, tools, MCP servers) is byte-identical to the pre-idle one. If it isn't, this pays the cold read anyway. Keeping Claude processes alive past ~55 min would sidestep that at the cost of memory. Since Claude Code users pushed back on silent idle compaction (anthropics/claude-code#98747), keeping it opt-in with a visible "auto-compacted after N min idle" marker, as proposed above, seems right. |
|
"idle" should include "waiting" states (waiting on PR watch, waiting on background shell, waiting on subagents)...any state where the agent thread itself is doing nothing even if subagents or shells are running since they all pay the cache hit price when the background task eventually notifies. Extra points if the compact request can pass along instructions to remember the list of background tasks/waits/watches it has active |
Uh oh!
There was an error while loading. Please reload this page.
Problem
When I step away from a large thread, its prompt cache expires. The cache lasts 60 minutes on a Claude subscription and 5 minutes on an API key or in overage. After that, my next message re-reads the whole context at the uncached rate, and so does compacting it. The "Resume with less context" banner only shows up after 70 idle minutes, so by the time it appears the cache has already expired and compacting is the expensive option.
Proposal
Add an opt-in setting that compacts a thread automatically after a period of inactivity, timed to happen while the cache is still warm.
compactThread.Why
The measurements in #13988 show the gap. Compacting a ~210K-token thread cost about $0.10 while the cache was warm and about $0.90 once it was cold. Continuing the cold thread without compacting cost $1.67 for the first message. For subscription users, that difference counts directly against usage limits.
Related
All reactions