Analyze Claude Code session cache efficiency
Project description
Claude Code Cache Efficiency Analyzer
Based on https://habr.com/ru/companies/bitrix/articles/1008320/
CLI tool that reads Claude Code JSONL session files, computes prompt cache efficiency metrics using the Bitrix24/Habr formula, and displays results as rich terminal tables.
Formula
C = S × [(1−h) × P_miss + h × P_hit] + D × P_miss + O × P_out
Where: S = cacheable tokens, h = hit rate, D = dynamic input tokens, O = output tokens.
Install & Run
Via uvx (no install needed)
uvx claude-cache-analyzer
Via pip
pip install claude-cache-analyzer
claude-cache
From source
git clone https://github.com/AgiMateIo/claude-cache-analyzer.git
cd claude-cache-analyzer
uv sync
uv run python cli.py
Sample Output
╭──────────────────────────────────────────────────╮
│ Claude Code · Cache Efficiency Report │
│ Project: all projects · 3 sessions analysed │
╰──────────────────────────────────────────────────╯
Summary
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Metric ┃ Value ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ Total actual cost │ $2.0190 │
│ Cost without cache │ $6.9472 │
│ Total savings │ $4.9283 │
│ Net savings (after write overhead) │ $4.7206 │
│ Savings % │ 70.9% │
│ Avg cache hit rate │ 85.5% │
│ Avg efficiency score │ 0.85 │
└────────────────────────────────────┴─────────┘
╭─────────────────────────── Tips ────────────────────────────╮
│ • Excellent hit rate (85.5%)! Cache is working efficiently. │
╰─────────────────────────────────────────────────────────────╯
Usage
Usage: claude-cache-analyzer [OPTIONS] [PROJECT_PATH]
Analyze Claude Code prompt cache efficiency.
Arguments:
[PROJECT_PATH] Root of Claude data (~/.claude) or a specific project directory.
Options:
-p, --project-name TEXT Filter by project directory name.
-n, --top INTEGER Show only the N most recent sessions.
--min-turns INTEGER Minimum number of turns to include a session. [default: 1]
-s, --session TEXT Show detailed view for a specific session (full or partial ID).
-g, --group-by-project Group results by project.
--export-json PATH Export raw metrics to a JSON file.
--version Show version.
-h, --help Show this message and exit.
Examples
# Analyze all sessions in ~/.claude
claude-cache-analyzer
# Last 5 sessions
claude-cache-analyzer --top 5
# Specific project
claude-cache-analyzer --project-name my-project
# Detailed view of a specific session (full or partial ID)
claude-cache-analyzer -s abcd1234
# Group by project
claude-cache-analyzer -g
# Export metrics to JSON
claude-cache-analyzer --export-json metrics.json
# Analyze a specific path
claude-cache-analyzer ~/.claude/projects/abc123
Metrics
| Metric | Description |
|---|---|
| Cache hit rate | cache_read / (cache_creation + cache_read) |
| Actual cost | Real cost with cache pricing applied |
| Cost without cache | Hypothetical cost if all tokens were at input price |
| Savings | cost_no_cache - actual_cost |
| Net savings | Savings minus cache write overhead |
| Efficiency score | hit_rate × (cacheable / (input + cacheable)) — range [0..1] |
Grades
| Grade | Efficiency Score |
|---|---|
| A | ≥ 0.70 |
| B | ≥ 0.50 |
| C | ≥ 0.30 |
| D | ≥ 0.10 |
| F | < 0.10 |
Tests
uv run pytest -v
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_cache_analyzer-0.1.3.tar.gz.
File metadata
- Download URL: claude_cache_analyzer-0.1.3.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f643269f47920884b90e8790d7359a7a0b291d9de621372e59166804d9935d6
|
|
| MD5 |
cf5258369ebb7ba6b8005635b8a5ccc3
|
|
| BLAKE2b-256 |
cbe8e98cb8a3825f978f7c7ad1e14f99cf6e09296c5e721d0fb5f4af3ae0672c
|
File details
Details for the file claude_cache_analyzer-0.1.3-py3-none-any.whl.
File metadata
- Download URL: claude_cache_analyzer-0.1.3-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a6d458bdcc65af49897461b4ab9ba161c796c771e848dbfab6ab9e4cd845132
|
|
| MD5 |
355253c6088cf14d3bbd1b98d2fde7d6
|
|
| BLAKE2b-256 |
cfa9e1dc540f5169f383cbcb156f2325f4fbc2c93f0e26b6745712e3478e1b1b
|