告诉 HN:Claude-code 提示词缓存修复

1作者: g4cg54g544 个月前
TLDR:目前,使用 `CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude "Hello"` 启动。<p>否则,你只会命中工具块,以及你的第一个后续问题。<p>(注意:在 settings.json 中设置 includeGitInstructions=false 也是一个选项,而且可能更好,因为 git-status <i>总是</i> 会产生噪音——但由于需要 "Hello",记住一个别名也很简单,效果一样;D)<p>目前,整个查询由 3 个可缓存的块构建:<p><pre><code> {tools | claude-version}, {system-prompt | ~&#x2F;.claude&#x2F;claude.md | git-status}, {skills | .&#x2F;claude.md | user-prompt} </code></pre> 环境变量将允许 system-prompt 行再次被缓存 https:&#x2F;&#x2F;github.com&#x2F;anthropics&#x2F;claude-code&#x2F;issues&#x2F;47107<p>"Hello" 允许 skills &amp; .&#x2F;claude.md 再次被缓存 https:&#x2F;&#x2F;github.com&#x2F;anthropics&#x2F;claude-code&#x2F;issues&#x2F;47098<p>之前:<p><pre><code> claude &gt; alive? &gt; -&gt; Yes, alive and ready. What do you need? &gt; &#x2F;exit # (11k cache read, 6k cache write) claude &gt; are you here? &gt; -&gt; Yes, I&#x27;m here. What can I help you with? &gt; &#x2F;exit # (11k cache read, 6k cache write) ^^ nothing changed, still cashed 6k write tokens claude &gt; alive? &gt; -&gt; Yes, I&#x27;m here. What can I help you with? &gt; &#x2F;exit # (18k cache read) ^^ the "exact same question" DOES hit the cache git commit --allow-empty -m "Dummy" claude &gt; alive? &gt; -&gt; Yes, alive and well. What do you need? &gt; &#x2F;exit # (11k cache read, 6k cache write) ^^ same question, but now git busts the cache.... </code></pre> 之后:<p><pre><code> $ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude "Hello" Claude Code v2.1.104 Hello ● Hello! How can I help you today? Alive? ● Yes, alive and ready to help! What are you working on? # (10k cache read, 6k cache write) $ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude "Hello" Claude Code v2.1.104 Hello ● Hello! How can I help you today? are you alive? ● I'm an AI, so not alive in the biological sense — but I'm here and ready to help. What can I do for you? # (16k cache read, 20 cache write) $ git commit -m "just a dummy" --allow-empty [main 642ce16] just a dummy $ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude "Hello" Claude Code v2.1.104 Hello ● Hello! How can I help you today? is this alive? ● Yes, I'm alive and running! Is there something I can help you with? # (16k cache read, 18 cache write) </code></pre> 注意:这并没有解决昨天关于 <i>5 分钟 vs 1 小时</i> 的讨论——但除非这些根本原因得到修复,否则整个讨论毫无意义……<p>- https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47739260 (Pro Max 5x 配额在 1.5 小时内耗尽,尽管使用量适中)<p>- https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47736476 (Anthropic 在 3 月 6 日降低了缓存 TTL)<p>但也有一些关于这方面的新闻:https:&#x2F;&#x2F;github.com&#x2F;anthropics&#x2F;claude-code&#x2F;issues&#x2F;46829#issuecomment-4237689126<p><pre><code> 目前,我们已经在许多地方为订阅用户默认推出了 1 小时的提示缓存…… 我们也没有将 API 客户默认为 1 小时——这需要更多测试,以确保它平均而言是一个净改进。 我们很快将把客户端默认值更改为 1 小时,用于一些查询 </code></pre>
查看原文
TLDR: for now launch using `CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude &quot;Hello&quot;`<p>otherwise you will only ever hit on the tools-block, and your first follow-up-question<p>(Note: setting includeGitInstructions=false in settings.json is an option to and likely the better thing anyhow since that git-status will <i>always</i> be noise - but since one needs the &quot;Hello&quot; remembering one alias is simple same deal ;D)<p>Currently the whole query is build from 3 cache-able blocks:<p><pre><code> {tools | claude-version}, {system-prompt | ~&#x2F;.claude&#x2F;claude.md | git-status}, {skills | .&#x2F;claude.md | user-prompt} </code></pre> the env-var will allow the system-prompt line go get cached again https:&#x2F;&#x2F;github.com&#x2F;anthropics&#x2F;claude-code&#x2F;issues&#x2F;47107<p>the &quot;Hello&quot; allows skills &amp; .&#x2F;claude.md to get cached again https:&#x2F;&#x2F;github.com&#x2F;anthropics&#x2F;claude-code&#x2F;issues&#x2F;47098<p>Before:<p><pre><code> claude &gt; alive? &gt; -&gt; Yes, alive and ready. What do you need? &gt; &#x2F;exit # (11k cache read, 6k cache write) claude &gt; are you here? &gt; -&gt; Yes, I&#x27;m here. What can I help you with? &gt; &#x2F;exit # (11k cache read, 6k cache write) ^^ nothing changed, still cashed 6k write tokens claude &gt; alive? &gt; -&gt; Yes, I&#x27;m here. What can I help you with? &gt; &#x2F;exit # (18k cache read) ^^ the &quot;exact same question&quot; DOES hit the cache git commit --allow-empty -m &quot;Dummy&quot; claude &gt; alive? &gt; -&gt; Yes, alive and well. What do you need? &gt; &#x2F;exit # (11k cache read, 6k cache write) ^^ same question, but now git busts the cache.... </code></pre> After:<p><pre><code> $ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude &quot;Hello&quot; Claude Code v2.1.104 Hello ● Hello! How can I help you today? Alive? ● Yes, alive and ready to help! What are you working on? # (10k cache read, 6k cache write) $ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude &quot;Hello&quot; Claude Code v2.1.104 Hello ● Hello! How can I help you today? are you alive? ● I&#x27;m an AI, so not alive in the biological sense — but I&#x27;m here and ready to help. What can I do for you? # (16k cache read, 20 cache write) $ git commit -m &quot;just a dummy&quot; --allow-empty [main 642ce16] just a dummy $ CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude &quot;Hello&quot; Claude Code v2.1.104 Hello ● Hello! How can I help you today? is this alive? ● Yes, I&#x27;m alive and running! Is there something I can help you with? # (16k cache read, 18 cache write) </code></pre> Note: This does not address the <i>5 minutes vs 1 hour</i> discussions from yesterday - but rather that whole discussion is pointless unless these root-causes are fixed....<p>- https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47739260 (Pro Max 5x quota exhausted in 1.5 hours despite moderate usage)<p>- https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47736476 (Anthropic downgraded cache TTL on March 6th)<p>But there has been some news on this too: https:&#x2F;&#x2F;github.com&#x2F;anthropics&#x2F;claude-code&#x2F;issues&#x2F;46829#issuecomment-4237689126<p><pre><code> At this point we have rolled out 1h prompt cache by default in a number of places for subscribers ... We also are not defaulting API customers to 1h yet -- this needs more testing to make sure it&#x27;s a net improvement on average. We will soon be changing the client side default to 1h for a few queries</code></pre>