Repository navigation
Description
Description *
Since routing Claude Code through bili, the VS Code extension no longer shows the 5-minute prompt-cache countdown icon. Prompt caching itself still works (cache_read_input_tokens stays high). Only the TTL breakdown is lost. Not compression-related: it happens on every turn, with or without a fold.
Expected: the response usage keeps usage.cache_creation.{ephemeral_5m_input_tokens, ephemeral_1h_input_tokens} from the upstream, so the countdown icon renders.
Repro:
- Point Claude Code (VS Code extension) at bili in proxy mode:
ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/bili/<upstream> - Send any message that creates or reads prompt cache
- Countdown icon is missing. In the transcript (
~/.claude/projects/<proj>/<session>.jsonl) every usage row hasephemeral_5m_input_tokens: 0, ephemeral_1h_input_tokens: 0even whencache_creation_input_tokens > 0
How the extension uses it. The webview derives the TTL only from the breakdown object:
// anthropic.claude-code-2.1.304 webview/index.js (minified)
function Pl0($){let J=$?.cache_creation;if(!J)return;
if((J.ephemeral_1h_input_tokens??0)>0)return"1h";
if((J.ephemeral_5m_input_tokens??0)>0)return"5m";return}No cache_creation object, or both fields 0, gives a TTL of undefined. The countdown state becomes unknown and the icon is hidden.
Root cause (dist/index.js 0.1.202):
neutralizeStartUsage()(fix: anthropic stitched terminal as the sole usage authority (#1310) #1315) replacesmessage_start.message.usagewith{input_tokens:0, output_tokens:0}. Anthropic puts thecache_creationobject in exactly this frame, so it is discarded.buildTerminal()re-emitsinput_tokens,output_tokens,cache_read_input_tokens, andcache_creation_input_tokens, but not thecache_creationobject.- The string
ephemeral_occurs nowhere indist/index.js.
#1315 anticipated this class of breakage ("If any host … reads usage ONLY from message_start … its usage display would now read 0"). Here the lost piece is the breakdown, not the totals.
Evidence (transcript usage rows, same upstream):
| Session | Via bili | cache_creation_input_tokens | cache_read_input_tokens | ephemeral_5m | ephemeral_1h |
|---|---|---|---|---|---|
| A | no | 151696 | 0 | 151696 | 0 |
| A | no | 417 | 153690 | 417 | 0 |
| B | yes | 66756 | 107541 | 0 | 0 |
| C | yes | 7551 | 77565 | 0 | 0 |
Suggested fix:
- When capturing round usage (
message_start/message_delta), also keepusage.cache_creationas-is. - In
buildTerminal, emit it next tocache_creation_input_tokens(from the final round when stitched, matching how the totals are chosen). - Pass it through as-is. Don't synthesize it: the upstream knows whether the write was 5m or 1h.
- The start frame stays neutral, so the [bug] claude native: stitched-stream usage double count after in-stream compress locks session ('Prompt is too long') — #300 variant #1310 / fix: anthropic stitched terminal as the sole usage authority (#1310) #1315 double-count protection is unaffected.
Test idea: extend the #1310 non-stitched companion test to assert that the terminal carries the same cache_creation object as the upstream start frame.
bili version *
0.1.202
Usage mode *
Proxy mode (client manually points its base URL at bili)
Client and version *
claude code — VS Code extension 2.1.304 (win32-x64)
Operating system *
Windows 11 Pro (not WSL2)
Upstream and model *
Anthropic-compatible relay (localhost) · claude-opus-5-5 · 1M
Compression-related config (optional)
# env only, no config-file changes
BILI_NO_CACHE_CONTROL: "1"Log excerpt (strongly recommended)
/acp or acp_status output (optional)
Activity
ranxianglei commentedon Oct 21, 2026
(ai: vllm-qwen/qwen3.8-27b)
查重: 不重复。 按失败签名(
cache_creation/ephemeral_5m/ countdown icon)检索 open+closed issues/PR:相关条目只有 #1315(引入本缺陷的改动,已合并)和 #1310(原始双计问题),均不覆盖「breakdown 对象丢失」这个缺陷本身。标签: bug, claude-code, scope/wiring, p2(缓存功能本身正常,仅 TTL 倒计时图标消失——明显可见但有绕行;非缓存泄露类,不升 p1)
审核结论(代码级核验,你的根因分析完全成立)
对照 v0.1.202 源码逐条复现了你列的三个事实:
neutralizeStartUsage()(fix: anthropic stitched terminal as the sole usage authority (#1310) #1315 所加)确实把message_start.message.usage整体改写为{input_tokens:0, output_tokens:0}(src/loop/adapter-anthropic.ts)。Anthropic 恰好把cache_creationbreakdown 对象放在这一帧里 → 随中性化一起被丢弃。buildTerminal()只重发input_tokens / output_tokens / cache_read_input_tokens / cache_creation_input_tokens,不重发cache_creation对象。ephemeral_零命中——这个字段从未被建模过。层次判断:#1315 要修的是「总量双计」(start 帧与合成 terminal 各带一份 totals,host 相加爆窗),所以把 start 帧用量置零、totals 归 terminal 独享。 casualties 是另一个数据维度:breakdown 对象在 wire 上没有第二个载体,start 一置零它就没了。你的修法方向正中要害——loop 本来就取最后一轮的 usage 进 terminal(stitched 场景下就是 fold 后重发那轮),把这个对象沿同一条路原样带过去即可,stitching 语义免费正确;且 start 帧保持中性,#1310/#1315 的双计保护不受影响。
开工中,计划改动面:
src/loop/adapter-anthropic.ts:parseStream 捕获usage.cache_creation(start 帧原样取;delta 不完整帧仅在含正值时采纳,防 relay echo 全零 schema 形状污染);buildTerminal增加该字段,紧邻cache_creation_input_tokens发出。src/loop/core.ts:usage 事件/完成选项类型加一个可选字段(纯类型管道)。cache_creation对象)+ stitched 变体(末轮胜出)+ 两个负例(upstream 无 breakdown → terminal 不带该键;全零 echo → 不采纳)。完成后在本帖回 PR 链接。
ranxianglei commentedon Oct 21, 2026
(ai: vllm-qwen/qwen3.8-27b)
修复完成:PR #4074(Closes #4072),分支
2026-10-21_anthropic-cache-creation-breakdown,已 rebase 到最新 master,等 CI。结构化八问
cache_creationbreakdown 对象(ephemeral_5m_input_tokens/ephemeral_1h_input_tokens)。Claude Code VS Code 的 prompt-cache TTL 倒计时图标只从该对象推导 → 图标消失(缓存命中本身正常)。message_start.message.usage中性化为零值,让合成 terminal 成为唯一 usage 权威(防总量双计)。但 breakdown 对象只存在于这一帧,而 terminal 重发时只带了四个数字字段、没给它留载体——它随中性化一起被丢弃。不是「总量被过度清零」,是「这个数据维度没有载体」。usage.cache_creation(无条件);不完整 delta 帧仅在对象含正值时采纳(与数字字段同族的 relay 全零 echo 防护,Redesign #408 host-usage backfill: post-fold by default, baseline opt-in (opencode gap + whack-a-mole exemptions) #660 同类);terminal 在cache_creation_input_tokens旁重发该对象;stitched 场景取末轮——与 totals 的选择规则一致;从不合成:上游没有就不带这个键。start 帧保持中性不变。{input_tokens:0, output_tokens:0},terminal 仍是唯一带 usage 的帧(测试断言钉住usageFrames.length === 1且 start 上无cache_creation键);② 数字字段采纳规则(>0 门、完整对象原子采纳)未动,新字段独立跟随同一规则;③ openai/responses/google 车道:字段可选且恒为 undefined,输出零差异;④ 错误路径emitError不传该参数,行为不变。结论:无回归。行为变更披露(additive):anthropic 车道的合成 terminal
usage在上游提供 breakdown 时新增携带cache_creation对象(与上游 start 帧逐字节一致)。旧值:键不存在 → 新值:上游提供时存在。读它的客户端受益,忽略未知键的客户端无感。验证状态:本地定向测试全绿(loop-adapters 38/38 含 3 个新用例+扩展的 #1310 companion、host-usage-postfold 27/27、issue1766-terminal-extra + proxy-stream-error + plugin-terminal-usage 23/23),typecheck clean;全量回归与真实客户端 e2e 交给 CI。CI 绿即可合并 PR #4074。
fix: re-carry the anthropic cache_creation breakdown on the synthetic…
fix: re-carry the anthropic cache_creation breakdown on the synthetic…