Detailed Analysis
A detailed, data-driven Reddit analysis has surfaced a subtle but costly inefficiency in how Claude Code handles prompt caching for subagents, one that the author frames not as a user-configurable setting but as an architectural issue for Anthropic to address. By parsing roughly two weeks of personal usage logs — spanning 95 sessions, 1,800 subagents, and 6.8 billion input tokens — the user found that subagent-related prompt costs run about 14% higher than they should, translating to an 8% overspend across total API usage. Critically, the claim isn't that Claude Code processes more tokens than necessary; it's that identical context is repeatedly billed at the more expensive cache-write rate instead of the cheaper cache-read rate, due to how the caching system's time-to-live (TTL) windows interact with subagent lifecycles.
The analysis identifies two distinct mechanical causes. First, every subagent cold-starts by resending roughly 30-37k tokens of largely static boilerplate — system prompts, tool definitions, project rules — of which only about 3% is unique to the actual task. This static block should be highly cacheable across same-type subagents, but two structural quirks prevent it: the shared prefix only persists in cache for five minutes (so subagents spawned more than five minutes apart find the cache already expired), and volatile per-invocation data like timestamps or git branch info is placed early in the prompt, which invalidates the cacheable prefix that follows it, since prompt caching requires an unchanged prefix to be reused. Second, when a parent agent spawns a child and waits more than five minutes for it to return, the parent's own cache — which also runs on a 5-minute TTL rather than the main session's 1-hour TTL — silently expires, forcing a costly full re-write of context when control returns to the parent.
Notably, the analysis pushes back against the obvious fix. Simply extending subagents to the 1-hour cache TTL used by main sessions actually makes costs 8.6% worse, because 98% of cache reuse happens within about 34 seconds, meaning longer retention windows mostly just force users to pay the premium write rate on content that would have expired naturally anyway. A blanket "split cache by volatility" approach also proves to be a wash. Instead, the proposed solution is granular: apply a 1-hour TTL specifically to the cache write that occurs right before a child subagent is dispatched (preserving the parent's context during the wait), apply a 1-hour TTL to the identical per-type static prefix while reordering the prompt so dynamic content comes after it (enabling genuine sharing across subagent instances), and leave the fast-churning conversational tail on the default 5-minute TTL, since re-reading it within seconds makes longer retention pointless there. Combined, these targeted changes are modeled to cut subagent costs by roughly 13.6% and slash cold-start costs by about 88%, using caching primitives — mixed 1-hour and 5-minute breakpoints within a single request — that are already part of Anthropic's generally available prompt-caching API.
This finding matters because it illustrates how caching architecture, not raw model capability, increasingly determines the real-world economics of agentic AI systems. As Claude Code and similar tools lean more heavily on multi-agent orchestration — parent agents dispatching specialized subagents for code review, testing, or research — the overhead of repeatedly re-establishing context becomes a first-order cost driver rather than a rounding error. The author's methodology is also notable: rather than relying on vendor-disclosed benchmarks, they built an open, stdlib-only script that developers can run locally against their own Claude Code transcripts to independently verify the same overpayment pattern, reflecting a broader trend of the developer community auditing AI infrastructure providers' billing and performance claims directly. Because the fix requires no new API capability — just different TTL assignment and prompt reordering on Anthropic's end — this is positioned as a straightforward, low-risk optimization that could meaningfully reduce costs for any team running subagent-heavy Claude Code workflows, underscoring how caching strategy is becoming as consequential to AI product economics as the underlying model pricing itself.
Read original article →