Overview
Thestats-cache.json file contains pre-computed analytics about your Claude Code usage. This cache file aggregates data from all sessions to provide quick access to statistics, daily activity patterns, model-specific token usage, and cost estimates.
File Location
File Format
JSON format containing aggregated statistics across all sessions.Data Structure
StatsCache Interface
Total number of coding sessions across all time
Total number of messages (user + assistant) sent
ISO timestamp of the first recorded session
Array of daily activity metrics. See DailyActivity structure below.
Daily token usage broken down by model. See DailyModelTokens structure below.
Aggregate token usage and costs per model. Keys are model names. See ModelUsage structure below.
Message count by hour of day (0-23). Keys are hour strings.
Metadata about your longest coding session
Version of the stats cache schema
ISO timestamp of when the cache was last computed
DailyActivity Structure
Date in YYYY-MM-DD format
Total messages sent on this day
Number of sessions started on this day
Total tool invocations on this day
DailyModelTokens Structure
Date in YYYY-MM-DD format
Token counts keyed by model name (e.g.,
"claude-4.5-sonnet": 125000)ModelUsage Structure
Total input tokens consumed by this model
Total output tokens generated by this model
Tokens read from prompt cache (cheaper than regular input)
Tokens used to create prompt cache entries
Number of web search tool invocations
Estimated cost in USD for this model’s usage
Maximum context window size for this model
Maximum output token limit for this model
Loading Function
Fromsrc/lib/load-data.ts:
Returns
null if the file doesn’t exist or can’t be parsed. This is normal for new installations.Usage in Export Script
Fromscripts/export.mjs:
- Attempts to read
stats-cache.json - Logs success or failure
- Includes the parsed stats (or
null) in the export bundle
Use Cases
- Activity Heatmap:
dailyActivitypowers the GitHub-style contribution grid - Model Breakdown:
modelUsagedisplays pie charts and cost tables - Daily Token Chart:
dailyModelTokensshows stacked area charts of token consumption - Hour Distribution:
hourCountsreveals when you code most - Summary Stats:
totalSessions,totalMessages, andlongestSessionappear in stat cards
Related Data Sources
- session-meta - Individual session details
- history - Raw prompt history