claude-code - 💡(How to fix) Fix [BUG] new sessions will **never** hit a (full)cache [6 comments, 5 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47098Fetched 2026-04-13 05:41:32
View on GitHub
Comments
6
Participants
5
Timeline
14
Reactions
1
Author
Timeline (top)
commented ×6cross-referenced ×5labeled ×3

Error Message

Error Messages/Logs

Code Example

Traffic-inspection shows

"messages": [
 {
  "role": "user",
  "content": [
   {
    "type": "text",
    "text": "<system-reminder>\nThe following skills are available ...."
   },
   {
    "type": "text",
    "text": "<system-reminder>\nAs you answer the user's questions, you can use the following context:\n# claudeMd\n...."
   },
   {
    "type": "text",
    "text": "alive?",
    "cache_control": {
     "type": "ephemeral"
    }
   }
  ]
 }
],

---

claude
> alive?
> -> Yes, alive and ready. What do you need? 
# (11k cache read, 6k cache write)
> nice
> -> What are we working on? 
# (18k cache read, 19 cache write)
> /exit

---

claude
> alive?
> -> Yes, I'm here. What can I help you with?  
# (18k cache read)
> /exit

---

claude
> are you here?
> -> Yes, I'm here. What can I help you with? 
# (11k cache read, 6k cache write)
RAW_BUFFERClick to expand / collapse

What's Wrong?

relaunching claude / clearing the session costs 6505 cache-create tokens even after "just seconds" and super short messages (so this is not about the ongoing 5 minutes vs 1 hour discussion!)

What Should Happen?

assuming no changes where made (looking at you CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS destroying the system-prompt...) relaunch/clear should be a 99% cachehit. but neither skills nor project/CLAUDE.md get cached:

Error Messages/Logs

Traffic-inspection shows

"messages": [
 {
  "role": "user",
  "content": [
   {
    "type": "text",
    "text": "<system-reminder>\nThe following skills are available ...."
   },
   {
    "type": "text",
    "text": "<system-reminder>\nAs you answer the user's questions, you can use the following context:\n# claudeMd\n...."
   },
   {
    "type": "text",
    "text": "alive?",
    "cache_control": {
     "type": "ephemeral"
    }
   }
  ]
 }
],

Steps to Reproduce

Have a statusline show/log you usage.

claude
> alive?
> -> Yes, alive and ready. What do you need? 
# (11k cache read, 6k cache write)
> nice
> -> What are we working on? 
# (18k cache read, 19 cache write)
> /exit
claude
> alive?
> -> Yes, I'm here. What can I help you with?  
# (18k cache read)
> /exit
claude
> are you here?
> -> Yes, I'm here. What can I help you with? 
# (11k cache read, 6k cache write)

-> note that the two string-matched "alive?"´s do hit, so one can start every claude session with a claude "Hello" and then do the actual work to get the full cache hits ? 🤔 but the "two different questions" gets a 6k token penalty

-> the "initial 11k" is likely some publicly shared tool cache that is hit.

there is no cache marker between system-prompt-part1 (base-prompt + user/CLAUDE.md) and the first user message. but a whole lot of tokens for skills, and system-prompt-part2 (memory + project/CLAUDE.md)

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.104

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Xterm

Additional Information

also came across the discussion here https://news.ycombinator.com/item?id=47740381 "keeping your context small" (and clearing often) is(used to?) be the way to go - but without cachepoint the reverse would be true? -> more compute for you, less expensive for users - what sounds wrong...

Note that this is especially NOT about the 5-minute vs 1 hour discussion, the claude launches above where all within 15 seconds ;)

extent analysis

TL;DR

Starting a Claude session with a cache-hitting message, like "Hello", may help reduce the cache-create token cost.

Guidance

  • Investigate the absence of a cache marker between the system-prompt-part1 and the first user message, as this might be causing the high token penalty.
  • Consider adding a cache marker or a similar mechanism to improve cache hits for subsequent messages.
  • Review the discussion on keeping context small and clearing often, as this might be related to the caching behavior.
  • Test the hypothesis that starting with a cache-hitting message can consistently reduce the token cost.

Example

No code snippet is provided, as the issue does not contain explicit code or APIs that can be used to create a concrete example.

Notes

The provided information suggests that the issue is related to the caching behavior of the Claude model, but the exact cause is unclear. Further investigation is needed to determine the root cause and develop a reliable solution.

Recommendation

Apply a workaround by starting Claude sessions with a cache-hitting message, like "Hello", to potentially reduce the cache-create token cost. This approach may help mitigate the issue until a more permanent solution is found.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] new sessions will **never** hit a (full)cache [6 comments, 5 participants]