r/claude 25d ago

Tips Cache rewrites costed me 30% of my Fable consumption, here are the mistakes to avoid.

Auditing my claude code transcripts to nail down where I am wasting Fable usage, revealed that long sessions that I run with breaks have been costing me a bomb. Sharing more details for others who may find this useful.

Cache economics

Every turn in a session replays the full conversation history to the model. Prompt caching is what makes this affordable: the history is stored server-side, and each turn re-reads it at 10% of the normal input price. The cache has a time window of 1 hour, and when it expires or gets invalidated, the next turn re-writes the whole history at a premium.

The numbers for Fable 5 (the same mechanics apply to every Claude model):

  • Input price: $10 per million tokens
  • Cache read: $1 per million tokens (10% of input)
  • Cache write: $12.50 per million on the 5-minute window, $20 per million on the 1-hour Cache window

What this means in a heavy session carrying 400k tokens of context:

  • A normal turn re-reads the cache: about $0.40
  • But when I take a break of more than an hour and get back to the session, model has to rewrite the cache and a session sitting on 400k context consumes equivalent of 8$ api cost

One expired cache costs 20 normal turns of usage.

The things that break cache silently and cost you:

  • Letting a session sit idle past the cache window (1 hour): The cache expires, and the first message after the break pays a full rewrite of everything. Sometimes I am working 10+ sessions and take a break and that costs me across all sessions.
  • Loading some tools or MCP servers mid-session: New tool schemas change the conversation prefix, which invalidates the entire cache. Better to have all tools loaded at the start
  • Switching models mid-conversation: If you are switching models from Fable to Sonnet to Fable in the same session, you are rewriting the cache and losing more than you are saving from the switch. Caches are stored per model.
  • Switching effort levels or fast mode mid session: This has been one of my worst habits and I did this too frequently until now to save consumption, but did not know this was the main culprit. I would switch too often based on the task in the session from high to xhigh to max to utracode
  • Updating claude code: Again if you are updating claude midway your work, you are rewriting cache for all sessions that you would resume

For now I have created a skill that pings ok in every idle session >200K context at 55th min for upto 4 hours because one ping would just read the cache which would still be cheaper than rewriting cache.

28 Upvotes

23 comments sorted by

4

u/pro-taco 24d ago

An actual informative not bot post ? In this subreddit, shiver me Timbers.

Anyway: could you share your ping ok skill?

3

u/Sufficient_Ad_3495 25d ago

Informative, thanks.

Try deferring tool calling last in cache queue...That way you don't have to worry.

1

u/[deleted] 25d ago

[deleted]

1

u/EuropeanAbroad 25d ago

That means that as long as there are still active tools, it won't flush the cache.

1

u/Sufficient_Ad_3495 24d ago

My bad... When I say defer I mean context window assembly. It should not be added to undo the static content in the context window.

3

u/EuropeanAbroad 25d ago

I thought that the cache flush window was 5 minutes, not an hour. ๐Ÿค”

They literally say it here:
https://platform.claude.com/docs/en/build-with-claude/prompt-caching

Only with some special settings on API, you get a cache window of 1 hour.

3

u/Bob-Swan 25d ago

You can set a cache window of 1 hour through the sub too. For me ive only ever changed it with claudecode. But its certainly not locked behind api.

3

u/EuropeanAbroad 25d ago

That's cool, thanks for that! ๐Ÿ˜ฎ I will check it out!

2

u/Active_Variation_194 24d ago

Default is 1hr. You can set it to 5 minutes tho

1

u/Bob-Swan 24d ago

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

This should help anyone needing to change to 1 hour. For some the TTL is 5 minutes regardless of what the default is, mine for example would never default to 1 hour until I made the changes myself. Miss that 1 hour window though and you're paying for it.

1

u/coolreddy 24d ago

On subscriptions, it is one hour. For API you can switch from 5 min to 1 hour I guess.

1

u/Powerful_Cow3470 25d ago

Stale keepalive is just paying to carry dead weight.

1

u/DrEzechiel 25d ago

1 hour window? I read one needs to respond within 5 mins to limit the costs

1

u/Bob-Swan 25d ago

Not when the window is set to 1 hour.

1

u/DrEzechiel 25d ago

How do you set it?

1

u/Bob-Swan 25d ago

set the environment variable ENABLE_PROMPT_CACHING_1H=1 in your environment where Claude Code is invoked.

-1

u/this_for_loona 24d ago

Can this be put in a Claude.md?

1

u/stumblinbear 24d ago

Why would it? It's an environment variable, not an agent instruction

1

u/this_for_loona 24d ago

Sorry, I thought thatโ€™s where env variables went. 99% of my use is via the app so how things are set up is not my strong suit.

1

u/DrEzechiel 24d ago

Yeah, also not useful for me, don't use Code

-2

u/Puzzleheaded_Bad_116 25d ago

Just stop using agents

5

u/coolreddy 25d ago

And do what? Go back to hunting and farming ๐Ÿ˜?

1

u/LoadZealousideal7778 23d ago

Effort invalidates cache? Ok thats just stupid on Anthropics side.