Skip to content

feat: prompt cache hit rate analytics panel#923

Open
vivekchand wants to merge 1 commit intomainfrom
auto/issue-851-cache-analytics
Open

feat: prompt cache hit rate analytics panel#923
vivekchand wants to merge 1 commit intomainfrom
auto/issue-851-cache-analytics

Conversation

@vivekchand
Copy link
Copy Markdown
Owner

Summary

Closes #851

  • New API endpoint GET /api/usage/cache-analytics in routes/usage.py — reads session JSONL files for cacheRead token 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.
  • New Usage tab section in 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.
  • JS wiring in clawmetry/static/js/app.js — adds loadCacheAnalytics() called from loadUsage() to fetch and render the new section.

Test plan

  • Open the Usage tab — "Prompt Cache Analytics" section appears at the bottom
  • If sessions have cache activity: hit rate % shows, green bar chart renders for the last 14 days, savings and recommendation reflect the tier
  • If no cache data: chart shows "No cache data in the last 14 days", stats show -- / $0.00
  • GET /api/usage/cache-analytics returns valid JSON with hit_ratio_pct, est_savings_usd, daily (14 entries), session_count, recommendation
  • Sessions dir not found: endpoint returns zeroed response (no 500)

https://claude.ai/code/session_01TNi2XgFsFJtFrDvhaiSFXK


Generated by Claude Code

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Prompt cache hit rate analytics

2 participants