Tell HN: Claude-code prompt-cache workaround/fix

10 hours ago

TLDR: for now launch using `CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude "Hello"`

(Note: setting includeGitInstructions=false in settings.json is an option to and likely the better thing anyhow since that git-status will always be noise....)

Currently the whole query is build from 3 cache-able blocks:

  {tools | claude-version}, 
  {system-prompt | ~/.claude/claude.md | git-status},
  {skills | ./claude.md | user-prompt}

the env-var will allow the system-prompt line go get cached again https://github.com/anthropics/claude-code/issues/47107

the "Hello" allows skills & ./claude.md to get cached again https://github.com/anthropics/claude-code/issues/47098

otherwise you will only ever hit on the tools-block, and your first follow-up-question

Before:

  claude
  > alive?
  > -> Yes, alive and ready. What do you need? 
  > /exit
  # (11k cache read, 6k cache write)

  claude
  > are you here?
  > -> Yes, I'm here. What can I help you with? 
  > /exit
  # (11k cache read, 6k cache write)
  ^^ nothing changed, still cashed 6k write tokens

  claude
  > alive?
  > -> Yes, I'm here. What can I help you with?  
  > /exit
  # (18k cache read)
  ^^ the "exact same question" DOES hit the cache
  
  git commit --allow-empty -m "Dummy"
  claude
  > alive?
  > -> Yes, alive and well. What do you need?
  > /exit
  # (11k cache read, 6k cache write)
  ^^ same question, but now git busts the cache....


After:

  $ 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)




Note: This does not address the 5 minutes vs 1 hour discussions from yesterday - but rather that whole discussion is pointless unless these root-causes are fixed....

- https://news.ycombinator.com/item?id=47739260 (Pro Max 5x quota exhausted in 1.5 hours despite moderate usage)

- https://news.ycombinator.com/item?id=47736476 (Anthropic downgraded cache TTL on March 6th)