u/ynu1yh24z219yq5

Claude Code Cost Analysis: Cache ReWarming Write Costs from Session Inactivity

I'm sure this is fairly widespread knowledge, but for the few of us that didn't know I thought I'd have Claude share a little bit of our deep dive into costs on some projects I've been working on. Long story short, 5 min TTL on caching means that if you often tab away and get distracted or take breaks from your current project (like I do 5-10 times per day), your costs are going to add up significantly from cache writes to rewarm up your big bloated cache (okay my caches are big and bloated, I'm sure yours aren't). I didn't really think about it too hard until I noticed my output tokens should not be costing what I was spending.

----- From Claude

Summary

In Claude Code, cache reads and writes — not output tokens — dominate API spend. The prompt cache has a 5-minute TTL. Each period of inactivity exceeding this TTL triggers a full-context cache write at 1.25× the base input rate. For sessions with frequent idle gaps, cache writes can approach or exceed cache read costs, roughly doubling the caching bill relative to a continuously-active session.

Observed Data

41-day Sonnet 4.6 session (damn! did I really use the same session for 41 days?), context cleared periodically via /clear, multiple daily idle gaps:

Component Tokens $/MTok Cost
Input 19.1K $3.00 $0.06
Output 1.1M $15.00 $16.50
Cache read 353.2M $0.30 $105.96
Cache write 27.7M $3.75 $103.88
Total $227.02

Output tokens account for ~7% of total cost. Cache operations account for ~93%.

Without caching, the ~380M tokens of repeated context would cost ~$1,140 at standard input rates. Caching reduced this to ~$210 — but the write component ($104) is nearly equal to the read component ($106), indicating frequent cache invalidation.

Mechanism

Each API call in Claude Code transmits the full prefix: system prompt, tool definitions, project configuration, and conversation history. When the cache is warm, this prefix is read at $0.30/MTok. After a >5-minute gap, the prefix must be rewritten at $3.75/MTok — 12.5× the read rate.

With an estimated 200-400 cold starts over 41 days and average context size of ~100K tokens at time of invalidation: ~300 × 100K × $3.75/MTok ≈ $112.50, consistent with the observed $104.

Mitigation

  • /compact before idle periods. Compaction summarizes conversation history, reducing context size. A 150K→20K compaction reduces the next cold-start write from ~$0.56 to ~$0.075.
  • /compact over /clear for related work. /clear guarantees a cold start with no context preservation. /compact retains relevant state in fewer tokens.
  • Minimize file reads into context. Use targeted tools (grep, head, symbol search) rather than reading entire files. Each file read persists in context and inflates every subsequent cache operation.
  • Compact proactively at ~60% context capacity rather than waiting for auto-compaction near the limit.

The single highest-leverage habit: type /compact before stepping away from the terminal.

reddit.com
u/ynu1yh24z219yq5 — 3 days ago

Alpha, Beta, Sigma, and etc. Male Wolf ideology resonates with American and machismo cultures because American culture is more like the "wolf prison" culture in the studies than the "wolves in the wild" culture we thought it was.

I was thinking about how I, as an obvious beta male, have stopped caring about fighting the alpha males in my life about being right and simply have begun to state my point, and then let them go scurrying about trying to prove themselves correct only to find that in general I had the right idea to start with.

And that got me thinking about the famous wolf studies where the Alpha/Beta/Sigma terminology come from and it's recent debunking (errr... revisions).

It turns out now that the concensus is more that what the scientists were observing was prison like conditions with totally unrelated wolves, fighting for perceived survival and scarce resources.

In the wild, wolves don't necessarily behave with such machismo and dominance. Their familial structures just don't work that way. Seemingly, they're far more democratic and each play their roles in the familial operation of pack survival.

In short, in the wild, the wolves operate with cooperation and abundance mindset. The "alpha wolf" gets mating priveleges not because he dominates everything, but because the pack agrees (my interpretation) that his genetics are desirous of passing on. Other wolves, including females get more hunting privileges and so on.

What we should be studying is American culture that has projected or read into the prison culture of wolves in captivity and then found strong parallels worth emmulating.

And I have to wonder, are we more like the open air prison that fostered the dysfunctional pack behavior in wolves?

Is America and human civilization in general just one big open air prison turning our primate brains into survivalists rather than cooperating members of an abundant environment? (Queue the hippy music and drum circle... )

reddit.com
u/ynu1yh24z219yq5 — 4 days ago

Was a good season, and there was lots of reason to hope for a solid run in the playoffs. Losing in heartbreaking fashion never feels good.

As I got to analyzing what went wrong here it seems a lot simpler and more difficult to fix than I've been reading: chemistry.

Sure there's some defensive problems with AG/PWAT injuries, and yes on offense it got 1 dimensional and predictable (although I think pretty much anyone but Gobert would have gotten beat...brilliant defensive performance by him and the rest of the wolves on the perimeter).

Basketball is a game of flow and chemistry. Those no-look passes and split second decisions don't work if you have to second guess where they're going to be or if they're the right guy to go to. Gotta feel it like Jedi power.

Championship nuggets had it.

First round exit Nuggets didn't.

Complete trust and confidence in each other... that's what Nuggets org has to get us back to. Magic, flow, chemistry.

reddit.com
u/ynu1yh24z219yq5 — 22 days ago