The Hidden Cost of Claude's 20-Block Lookback

When building agentic AI systems with Claude, developers often overlook a critical limitation that can dramatically increase inference costs: the 20-block lookback window for prompt caching. This isn't a minor detail; it's the single most expensive aspect of Claude prompt caching that frequently gets omitted from post-mortems and retrospectives. The issue arises when an agent's sequence of tool calls generates more than 20 content blocks within a single turn. When this threshold is breached, Claude's caching mechanism fails to find a relevant cache entry, forcing a full rewrite of the prompt prefix at a significantly higher cost.

Consider a typical agent loop. It might start with a substantial context window, say 40,000 tokens, with `cache_read_input_tokens` reflecting this. After executing several tool calls, the agent might emit 22 or more content blocks. This exceeds the 20-block limit for the `cache_control` breakpoint. Consequently, the next request from the agent, even if the prompt's core content hasn't changed, will find zero cache hits. The system then resorts to `cache_creation_input_tokens`, which writes the entire conversation prefix again, but at a performance penalty – effectively re-processing content that should have been cached. This happens turn after turn, inflating costs without any apparent change in the prompt itself.

Diagram illustrating Claude's 20-block lookback window and agent tool call block generation

Understanding the Mechanism

Claude's prompt caching is designed to accelerate responses by reusing previously processed parts of a conversation. It operates by looking back through content blocks to find a match. However, this search is capped at a maximum of 20 content blocks. A content block can be a tool output, a user message, or a model response. When an agent makes multiple parallel tool calls, each tool's output can constitute a new content block. If an agent executes, for instance, 11 parallel tool calls, this alone can easily generate 22 or more content blocks within a single turn. This immediately blows past the 20-block limit.

The consequence is straightforward: the caching mechanism cannot find a prior state within its lookback window. It then treats the current request as entirely new, leading to the inefficient process of rewriting the entire prefix. This rewrite doesn't just add latency; it incurs direct financial cost, as models are billed per token processed. When this happens repeatedly across many turns in an agent's workflow, the cumulative cost can be substantial and often goes unnoticed because the prompt *appears* unchanged to the developer.

The Solution: Rolling Breakpoints

The effective solution to this costly limitation is to strategically place rolling breakpoints. Instead of placing a single marker on the very last content block, developers should implement breakpoints at intervals of approximately 15 content blocks. This ensures that even with multiple tool calls, the agent's output remains within the 20-block lookback window for subsequent cache lookups.

Claude allows for a total of four breakpoints per request. By distributing these four breakpoints at roughly 15-block intervals, you create multiple opportunities for the caching mechanism to find a relevant entry. For example, if your agent generates 30 blocks, breakpoints at blocks 15 and 30 would ensure that subsequent requests looking for cache entries around block 30 can find a match at block 15. This proactive management of breakpoints prevents the system from repeatedly reprocessing the entire prompt prefix. It transforms the caching from an all-or-nothing failure into a consistently effective performance and cost-saving tool.

Implications for Agent Development

For developers building complex agentic workflows on Claude, this understanding is critical. Architectures that rely on long sequences of tool calls without considering this caching limitation will face unexpectedly high inference costs and performance degradation. The key takeaway is that agent design must now account for the physical constraints of the underlying LLM's caching mechanisms. This isn't just about prompt engineering; it's about system architecture. Developers need to actively manage the number of content blocks generated per turn or implement a strategy for rolling breakpoints. Failure to do so means paying a premium for every