Claude Prompt Caching Fails in Agent Loops Due to 20-Block Lookback Limit
Anthropic's Claude API caches prompts using a prefix-match system, but cache lookups only scan backward through a maximum of 20 content blocks to find a valid entry. In agentic workflows, a single round trip with parallel tool calls can append 18 or more blocks, meaning just two such turns push a trailing cache breakpoint beyond the 20-block window and silently invalidate the cache. When this happens, the API treats the request as entirely uncached and charges full cache-creation costs — up to 12 times more expensive than a cache read on Claude Opus 5. Developers can avoid this by placing rolling cache breakpoints every 15 blocks across the message list rather than a single marker at the end, using all four available breakpoints per request strategically. Monitoring tools that only track input_tokens will miss the problem entirely, as cached token counts are reported separately in the API usage block.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in