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

1作者: g4cg54g543 个月前原帖
简要说明:目前请使用 `CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude "Hello"` 启动,否则您将只会遇到工具阻塞,并且您的第一个后续问题将无法正常工作。 (注意:在 settings.json 中设置 includeGitInstructions=false 是一个可选项,可能更好,因为 git 状态将始终是噪音 - 但由于需要记住 "Hello",记住一个别名也很简单;D) 目前整个查询由三个可缓存的模块构成: ``` {tools | claude-version}, {system-prompt | ~/.claude/claude.md | git-status}, {skills | ./claude.md | user-prompt} ``` 环境变量将允许 system-prompt 行再次被缓存,详情请见:https://github.com/anthropics/claude-code/issues/47107。 "Hello" 使得 skills 和 ./claude.md 可以再次被缓存,详情请见:https://github.com/anthropics/claude-code/issues/47098。 之前的情况: ``` claude > alive? > -> Yes, alive and ready. What do you need? > /exit # (11k 缓存读取,6k 缓存写入) claude > are you here? > -> Yes, I'm here. What can I help you with? > /exit # (11k 缓存读取,6k 缓存写入) ^^ 没有变化,仍然缓存了 6k 写入令牌 claude > alive? > -> Yes, I'm here. What can I help you with? > /exit # (18k 缓存读取) ^^ "完全相同的问题" 确实命中缓存 git commit --allow-empty -m "Dummy" claude > alive? > -> Yes, alive and well. What do you need? > /exit # (11k 缓存读取,6k 缓存写入) ^^ 相同的问题,但现在 git 清除了缓存.... ``` 之后的情况: ``` $ 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 缓存读取,6k 缓存写入) $ 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 缓存读取,20 缓存写入) $ 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 缓存读取,18 缓存写入) ``` 注意:这并没有解决昨天的 <i>5分钟与1小时</i> 讨论,但如果不解决这些根本原因,整个讨论都是毫无意义的.... - https://news.ycombinator.com/item?id=47739260 (Pro Max 5倍配额在1.5小时内耗尽,尽管使用量适中) - https://news.ycombinator.com/item?id=47736476 (Anthropic在3月6日降低了缓存TTL) 但对此也有一些新消息:https://github.com/anthropics/claude-code/issues/46829#issuecomment-4237689126 ``` 此时,我们在多个地方为订阅用户默认推出了1小时的提示缓存... 我们尚未将API客户默认设置为1小时 - 这需要更多测试,以确保平均而言这是一个净改善。 我们将很快将客户端默认设置更改为1小时,以便处理一些查询。 ```
查看原文
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>