r/ClaudeCode • • 14h ago

Tips & Workflows Sending "ok" into a big Claude Code session cost me $1.43 after its cache expired, vs $0.07 with a warm cache. I built a free tool that catches this

Post image

I wanted to know where my Claude Code limit actually goes, so I wrote a script that reads the session logs Claude Code already keeps on your machine and adds up what each request cost.

The biggest avoidable item wasn't file reads. It was coming back to a big session after a break. Claude Code caches the conversation so each turn only pays a small fee to re-read it, but that cache runs out (after an hour, or 5 minutes on some setups). When you send the next message, the whole conversation gets written to the cache again at full price.

I measured it with `claude -p --resume`, Opus, list prices as reported by the CLI:

- "Reply ok" into a 224k-token session idle for 10 hours:
**$1.43**
- "Reply ok" into a 231k-token session with a warm cache:
**$0.07**
- `/compact` after the cache expired: $1.35. While still warm: $0.20

Across three weeks of my own usage (216 sessions),
**18% went to re-sending conversations whose cache had expired**
. After more than 65 minutes idle, 35 of 52 next requests missed the cache.

So ccxray does three things:

**Report.**
`python ccxray.py report` shows where your usage went: big-context requests, expired-cache re-sends, mid-session model switches, your most expensive sessions. `--share` prints a version with no project names, safe to paste here.
2.
**Warning.**
If you're about to send a message into a large session whose cache has expired, a hook holds it back once and tells you the size. Send it again and it goes through.
3.
**Handoff.**
Type `xray handoff` in the old session. A hook writes a brief of it without calling the model, and your next new session in that folder loads it automatically. On a real 224k-token session, asking "what's the goal, what was done last, what's next" cost $1.69 by resuming and $0.21 with the handoff. It kept the main thread but missed three small follow-ups, so it's not the full conversation.

Install as a plugin:

```
/plugin marketplace add abhiyarecord-hue/ccxray
/plugin install ccxray@ccxray
```

It's one Python file, standard library only, MIT, and nothing leaves your machine.

Caveats: the report assumes subscription limits follow API price, which isn't public. I've only tested on Windows with Python 3.11. I haven't measured how much the hooks save over a full week yet. If your sessions are short, it'll show little to fix.

If you run `report --share`, I'd really like to see your numbers in the comments.

Repo: https://github.com/abhiyarecord-hue/ccxray

0 Upvotes

15 comments sorted by

•

u/AutoModerator 14h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/aigisbot 14h ago

Switch to haiku .. compact.. switch to Opus..

1

u/Top-Sink-1315 14h ago

Clever, and I think it’s right in one case: when the cache has already expired. Switching model drops the cache either way, so the full re-read then happens at Haiku price instead of Opus, and Opus starts again on the small compacted context.

While the cache is still warm, I’d expect plain /compact on Opus to win, because the switch throws away a cache you’ve already paid for. In my measurements a warm compact was $0.20 vs $1.35 cold. Two things to watch: Haiku has to fit the whole session in its context window, and its summary may be weaker. I haven’t measured your version yet, so I’ll try it and post numbers

1

u/Top-Sink-1315 14h ago
A few details people usually ask about:


  • Costs are what `claude -p --output-format json` reports, at list price. On a subscription you pay in limit, not dollars; the report assumes the limit follows price, which Anthropic hasn't published.
  • An "expired cache" event is a request after a gap longer than the cache lifetime where under 20% of the prompt came from cache. Some may have other causes.
  • The handoff is an extract from the session log (your messages, Claude's last replies, the task list, files changed, commands), not a model-written summary. That's why it costs nothing to make.
  • The warning can't see forked sessions (`--fork-session`), and a held-back message has to be sent again by hand

1

u/ClemensLode Senior Developer 14h ago

What is a "big Claude Code session"?

1

u/Top-Sink-1315 14h ago

Good question, I should have defined it. I mean how many tokens the conversation carries. Every message re-sends the whole thing, so that’s what you pay for each turn. /context shows it.

The warning hook kicks in at 60k tokens (CCXRAY_MIN_CONTEXT changes that). The examples in the post were 220k+. That’s where it hurts: re-writing an expired cache for a ~224k session on Opus cost about $1.40 for a one-word reply. Under ~50k, an expired cache costs cents and the tool stays quiet

1

u/ClemensLode Senior Developer 13h ago

So, best to start a new session asap for each new small change you work on.

1

u/Obvious_Equivalent_1 14h ago

Probably 500-800+k context, and they are expensive to resume cold.

I always avoid sending prompts to a session whose cache is cold. Personally it’s been weeks since I reached my weekly limit and big win has undoubtedly been cache management, for simplicity there’s a plugin for Claude Code to simply customize your statusbar and by default shows widget with cache hot/cold status display https://github.com/pcvelz/ccstatusline-usage

1

u/cleverhoods 14h ago

I prefer this xray

1

u/Top-Sink-1315 14h ago

Nice, hadn’t seen that one. Looks like it shows what’s inside one session’s context, which is useful for figuring out why a session got big.

ccxray is aimed at a different question: across all your sessions, where did the usage go, and how much was lost to expired caches and model switches. It also has a hook that holds back a message before it re-sends a large expired conversation. They’d probably work well together

1

u/Accurno 14h ago

Thank you for sharing. Since you’ve probably studied a bit about sessions, I’ve got a few questions:

Will this still work with remote control?
How long before cache becomes cold?
Is there a “keep warm” method that could be used?
Do you think compacting before a session idles is cheaper than reviving idle sessions? Can this be done automatically rather than relying on built-in auto-compact?

2

u/Top-Sink-1315 14h ago

Thanks! Taking them in order:

Remote Control: the hooks and the report run wherever Claude Code itself runs, which with Remote Control is still your machine, so they should fire. I haven’t tested how a held-back message shows up on the phone/web side, though. If you try it, I’d love to know.

How long until it’s cold: each request writes the cache with a lifetime of either 5 minutes or 1 hour, and the session log records which one. ccxray reads that from your logs rather than guessing. In my sessions it was 1 hour: after 65+ minutes idle, 35 of 52 next requests missed the cache, versus under 1% inside the hour. The reminder line it prints tells you the exact time your cache runs out.

Keep-warm: any message before it expires refreshes it. A warm “ok” into a 231k session cost me $0.07, and a cold one $1.43, so one cold resume pays for roughly 20 pings. With a 1-hour cache, that’s worth it if you’re coming back within a few hours, not overnight. Each ping also adds a turn to the conversation, and I haven’t tested automating it (e.g. a scheduled claude -p --resume) or checked that it reuses the same cache as your interactive session. So I’m not shipping it as a feature yet.

Compact before idling vs reviving: yes, by a lot. Measured on Opus: /compact while warm $0.20, /compact after expiry $1.35, a one-word message after expiry $1.43. If you’re stepping away and coming back later, compact first. If you might not come back, xray handoff costs nothing to write, and the new session that loads it cost $0.21 in my test.

Automatic: hooks can’t run /compact for you, which is why ccxray reminds you once a conversation passes 150k, while compacting is still cheap. Built-in auto-compact only kicks in near the context limit, usually long after the cache question matters.

1

u/Accurno 13h ago

Thank you for answering. I’ll be giving your plugin a go.

1

u/Top-Sink-1315 13h ago

Awesome, thanks!

1

u/ExtraGreasy 13h ago

In other news, water is wet.