Skip to main content

Analyze Claude Code session cache efficiency

Project description

Claude Code Cache Efficiency Analyzer

Based on https://habr.com/ru/companies/bitrix/articles/1008320/

It helps to analyze you Claude Agent SDK usage.

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

uv sync

Usage

# Analyze all sessions in ~/.claude
uv run python cli.py

# Last 5 sessions
uv run python cli.py --top 5

# Specific project
uv run python cli.py --project-name my-project

# Export metrics to JSON
uv run python cli.py --export-json metrics.json

# Analyze a specific path
uv run python cli.py ~/.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

claude_cache_analyzer-0.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_cache_analyzer-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file claude_cache_analyzer-0.1.0.tar.gz.

File metadata

  • Download URL: claude_cache_analyzer-0.1.0.tar.gz
  • Upload date:
  • Size: 15.9 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

Hashes for claude_cache_analyzer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4e328772e57e3cd9fd5a88cc215e5a033321141bbcbe491d283792f153d2419c
MD5 3f22f2af39c4eabee57508e15935d947
BLAKE2b-256 3f59e175b64eb0516cc8f1f344395ff0317685573f5748181d3172c9b3e1e884

See more details on using hashes here.

File details

Details for the file claude_cache_analyzer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: claude_cache_analyzer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 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

Hashes for claude_cache_analyzer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6ec78c650dbe0ae677bd70c0003527d438e489077abcff420029373c7a4c30d
MD5 6a76546dbe92b0d0e42dc9771a21f4a2
BLAKE2b-256 5ae982e29650bfbd0534bac263d7548c79003ccc36abb39495e681e09c3aeebc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page