ByteCosts
prompt-caching-aider-cline-opencode.mdx

AI Coding Agents

Prompt Caching in Aider, Cline and OpenCode: Who Caches What, and Where It Breaks

Aider documents --cache-prompts and a keepalive option for eligible provider caches. On Cline’s direct Anthropic path, users of specific Next-engine versions reported cache reads for the initial prefix and ordinary input charges for later tool-loop tokens. An OpenCode 2.4.1 report described a Plan-mode miss when a reminder moved after the first request.

Aider documents an opt-in cache setting and keepalive pings for eligible provider caches. Cline users on specific VS Code Next-engine versions reported that their direct Anthropic requests kept reading the initial cached prefix while later tool-loop input accrued ordinary input charges. An OpenCode 2.4.1 report described a separate Plan-mode miss when a reminder moved after the first request. Issue and pull request states are as of November 30, 2026.

Aider’s opt-in cache and keepalive pings

Run Aider with --cache-prompts or enable the setting in your configuration files. Aider’s documented launch output includes “prompt cache” next to the main model when the setting is on. Check that line when comparing sessions launched from different directories or with different configurations.

Aider organizes the chat history so the cacheable content forms a stable prefix. Per its docs, it tries to cache:

  • The system prompt.
  • Read-only files added with --read or /read-only.
  • The repository map.
  • The editable files that have been added to the chat.

To inspect Aider’s cache statistics, try the illustrative command aider --cache-prompts --no-stream. Aider’s docs say cache statistics and costs are unavailable with streaming responses because of provider API limitations. The docs’ launch example uses claude-3-5-sonnet-20240620. Check your provider’s caching support for the exact model you choose.

Anthropic’s default cache TTL is five minutes. For pauses, --cache-keepalive-pings 3 asks Aider to send up to three pings over 15 minutes after each message. Check the cache statistics when you resume. A read depends on a live entry and a matching eligible prefix, so a ping cannot preserve reuse if the request now starts with different content.

For a useful comparison, start with a normal follow-up before pausing. Keep the model and file selection steady and check that you can get a read in an active session. Then repeat after a typical pause. A slow resumption with a new write suggests a different problem from a session that showed no reads even while active. If your agent and provider expose a one-hour TTL, compare its write cost with the cost of rebuilding an expired prefix using the cache TTL tradeoff.

Cline’s reported tool-loop breakpoint

Open issue #15167, filed October 18, 2026, reports the problem on the direct Anthropic path in the Cline 4.1.24 Next bundle for VS Code. The captured /v1/messages body shows one cache_control marker on the last user text block. The SDK treats tool results as tool messages. On the wire, those results appear as user messages containing tool_result blocks, and the captured blocks have no cache marker. The marker stays with the earlier user text while assistant turns and tool results accumulate beyond it.

Open issue #15307, filed October 24, 2026, reports the pattern from billing logs in VS Code Next v4.1.25. The reporter observed cacheReadTokens staying near 15,000 and cacheWriteTokens staying at zero on subsequent automated turns. Their logs still showed reads for the initial prefix, with ordinary input charges for conversation growth beyond it. The reporter said reverting to Legacy v4.0.12 restored growing cache reads and writes when new content arrived.

Two pull requests propose changes to where the cache boundary advances. Both were open as of November 30, 2026.

  • PR #15174, opened October 18, proposes moving the explicit marker to the last tool-result part when a tool response is the newest cacheable message. The PR says the SDK serializes this as cache_control on the tool_result block for the anthropic and vertex clients, keeping one explicit message breakpoint per request.
  • PR #15340, opened October 25, attributes the missing automatic breakpoint to the SDK option spelling. The author says @ai-sdk/anthropic drops the request-level option when spelled cache_control and proposes passing cacheControl so it serializes as top-level cache_control. This would add automatic caching alongside the explicit marker.

The descriptions differ on gateway behavior. PR #15174 leaves OpenAI-compatible routes out because they serialize tool messages differently and speculates that they could show a similar symptom. PR #15340 says the Cline and OpenRouter passthrough paths already supplied top-level cache_control. Inspect the serialized request and the usage counters for the route you actually run, since each description concerns a particular integration and request shape.

PR #15340’s author recorded 3,359 cache-read tokens and zero writes in each of three tool rounds before the proposed change. After it, reads grew from 3,361 to 6,548 to 9,736, with about 3,190 tokens written per round. In an append-only loop with a live cache, that pattern means the prior round’s write is available to read on the next request. A single cache hit can look healthy even while these counters stay flat across an entire loop.

Open issue #15641, filed November 10, 2026, reports repeated re-prefill on Cline 4.1.26 VS Code when toggling between Plan and Act against a local llama.cpp server. The reporter recorded 17 to 36 seconds and 24,000 to 46,000 tokens of re-prefill. They identified changes to the serialized system instructions and tool set, including the editor tool being hidden in Plan mode. The issue proposes keeping the prefix stable and enforcing Plan-mode restrictions through per-message markers and a tool execution guard.

OpenCode’s first Plan-mode follow-up

Issue #67040, opened and closed on November 28, 2026, reports a Plan-mode prefix mismatch in OpenCode 2.4.1. The <system-update> reminder appeared before the user’s first message in the first request. The reminder appeared after that message starting with the second request. The change shortens the matching prefix on the first follow-up.

The reporter logged requests through a proxy in front of llama-server. In Build mode, requests 2 through 5 each started with the full previous request. In Plan mode, request 2 matched only the first 25,690 of 26,257 characters, through the system prompt. Requests 3 through 5 matched again. At the reporter’s assumed prefill speed of 250 tokens per second, re-prefilling an illustrative 16,000-token first message would take about 64 seconds. The log measured a shared character prefix, so use model or provider telemetry to measure the actual number of reused tokens on your installed version.

The three agents side by side

AgentHow caching is engagedWhere the cacheable boundary sitsKnown issue as of 2026-11-30State
AiderOpt-in via --cache-prompts or config, with optional keepalive pingsAider tries to cache the system prompt, read-only files, repo map and chat filesCheck eligibility on the model you useDocumented
ClineExplicit marker on the reported direct Anthropic Next-engine pathMarker stayed on the last user text block#15167 and #15307 describe tool-loop growth outside the breakpoint. #15641 describes local Plan/Act re-prefill.Issues and related PRs open
OpenCodePrefix reuse on the reported local provider pathMatching prefix shortened when the Plan reminder moved between the first two requests#67040 describes the mismatch and later recovery in OpenCode 2.4.1Closed November 28, 2026

What a stuck breakpoint costs

Estimate input costs for a cold 15,000-token initial request (system prompt, tools and the user’s task) followed by 20 tool rounds that each append 3,000 tokens, ending near the 70,000-token context the #15307 reporter describes. Assume the stuck breakpoint stays on that initial 15,000-token prefix, the advancing breakpoint covers the whole request and each follow-up hits the eligible prefix within the five-minute TTL. Claude Sonnet 5.5 costs $2.00 per million ordinary input tokens, $0.10 per million cache-read tokens and $2.50 per million five-minute cache-write tokens. The estimate counts input charges only.

  • Stuck breakpoint. The first request writes 15,000 tokens. Each follow-up reads 15,000, while ordinary input grows from 3,000 to 60,000. Across all requests, that is 15,000 cache-write tokens, 300,000 cache-read tokens and 630,000 ordinary input tokens. Estimated input cost is (15,000 × $2.50 + 300,000 × $0.10 + 630,000 × $2.00) / 1,000,000, about $1.33.
  • Advancing breakpoint. The first request writes 15,000 tokens. Each follow-up writes 3,000 more and reads the previous request’s full prefix, growing from 15,000 read tokens on the first follow-up to 72,000 on the last. Across all requests, that is 75,000 cache-write tokens and 870,000 cache-read tokens. Estimated input cost is (75,000 × $2.50 + 870,000 × $0.10) / 1,000,000, about $0.27.

The stuck breakpoint costs about five times as much in this estimate. A short loop has fewer chances to read back each newly written segment. A longer append-only loop repeatedly resends old tool output, so an advancing breakpoint turns more of those repeated ordinary input charges into reads. For a workload that changes tools, rewrites earlier messages or pauses long enough for entries to expire, use the actual per-turn counts from measuring prompt cache hit rate.

What to check in your next session

  1. Aider. Inspect the non-streaming cache statistics on a normal follow-up and again after a pause. If only the second case misses, test keepalive with the same model and files. If both miss, check the launch line, provider eligibility and any edits to the cached file content before interpreting the result as expiration.
  2. Cline with the direct Anthropic API. Keep the model, tools and mode fixed for several tool rounds. Log cache_read_input_tokens, cache_creation_input_tokens and input_tokens from the API response. The last field measures ordinary input, so add all three to calculate total input. Under a live, unchanged prefix, flat reads and growing ordinary input point to the tail staying outside the marker. Inspect breakpoint placement using the Anthropic cache breakpoints guide. If reads fall after a long pause or a tool change, use the Claude Code cache-miss examples to compare the symptoms of expiration and a changed prefix.
  3. Local Plan mode. Compare the serialized system prompt, tool order and first user message between requests. Test the first follow-up and later turns before switching modes, then compare a Plan-to-Act toggle separately. The OpenCode report saw matching prefixes again after the first mismatch. The local Cline report describes the system prompt and tools changing on toggles. Use a prefix diff to locate the first changed section, then confirm the effect with your server’s reuse telemetry.
  4. Hosted cost. Add up the read, write and ordinary input buckets across the session and apply the model’s rates from the AI Provider Pricing Index. Comparing those totals alongside the number of tool rounds helps distinguish a more expensive cache pattern from a task that simply required more requests.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

Prompt Caching in Aider, Cline and OpenCode: Who Caches What, and Where It Breaks. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/prompt-caching-aider-cline-opencode/

Sources