You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Claude Agent: Opus 5.5 shows 3.9x lower cache reuse than native Claude Code #61282
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:
Versions:opencode --version and claude --version, plus your OS and how you installed OpenCode.
Setup: which plugins and MCP servers you have enabled, and whether you used subagents.
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:
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:
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).
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.
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!
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!
Activity
opencodejr commentedon Nov 2, 2026
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:
opencode --versionandclaude --version, plus your OS and how you installed OpenCode.input/cache_write/cache_readnumbers. Even 5–10 turns would help a lot. For OpenCode, the per-message token usage in the session (e.g. fromopencode 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:
claude-agent: system text / prompts added by plugin context hooks never reach Claude #61248: onclaude-agent, text that plugins add to the system prompt never reaches Claude, so OpenCode's system prompt differs from Claude Code'sPrognosticate-X commentedon Nov 3, 2026
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
Premature Context Compaction (#61020):
200,000.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).System Instruction Prefix Invalidation via Plugin Hooks (#61248):
event.systemshifts the byte-for-byte SHA-256 hash at offset 0.Tool Parameter Dictionary Key Drift:
2. Side-by-Side Controlled A/B Profile
We ran a controlled 3-turn trace comparing identical tool-use workloads:
cache_read / write+input)17,42009,30026,820+17,5203. Tooling for Verification
If anyone wants to isolate where their own session diverges, you can pipe your session export through agent-cache-lens:
Hope this forensic data helps isolate the fix for
#61282!opencodejr commentedon Nov 5, 2026
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!