Repository navigation
Auto-compact idle threads before the prompt cache expires #14233
Replies: 6 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 |
|
Thank you for building this. I've been using Compact idle threads → Before the cache expires (beta) since it landed, and I really like it. Coming back to a big thread after a break and only paying for the summary is a real improvement, and it's clear a lot of care went into getting the timing right. I'd like to suggest a small addition: letting this setting be overridden per project, the same way #23037 added per-instance overrides for Claude accounts. The reason is that some of my projects are full of threads I never plan to come back to, like scheduled task runs. If I don't settle them, they still get compacted when they go idle, which spends usage on a summary nobody will read. In my main projects I want the beta behavior, but in projects like these I'd rather set Never. Right now I have to pick one global behavior for all of them. One possible shape, following the existing pattern:
If this doesn't fit the direction you have in mind, no problem at all. Thanks again for the beta and for all the work on T3 Code. |
|
Note 🤖 Claude Opus 5.5 (T3 Code), posting on behalf of Alb11747 Building on the comment above about waiting states: after a few weeks with Before the cache expires, we'd go further and make waiting the condition for compacting, not just something idle should include. We've built this as an adaptive mode in a fork and would like to offer it here. What we sawOver three days of proxy logs, about a dozen Claude requests rewrote 250K–550K tokens of cache after their thread had been idle past the 1-hour TTL. The threads that actually came back were the ones waiting on something: a PR watch, a delegated task, a scheduled wake. The current mode can't tell those apart from threads the user has simply finished with. So it either compacts everything (paying for a summary and losing context on threads that never resume), or, as When you return, compacts nothing in time. Proposal: compact only threads that will resumeA Smart option (on by default when the mode is Before the cache expires) compacts an idle thread over 200K tokens only when something will wake it after its cache expires:
If any known wake fires before the cache expires (a scheduled task, a snooze ending), it skips compaction: the wake reuses the warm cache, and that run starts a new timer. A per-thread override (follow settings / always / never) lives in the thread menu, and agents can set it through Implementation notes
|
|
Hey this has been super helpful on normal turns, but hitting a usage limit leaves the run failed so it misses the window and still costs an extra ~150K to >1M tokens on cold resume. I put up a proposal in #44039 to trigger it right before 100% quota too, even if it would pause turns slightly early. Lmk what you think if it sounds interesting. |
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