[FEATURE] Keep the main thread's prompt cache warm while it waits for background agents

Status Open
Reported on v2.1.283
Maintainer reply None cached
Activity 1 comment · opened Sep 28, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

When the main thread starts background agents and ends its turn, it makes no API requests until a task notification arrives. Its prompt cache uses the 1-hour TTL (every main-thread cache write in my sessions is ephemeral_1h), and only a read refreshes it. If a single background agent runs longer than an hour and nothing else finishes, the next wake-up rewrites the whole main context.

In one orchestration session (Claude Code 2.1.283, Opus 5.5, context about 900k tokens), the main thread slept 42 and 44 minutes between notifications. Both wake-ups still read from cache (about 900k read, 3k written), with roughly 16 minutes to spare. Across my sessions, 24 of 105 subagents ran longer than 55 minutes. At API prices, rewriting 900k tokens with the 1-hour TTL costs about $7.20, versus about $0.18 to read them.

Proposed Solution

While the main thread is idle and background tasks are running, send a cache-only request before the entry expires, for example 50 minutes after the start of the last main-thread request. This is the previous request resent with max_tokens: 0 and without streaming, which the prompt caching docs describe for refreshing an entry without generating output. It adds nothing to the transcript and doesn't change what the main thread does next.

Alternative Solutions

  • A longer TTL for the main thread. The API offers only 5-minute and 1-hour TTLs, so this would need a longer tier on the API side.
  • Waking the main thread with a status prompt, which a client could do. It refreshes the cache too, but adds a turn to the conversation.

Priority

Medium - Would be very helpful

Feature Category

API and model interactions

Use Case Example

  1. The main thread starts one long review agent and ends its turn.
  2. The agent runs for 70 minutes, and nothing else finishes meanwhile.
  3. At about minute 50, Claude Code sends the cache-only request.
  4. When the agent finishes, the main thread resumes from a warm cache instead of rewriting 900k tokens.

Additional Context

Related: #87106 (subagents cache for only 5 minutes, so a subagent's context is rewritten after a long tool call or when it is continued).

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗