feat: add cache compounding savings to rtk gain#261
feat: add cache compounding savings to rtk gain#261sahilmgandhi wants to merge 6 commits intortk-ai:masterfrom
Conversation
f0bf678 to
4aef192
Compare
Show how direct token savings compound through Claude Code's prompt caching. Saved tokens avoid a 1.25x cache write plus 0.1x cache read on every subsequent turn, producing a multiplier based on average session length (scanned from JSONL session files). New section appears after the "By Command" table with multiplier, effective savings, and optional dollar amounts (when ccusage installed). Gracefully degrades: falls back to 20-turn estimate when no session data, omits section entirely on failure. - New module: src/session_stats.rs (8 unit tests) - Export WEIGHT_* constants from cc_economics.rs - Add cache_compounding field to JSON/CSV export - Remove dead BILLION constant, consolidate color helpers
4aef192 to
fc2f85e
Compare
|
Hi, this PR has conflicts with master. Could you rebase on current master? Thanks! |
Resolve conflicts in src/gain.rs: keep both cache compounding functions (branch) and project scope functions (master).
|
Rebased and verified all tests passed. |
|
Hi @sahilmgandhi, the graceful degradation chain is excellent throughout: missing sessions fall back to defaults, missing ccusage skips the dollar amount, any error silently skips the section. That's the right design. Two things to discuss before we move forward:
Happy to discuss the right framing for the multiplier. |
This makes sense, it isn't the true cache savings, but the theoretical max. Let me change it to that.
Let me think about this one a bit, limiting to 50 would mean some savings won't show up. Maybe what I can do is something like:
|
8911446 to
a8fe88a
Compare
Update test_try_parse_git_with_dash_c to expect success since master now supports git global options (-C, -c, etc.).
a8fe88a to
71b7a20
Compare
I think more importantly than just the immediate savings of
rtk, it also offers compounding savings in the form of less cache thrashing. This is helpful both from a monetary perspective (cache writes/reads cost money) and also from a time perspective (fewer tokens from cache => less thinking => less time for output** (potentially))Summary
How it works
When RTK removes tokens from command output, those tokens:
For a session with 336 avg turns (median position = 168 remaining), the multiplier is
1.25 + 0.1 × 168 = 18.06x.Example output
Graceful degradation
Files changed
src/session_stats.rssrc/cc_economics.rsWEIGHT_*constants aspub(crate), remove deadBILLIONsrc/main.rsmod session_statssrc/gain.rsTest plan