Skip to main content

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

Metadata

Release files for claude-cache-analyzer 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claude-cache-analyzer 0.1.3
File Size Uploaded
claude_cache_analyzer-0.1.3.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for claude-cache-analyzer 0.1.3
File Interpreter ABI Platform
claude_cache_analyzer-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 33.5 kB

Release files / claude_cache_analyzer-0.1.3.tar.gz

Download URL claude_cache_analyzer-0.1.3.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f643269f47920884b90e8790d7359a7a0b291d9de621372e59166804d9935d6
BLAKE2b-256 checksum
How to use checksums
cbe8e98cb8a3825f978f7c7ad1e14f99cf6e09296c5e721d0fb5f4af3ae0672c
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / claude_cache_analyzer-0.1.3-py3-none-any.whl

Download URL claude_cache_analyzer-0.1.3-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a6d458bdcc65af49897461b4ab9ba161c796c771e848dbfab6ab9e4cd845132
BLAKE2b-256 checksum
How to use checksums
cfa9e1dc540f5169f383cbcb156f2325f4fbc2c93f0e26b6745712e3478e1b1b
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page