High quota consumption (~30% to 40%) on first request after limit reset due to expired prompt cache + compaction deadlock
Bug Description
When using claude-code, hitting the rate limit on the Pro subscription and choosing to pause ("stop and wait"), the first interaction after the quota resets immediately consumes ~30% to 40% of the newly allocated limit.
This happens due to a combination of technical factors, including a deadlock in the compaction logic:
- Prompt Cache Expiry (Cold Start Penalty): During the long waiting period, the remote prompt cache on the servers naturally expires due to its relatively short time-to-live. When the quota resets and the user sends even a trivial message to resume, claude-code is forced to re-submit the entire large uncompressed context window accumulated during the previous session as a completely "cold" uncached request. This immediately drains a massive portion of the newly restored quota.
- The Compaction Deadlock Bug (as seen in logs): The CLI attempts to run context compaction automatically when limits are tight, but it fails with: 'Error during compaction: You've hit your session limit...'
This creates a deadlock: the tool cannot compact the history because the API is already blocked by the rate limit. Then, when the limit finally resets, the tool has to cold-start with a massive, uncompacted history, destroying a large chunk of the new quota instantly.
Suggested Optimizations / Feature Requests
To make the pricing structure and token usage reasonable for long-running terminal sessions, please consider implementing:
- Local Session Caching & Offline Compaction (Highly Recommended): Since the remote KV-cache on the GPU expires during the 5-hour wait, the user's local disk should be used to manage the session state. Allow claude-code to keep a comprehensive local cache of the session history, files, and diffs. During the rate-limit wait period, the CLI should perform offline local compaction and state optimization on the user's machine. When the limit resets, the tool can submit a pre-compacted, highly optimized local state rather than re-uploading the raw, bloated history.
- Pre-emptive / Local Compaction: Run the compaction logic before hitting 100% of the rate limit (e.g., trigger it automatically when the session usage is nearing the limit), so that the saved state is small before the API blocks further calls.
- Cold-Start Warning / Prompt: If the remote cache has expired during a long pause, have the CLI prompt the user before sending the first request:
"Your remote prompt cache has expired. Re-submitting the active context will consume a significant portion of your new limit. Would you like to: [1] Compact history locally, [2] Clear session, [3] Proceed?"
- Local offline caching analysis: Allow local tracking of context size to warn the user of ballooning history before they hit the hard remote limit.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.1.178
- Feedback ID: 730298ee-21c1-48e2-88e4-eaf3de32981e
Errors
[{"error":"Error: Error during compaction: You've hit your session limit · resets 11:20am (Asia/Bangkok)\n at qUL (/$bunfs/root/src/entrypoints/cli.js:7353:1646)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-06-17T02:25:08.665Z"}]This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗