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
Session:ses_02b3612c6ffeOFnJw6eQrlTKW0 (2026-08-06) Cost: $0.03 Cache write: 0 (DeepSeek does not charge for cache writes) Cache read: grows steadily from 2K to 89K (no busts)
This demonstrates that the issue is specific to Anthropic's cache write pricing combined with the cache bust bug.
OpenCode's prompt loop reloads all messages from DB via filterCompactedEffect() at the start of every iteration
Tool parts transition from pending → completed with output text between API calls
toModelMessages() serializes the conversation with different bytes
Anthropic's prompt cache sees different content → cache invalidated from that position forward
Entire conversation context (~250K tokens) re-written at cache-write pricing ($6.25/M)
Verified: All 9 cache busts in the $18.66 session occurred immediately after tool-calls finish type.
New Evidence Not in Previous Reports
Consecutive cache busts: 5 in a row (messages Codex mini #34-38), each costing $1.63. This suggests the cache is being invalidated on every single turn during heavy tool-use loops.
Cache bust rate: 22.5% (9/40 messages) in a real production session with only 43 messages.
Production cost data: Real money wasted ($14.82 across 3 sessions) with exact per-message cost breakdown from OpenCode's SQLite database.
Database Queries
Query 1: Session-level cache stats
SELECT
id,
cost,
tokens_input,
tokens_output,
tokens_cache_read,
tokens_cache_write
FROM session
WHERE id ='ses_03563ecbdffe92x5KFrsYJRWnN';
Query 2: Message-level cache pattern
SELECT
json_extract(data, '$.finish') as finish,
json_extract(data, '$.tokens.cache.read') as cache_r,
json_extract(data, '$.tokens.cache.write') as cache_w,
json_extract(data, '$.cost') as cost
FROM message
WHERE session_id ='ses_03563ecbdffe92x5KFrsYJRWnN'AND json_extract(data, '$.role') ='assistant'ORDER BY json_extract(data, '$.time.created');
Query 3: Verify cache busts after tool-calls
WITH msg_list AS (
SELECT
json_extract(data, '$.finish') as finish,
json_extract(data, '$.tokens.cache.read') as cache_r,
json_extract(data, '$.tokens.cache.write') as cache_w,
ROW_NUMBER() OVER (ORDER BY json_extract(data, '$.time.created')) as rn
FROM message
WHERE session_id ='ses_03563ecbdffe92x5KFrsYJRWnN'AND json_extract(data, '$.role') ='assistant'
)
SELECTm1.rn,
m1.cache_r,
m1.cache_w,
m2.finishas prev_finish
FROM msg_list m1
LEFT JOIN msg_list m2 ONm1.rn=m2.rn+1WHEREm1.cache_r=0ANDm1.cache_w>0;
Impact
Financial: $14.82 wasted across 3 sessions (39% of total Opus 5 spend)
User trust: Users expect prompt caching to work as advertised; silent cache busts at 12.5x read cost are unacceptable
Model choice: Forces users to avoid Anthropic models on Zen for tool-heavy workloads, limiting model selection
Full session data available upon request (can export from ~/.local/share/opencode/opencode.db). Per-message cost breakdown available. Can provide additional sessions if needed.
Summary
Production data from OpenCode 1.18.9 shows the Anthropic prompt cache bust bug (Issue #24841) is still active and causing significant financial waste.
Key findings:
Estimated waste: $14.82 (39% of total cost) could have been avoided if caching worked correctly.
Evidence
Session 1:
ses_03563ecbdffe92x5KFrsYJRWnN($18.66)Title: Creating AGENTS.md for repository
Date: 2026-08-04
Messages: 43 (38 tool-calls, 2 stop)
Total tokens: 80 input / 48,028 output / 6,148,780 cache read / 2,301,161 cache write
Cost breakdown:
Cache bust pattern (all after tool-calls):
Consecutive cache busts (#34-38): 5 in a row, wasting $8.15
Expected cost if cache worked: $5.84
Actual cost: $18.66
Waste: $12.82 (69%)
Session 2:
ses_03861eca0ffeuobD3dLHqYq99p($11.50)Title: LLM速度对比与Agent配置优化建议
Date: 2026-08-03
Messages: 73 (67 tool-calls, 3 stop)
Cache busts: 2
Cache write: 523,712 tokens × $6.25/M = $3.27 (28.5% of cost)
Session 3:
ses_0381fd091ffe4KS4TxsnTcsOFW($7.51)Title: Claude Code Max订阅与API token费用对比
Date: 2026-08-03
Messages: 45 (35 tool-calls, 5 stop)
Cache busts: 2
Cache write: 498,810 tokens × $6.25/M = $3.12 (41.5% of cost)
Comparison: DeepSeek V4 Pro (no cache write fee)
Session:
ses_02b3612c6ffeOFnJw6eQrlTKW0(2026-08-06)Cost: $0.03
Cache write: 0 (DeepSeek does not charge for cache writes)
Cache read: grows steadily from 2K to 89K (no busts)
This demonstrates that the issue is specific to Anthropic's cache write pricing combined with the cache bust bug.
Root Cause
Matches Issue #24841 exactly:
filterCompactedEffect()at the start of every iterationpending→completedwith output text between API callstoModelMessages()serializes the conversation with different bytesVerified: All 9 cache busts in the $18.66 session occurred immediately after
tool-callsfinish type.New Evidence Not in Previous Reports
Consecutive cache busts: 5 in a row (messages Codex mini #34-38), each costing $1.63. This suggests the cache is being invalidated on every single turn during heavy tool-use loops.
Cache bust rate: 22.5% (9/40 messages) in a real production session with only 43 messages.
Cost per bust: $1.46-$1.63 (250K tokens), lower than the $3.50 (560K) reported in Prompt loop DB reload breaks Anthropic cache after tool calls (63% of spend) #24841, but still significant at scale.
Production cost data: Real money wasted ($14.82 across 3 sessions) with exact per-message cost breakdown from OpenCode's SQLite database.
Database Queries
Query 1: Session-level cache stats
Query 2: Message-level cache pattern
Query 3: Verify cache busts after tool-calls
Impact
Request
Environment
opencode/claude-opus-5)Additional Data
Full session data available upon request (can export from
~/.local/share/opencode/opencode.db). Per-message cost breakdown available. Can provide additional sessions if needed.Related: #24841 #25366 #31525 #20110 #36852