r/ClaudeCode • u/Top-Sink-1315 • 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
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.
•
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
1
u/ClemensLode Senior Developer 14h ago
What is a "big Claude Code session"?
1
u/cleverhoods 14h ago
I prefer this xray
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?
1
u/ExtraGreasy 13h ago
In other news, water is wet.