跳到主内容
@wquguru
精选82VoxAI 产品与模型

Claude Code 状态栏添加缓存倒计时功能推荐

Highly recommend adding a 𝗰𝗮𝗰𝗵𝗲 𝗰𝗼𝘂𝗻𝘁𝗱𝗼𝘄𝗻 to your Claude Code status line.

原文
发到 X
推荐理由

将技术文档转化为具体的工具优化方案,结构清晰,直接提供可执行的 Prompt 和配置逻辑,对同类 AI 工具用户有较高的参考价值。

Highly recommend adding a 𝗰𝗮𝗰𝗵𝗲 𝗰𝗼𝘂𝗻𝘁𝗱𝗼𝘄𝗻 to your Claude Code status line.

强烈建议在你的 Claude Code 状态栏中添加一个 𝗰𝗮𝗰𝗵𝗲 𝗰𝗼𝘂𝗻𝘁𝗱𝗼𝘄𝗻(缓存倒计时)。

Simply put, every time you send a message, Claude Code sends the whole conversation to the model again. The cache lets it skip reprocessing everything that came before, so replies come back faster and count less against your usage limits. But the cache expires, and the first message after that makes it process 𝘁𝗵𝗲 𝘄𝗵𝗼𝗹𝗲 𝗰𝗼𝗻𝘃𝗲𝗿𝘀𝗮𝘁𝗶𝗼𝗻 𝗳𝗿𝗼𝗺 𝘀𝗰𝗿𝗮𝘁𝗰𝗵. Normally you can't see how much time it has left. With this, your status line always shows the minutes left, and once the cache expires, it tells you how many tokens your next message will re-cache. If it's about to run out and you still have something to ask, ask it now.

简单来说,每次你发送消息时,Claude Code 都会将整个对话重新发送给模型。缓存功能让它能够跳过对之前内容的重复处理,从而使回复更快返回,并减少对你使用限额的消耗。但缓存会过期,过期后的第一条消息会让它从头开始处理 𝘁𝗵𝗲 𝘄𝗵𝗼𝗹𝗲 𝗰𝗼𝗻𝘃𝗲𝗿𝘀𝗮𝘁𝗶𝗼𝗻 𝗳𝗿𝗼𝗺 𝘀𝗰𝗿𝗮𝘁𝗰𝗵(整个对话)。通常你无法看到剩余的时间。有了这个功能,你的状态栏始终显示剩余分钟数;一旦缓存过期,它会告诉你下一条消息将重新缓存多少 token。如果缓存即将耗尽而你还有问题要问,现在就问吧。

The official docs have a few more things I didn't know: → On a subscription, within your plan's usage, the main conversation's cache lasts 1 hour, while subagents and workflows get 5 minutes. On an API key, or once you're past your limit and on usage credits, the main conversation gets 5 minutes too → Switching models mid-session recomputes everything, and with opusplan, every move into or out of plan mode counts as a switch → Editing CLAUDE.md mid-session doesn't break the cache, but the edit doesn't apply either until /clear, /compact or a restart → Went down the wrong path and want a redo? /rewind back and it can pick up the cache you already had; /compact builds a new one

官方文档中还有一些我不知道的内容: → 在订阅模式下,在套餐用量范围内,主对话的缓存有效期为 1 小时,而子代理和工作流仅为 5 分钟。在使用 API Key 或超出限额并使用按量付费信用额度时,主对话的缓存也仅为 5 分钟 → 在会话中途切换模型会重新计算所有内容,而在 opusplan 中,进入或退出计划模式都算作一次切换 → 在会话中途编辑 CLAUDE.md 不会破坏缓存,但在执行 /clear、/compact 或重启之前,该编辑也不会生效 → 走错了路径想要重来?使用 /rewind 回退,它可以利用你已有的缓存;/compact 则会构建一个新的缓存

Send this prompt and the link below to Opus 5.5 👇

将此提示词和下方的链接发送给 Opus 5.5 👇

"Read this doc, plus the status line field reference it links to, and add a cache segment to my Claude Code status line. 1. If I already have a status line, don't replace it. Save stdin first so the original command and the cache segment read the same input, leave the original output as is, and put the cache segment on its own line after it. If I don't have one, create one. 2. Get the data from prompt_cache in the input: warm, ttl, expires_at, hit_ratio, misses, last_miss_cause, recache_tokens_if_cold. Show nothing until prompt_cache appears, and skip any field my version doesn't have. 3. While the cache is warm, show it in green with a progress bar and the time left, like "cache ● 1h ████░░ 38m left · hit 91% · misses 0". Turn it yellow when less than 20% of the time is left. 4. When it's cold, show it in red as "cache ○ cold · next message re-caches 82k tokens", with the token count rounded to k. Add the miss cause only when there is one. 5. In the settings file where my statusLine already lives, add "refreshInterval": 30 inside the statusLine object, next to command, so the countdown keeps moving. If my Claude Code is older than 2.1.251, tell me. Don't upgrade it yourself. When you're done, run sample JSON for warm, about to expire, and cold, and show me the output."

"阅读此文档,以及它链接到的状态行字段参考,并在我的 Claude Code 状态行中添加一个缓存段。 1. 如果我已经有一个状态行,不要替换它。先保存 stdin,以便原始命令和缓存段读取相同的输入,保留原始输出不变,并将缓存段放在其单独的一行上。如果没有,则创建一个。 2. 从输入中的 prompt_cache 获取数据:warm(热)、ttl(生存时间)、expires_at(过期时间)、hit_ratio(命中率)、misses(未命中次数)、last_miss_cause(上次未命中原因)、recache_tokens_if_cold(冷时重新缓存的 token 数)。在 prompt_cache 出现之前不显示任何内容,并跳过我的版本中不存在的任何字段。 3. 当缓存处于热状态时,以绿色显示进度条和剩余时间,例如“cache ● 1h ████░░ 38m left · hit 91% · misses 0”。当剩余时间少于 20% 时变为黄色。 4. 当缓存处于冷状态时,以红色显示为“cache ○ cold · next message re-caches 82k tokens”,token 数量四舍五入到 k。仅在存在未命中原因时才添加该原因。 5. 在我 statusLine 所在的设置文件中,在 statusLine 对象内、command 旁边添加“refreshInterval”: 30,以便倒计时持续移动。 如果我的 Claude Code 版本早于 2.1.251,请告诉我。不要自行升级它。完成后,运行针对热状态、即将过期和冷状态的示例 JSON,并向我展示输出结果。"

https://code.claude.com/docs/en/prompt-caching

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件