feat: prompt cache hit rate analytics panel#923
Open
vivekchand wants to merge 1 commit intomainfrom
Open
Conversation
Adds a dedicated cache analytics section to the Usage tab showing: - Overall cache hit rate as a percentage - Estimated cost savings (cached tokens cost ~10x less than fresh input) - Session count with cache activity - 14-day daily hit-rate bar chart - Actionable recommendation text based on hit rate tier New endpoint GET /api/usage/cache-analytics reads session JSONL files, buckets cacheRead/input token counts by session file mtime (14-day window), and returns aggregated stats. Data source is the same usage.cacheRead fields already consumed by /api/cost-split. Closes #851 Co-Authored-By: Claude <noreply@anthropic.com> https://claude.ai/code/session_01TNi2XgFsFJtFrDvhaiSFXK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #851
GET /api/usage/cache-analyticsinroutes/usage.py— reads session JSONL files forcacheReadtoken counts (same fields already used by/api/cost-split), buckets them by session file mtime over the last 14 days, computes overall hit ratio and estimated savings, and returns a tiered recommendation string.clawmetry/templates/tabs/usage.html— "💾 Prompt Cache Analytics" card with three stat cards (Hit Rate, Est. Savings, Sessions) plus a 14-day bar chart and recommendation row.clawmetry/static/js/app.js— addsloadCacheAnalytics()called fromloadUsage()to fetch and render the new section.Test plan
--/$0.00GET /api/usage/cache-analyticsreturns valid JSON withhit_ratio_pct,est_savings_usd,daily(14 entries),session_count,recommendationhttps://claude.ai/code/session_01TNi2XgFsFJtFrDvhaiSFXK
Generated by Claude Code