October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Why Claude Cache Hits Disappear in Long Agent Loops

Claude checks back at most 20 block positions per breakpoint—and only for entries previously written. Stable-prefix placement and timely intermediate breakpoints help long agent loops keep cache hits in reach.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Claude prompt caching can miss in a long agent loop even when much of the prompt is unchanged: each cache breakpoint searches backward through at most 20 block positions for a matching entry that an earlier request actually wrote. If the loop grows beyond that reach, or the breakpoint includes changing content, the stable prefix may not be reused. Put the breakpoint at the end of the stable prefix and add an intermediate breakpoint before a long turn can push the previous write out of range.

How Claude’s 20-position lookback works

Claude caches a cumulative prompt prefix: tool definitions, system content and messages up to a block marked with cache_control. That breakpoint writes a cache entry for the prefix ending there. On a later request, Claude checks backward from the current breakpoint for a matching entry previously written by an earlier request. Anthropic’s documentation describes the limit this way: “The lookback window is 20 blocks.” The current breakpoint counts as one of those positions, leaving 19 earlier positions to check. Anthropic’s prompt caching documentation.

As an Amazon Associate I earn from qualifying purchases.

“Block” here refers to a position in the API’s prompt structure, not necessarily an individual tool call. On the Claude API, a consecutive run of tool_use blocks counts as one position, and a consecutive run of tool_result blocks also counts as one. Do not assume the same counting behavior on other platforms without checking their documentation. Anthropic’s prompt caching documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The boundary in Anthropic’s example

Anthropic illustrates the limit with a cache write at block 15 and a later breakpoint at block 35. From block 35, the lookup checks blocks 35 back through 16; block 15 is just outside the window and cannot be found. A nearer breakpoint can establish another entry within reach. This is a deterministic example of the documented rule, not a performance benchmark. Anthropic’s prompt caching documentation.

Why a long agent loop can lose a cache hit

Agent turns may add many messages and tool-related blocks between requests. If that growth leaves the next breakpoint at least 20 positions beyond the previous write, the bounded search cannot reach that entry. An unchanged prefix is not enough: the entry must have been written earlier and remain inside the current breakpoint’s lookback window.

There is another common cause: placing the breakpoint after content that changes every request. A cache entry represents the entire prefix through the breakpoint, so a changing timestamp or user message changes the prefix. Searching backward does not automatically write an entry for the stable blocks before it. Anthropic advises placing the breakpoint at the end of the last stable block intended for reuse. Anthropic’s prompt caching documentation.

Automatic caching does not bypass the window. It places a breakpoint on the last cacheable block and follows the same lookback rule. If that block varies between requests, explicit placement at the stable-prefix boundary may be needed. Anthropic’s prompt caching documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to keep caching working as the loop grows

  1. Put stable content first. Arrange relatively static tool definitions, system instructions, shared context and examples before the changing per-request suffix.
  2. Mark the stable boundary. Put cache_control on the last block whose full preceding prefix is identical across the requests you expect to share a cache. Avoid putting it after a timestamp or incoming message that changes on each request.
  3. Estimate growth between writes. Count the positions likely to accumulate during a long agent turn. If the next breakpoint may end up 20 or more positions beyond the last write, establish a nearer breakpoint before that growth occurs.
  4. Use multiple breakpoints when needed. They can serve prompt sections that change at different rates or keep a growing conversation from leaving the earlier write unreachable. Anthropic documents a maximum of four breakpoints. The number of breakpoints does not itself create a separate fee; costs follow the cached content and cache operations. Anthropic’s prompt caching documentation.
  5. Check response usage. Inspect cache-read and cache-write usage in API responses to tell whether a request read a prior entry or wrote one. A stable-looking prefix alone does not establish that a cache hit occurred.

One breakpoint or several?

Prompt or loop pattern Practical approach
Stable prompt prefix followed by a short, changing suffix Place a breakpoint at the end of the stable prefix; a single breakpoint may be sufficient if the write stays within lookback reach.
Long turns add many positions before the next request Add a nearer intermediate breakpoint early enough to be written before growth pushes the earlier entry out of reach.
Prompt sections change at different rates Consider separate breakpoints at stable boundaries, staying within Anthropic’s documented maximum of four.
Last cacheable block changes on every request Use explicit breakpoint placement at the end of the stable prefix rather than relying on automatic placement there.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Cache lifetime, cost and platform qualifications

Anthropic’s documentation describes a five-minute default cache lifetime and an optional one-hour duration at additional cost. Its standard rate examples list five-minute cache writes at 25% above base input price and cache reads at 10% of base input price. These are relative rates, not fixed dollar prices; check the current pricing schedule for the specific model and platform before estimating costs. Anthropic’s prompt caching documentation.

Feature availability can differ by platform. Anthropic’s documentation says the legacy Amazon Bedrock integration for Opus 4.6 and earlier does not support top-level automatic caching, so that integration requires explicit cache breakpoints. Confirm current model and platform support in the relevant feature documentation before relying on automatic caching. Anthropic’s prompt caching documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.