AI编码
dev.to ·
@Johmisking
实测 Claude Code 的 prompt cache 过期时间:暂停 0 到 65 分钟
作者在 Claude Code 2.1.295、Opus 5.5、订阅登录、headless 模式下,先让模型生成一个 index.html 小游戏,再分别暂停 0、4、6、15、30、55、65 分钟后用 --resume 继续同一会话,要求修改小球颜色和速度,通过成本跳变判断 prompt cache 的实际有效期,以检验“5 分钟”与“1 小时”两种说法。摘要未披露最终结果。
AI推荐理由 作者对 Claude Code 的 prompt cache 过期时间做了实测:在 0、4、6、15、30、55、65 分钟暂停后继续同一会话,观察成本跳变点,以区分“5 分钟”与“1 小时”两种说法。这是开发者关心的成本与延迟问题,方法可复现;但摘要只给出测试设置,未给出结果数据,且为个人单点测试,样本与版本有限,结论需谨慎。
72
正文
You work in Claude Code all morning, go to lunch, come back and send one more message. The first reply is slow and your usage jumps. The usual suspect is the prompt cache: once it expires, the next message has to re-process the whole conversation.
But how long does the cache actually last? Guides say five minutes, others say an hour, and in April 2026 there was a whole controversy about it. I couldn't find anyone who had simply waited and measured, so I did.
The test
Claude Code 2.1.295, Opus 5.5, medium effort, signed in with a subscription, headless (-p), no MCP servers
Turn 1: build a small brick-breaker game in one index.html
Wait 0, 4, 6, 15, 30, 55 or 65 minutes
Turn 2 in the same session (--resume): "Make the ball red and slightly faster."
Each pause in its own session, all started within a minute of each other, run twice (October 20, 2026)
If the cache lasts five minutes, the cost should jump between 4 and 6 minutes. If it lasts an hour, between 55 and 65.
Results
First model call of the next message, mean of two runs. Cost is Claude Code's API list-price estimate.
Pause
Read fr