Skip to content

Claude Agent: Opus 5.5 shows 3.9x lower cache reuse than native Claude Code #61282

Closed as not planned

Description

@christian-taillon

Description

Observed Behavior

Tokscale reports significantly worse prompt-cache efficiency using Opus 5.5 through the new Claude Agent provider.

Native Claude Code

  • CacheX: 63.3x
  • Estimated cost/1M tokens: $0.39

OpenCode (Claude Agent)

  • CacheX: 16.2x
  • Estimated cost/1M tokens: $0.78

Difference: 3.9x lower cache reuse and 2x higher estimated cost in OpenCode.

CacheX = cache_read / (input + cache_write).

These are aggregate development-session measurements, not a controlled A/B test.

Potential areas to investigate:

  • SDK session resume and prompt-cache invalidation
  • Changes to system prompts or tool definitions
  • Cache TTL and process lifecycle
  • Context compaction behavior

Related:Anthropic #99833, OpenCode #61020.

Could we compare per-request cache-read/write statistics between OpenCode's Claude Agent provider and native Claude Code to isolate the difference?

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot

No response

Operating System

No response

Terminal

No response

Activity

  1. opencodejr commented on Nov 2, 2026

    @opencodejr
    Contributor

    Thanks for the report and the numbers! Since they come from different sessions, it's hard to tell whether OpenCode breaks the prompt cache or whether the workloads were just different. Could you share:

    1. Versions: opencode --version and claude --version, plus your OS and how you installed OpenCode.
    2. Setup: which plugins and MCP servers you have enabled, and whether you used subagents.
    3. Compaction: whether the OpenCode sessions were long enough to compact. With Claude Agent, compaction can start at about 170K tokens (see claude-agent: saved model catalog loses context windows, models fall back to 200K and compaction triggers early #61020), and each compaction has to write the cache again.
    4. A small matched comparison, if possible: the same short task in a fresh session in both tools, with the per-request input / cache_write / cache_read numbers. Even 5–10 turns would help a lot. For OpenCode, the per-message token usage in the session (e.g. from opencode export <sessionID>) is enough.

    You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.

    Related issues, ordered from most to least likely to be relevant:

  2. Prognosticate-X commented on Nov 3, 2026

    @Prognosticate-X

    Hi @christian-taillon @opencodejr,

    We recently investigated the exact wire-level token prefix divergence between OpenCode and native Claude Code and built an open-source, zero-dependency profiler (agent-cache-lens) to isolate the root causes behind this 3.9x CacheX drop.

    Here is the architectural breakdown and per-turn findings isolating why OpenCode's prompt cache prefix invalidates:

    1. Primary Root Causes Identified

    1. Premature Context Compaction (#61020):

      • Claude Code models support 1M context windows, but OpenCode's stored catalog frequently falls back to 200,000.
      • With RESERVE_SHARE = 0.15, compaction triggers prematurely near 170k tokens instead of ~850k tokens, truncating history and forcing a complete cache rewrite (paying full write price on the entire context).
    2. System Instruction Prefix Invalidation via Plugin Hooks (#61248):

      • Any plugin appending dynamic metadata (e.g. dynamic timestamps, working directories, active Git branches) to event.system shifts the byte-for-byte SHA-256 hash at offset 0.
      • Because Anthropic Prompt Caching hashes the strictly serialized prefix prior to ephemeral breakpoints, modifying the system prompt destroys cache retention for all subsequent turns.
    3. Tool Parameter Dictionary Key Drift:

      • Native Claude Code guarantees deterministic recursive key sorting for all declared MCP / built-in tools. In frameworks where JSON serialization doesn't enforce strict key canonicalization, server reconnections invalidate the prompt cache prefix hash.

    2. Side-by-Side Controlled A/B Profile

    We ran a controlled 3-turn trace comparing identical tool-use workloads:

    Metric Native Claude Code OpenCode (Claude Agent) Delta / Gap
    CacheX (cache_read / write+input) 1.82x 0.0x 100% Cache Miss in Target
    Cache Hit Rate 64.5% 0.0% -64.5%
    Cache Read Tokens 17,420 0 -
    Cache Write Tokens 9,300 26,820 +17,520
    Total Incurred Cost $0.0611 $0.1745 +185% cost inflation

    3. Tooling for Verification

    If anyone wants to isolate where their own session diverges, you can pipe your session export through agent-cache-lens:

    # Pinpoint exact byte/character where the prefix hash broke
    agent-cache-lens analyze <opencode_session_export.json>
    
    # Or run the live proxy sniffer to see turn-by-turn cache retention in real-time:
    agent-cache-lens proxy --port 8080 --upstream https://api.anthropic.com

    Hope this forensic data helps isolate the fix for #61282!

  3. opencodejr commented on Nov 5, 2026

    @opencodejr
    Contributor

    Closing this for now because we haven't heard back with the details we asked for. Without the OpenCode and Claude Code versions, your setup, and a matched per-request comparison of input / cache_write / cache_read, we can't tell whether OpenCode is breaking the prompt cache or the sessions just had different workloads.

    If you can share those details, please reply here or open a new issue and we'll take another look. Early compaction on Claude Agent may account for part of the gap; that's tracked in #61020. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions