Skip to main content

Daily Claude cost analysis with before/after comparison and model health signals

Project description

claude-cost-compare

Daily Claude spend, before/after windows, and model routing health — in your terminal.

PyPI Python CI License: MIT

Turn local ccusage data into three Rich tables: daily cost, split-window comparison, and per-model verdicts.

Quick start · Demo · Install · Usage · How it works


✨ Why this exists

Claude Code usage can spike fast — especially when Opus routing leaks or Sonnet/Haiku tiers stop doing their job. This CLI answers three questions at a glance:

Question Table
What did I spend each day? Daily cost — cost, tokens, model mix
Did things change after a date? Before vs After — avg/day, totals, mix shift
Are models routed correctly? Real Signal — Opus / Sonnet / Haiku verdicts

No cloud upload. Reads your local ccusage JSON and prints a terminal report.


🖥 Demo

claude-cost-compare terminal output showing daily cost, before/after comparison, and model health verdicts

Sample fixture output · --range 7 --cutoff 2026-05-08

Same output as plain text
claude-cost-compare --range 7 --cutoff 2026-05-08
CLAUDE DAILY COST  ·  2026-05-06 → 2026-05-26
┌─────────────┬────────┬───────────┬────────┬───────────┬──────┬────────┬──────┐
│ Date        │ Era    │      Cost │ Tokens │ Mix       │ Opus │ Sonnet │ Haiku│
├─────────────┼────────┼───────────┼────────┼───────────┼──────┼────────┼──────┤
│ 2026-05-06  │ Before │     $2.68 │   3.2M │ ████████… │ 100% │     0% │   0% │
│ 2026-05-08  │ Today  │    $80.88 │ 117.9M │ ████████… │  97% │     0% │   3% │
│ 2026-05-09  │ After  │     $9.92 │  12.1M │ ████████… │  45% │    55% │   0% │
└─────────────┴────────┴───────────┴────────┴───────────┴──────┴────────┴──────┘

BEFORE vs AFTER  ·  Split at 2026-05-08
REAL SIGNAL      ·  Post-2026-05-08 · per-model routing verdicts

🚀 Quick start

1. Install ccusage (peer dependency — reads your local usage data):

npm install -g ccusage

2. Install the CLI:

pip install claude-cost-compare
# or
uv tool install claude-cost-compare

3. Run:

claude-cost-compare --range 5

📦 Install

PyPI / uv

pip install claude-cost-compare
uv tool install claude-cost-compare
uvx claude-cost-compare --help          # run without installing

Homebrew

brew tap mazulo/claude-cost-compare https://github.com/mazulo/claude-cost-compare
brew install claude-cost-compare
npm install -g ccusage                  # still required

One-liner (no tap):

brew install https://raw.githubusercontent.com/mazulo/claude-cost-compare/main/Formula/claude-cost-compare.rb

Requirements

  • Python 3.11+ (pip/uv) or Homebrew
  • ccusage on your PATH

📖 Usage

# Last 5 days vs today (default)
claude-cost-compare --range 5

# 7-day window split at a specific date
claude-cost-compare --range 7 --cutoff 2026-05-13

# Full billing period from a start date
claude-cost-compare --since 2026-05-01 --cutoff 2026-05-13

# Daily summary only — skip comparison tables
claude-cost-compare --summary --since 2026-05-01

# Plain output (also respects NO_COLOR)
claude-cost-compare --plain --range 5

Flags

Flag Short Description
--range -r Days before cutoff for the "before" window (default: 5)
--cutoff -c Before/after split date YYYY-MM-DD (default: today)
--since -s Explicit start date — overrides --range
--summary Daily cost table only
--plain Disable color

🧠 How it works

flowchart LR
  A[ccusage JSON] --> B[Parser]
  B --> C[Window stats]
  C --> D[Before / After deltas]
  C --> E[Model verdicts]
  D --> F[Rich terminal report]
  E --> F
  1. Fetch — shells out to ccusage for daily usage JSON (NVM-aware discovery).
  2. Parse — normalizes dates, costs, and per-model breakdowns.
  3. Analyze — splits records at --cutoff, computes averages and mix shifts.
  4. Verdict — flags Opus routing leaks, low Sonnet share, Haiku usage patterns.
  5. Render — Rich tables with era labels, mix bars, and color-coded costs.

🛠 Development

git clone https://github.com/mazulo/claude-cost-compare.git
cd claude-cost-compare
uv sync --dev
uv run pytest
uv run claude-cost-compare --range 5

Regenerate the README demo SVG after UI changes:

uv run python scripts/export_demo.py

🚢 Releasing

Bump version in pyproject.toml and src/claude_cost_compare/__init__.py, push to main, then run the Publish workflow from GitHub Actions. It will:

  1. Run tests and publish to PyPI
  2. Update the Homebrew formula checksum
  3. Create a git tag and GitHub Release
  4. Refresh Homebrew Python resources on macOS

Details: docs/RELEASING.md


📄 License

MIT — see LICENSE.


Built for Claude Code power users who want spend visibility without leaving the terminal.

⭐ Star on GitHub if this saves you from an Opus routing surprise.

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_cost_compare-0.1.1.tar.gz (37.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_cost_compare-0.1.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file claude_cost_compare-0.1.1.tar.gz.

File metadata

  • Download URL: claude_cost_compare-0.1.1.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for claude_cost_compare-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aa3dee8eeb3df63a38342e83f5b486832a263c118428d5db6baa2757aaa966de
MD5 6b68d6af3b8e0f6da23d8f2f8a38bde9
BLAKE2b-256 9c80b620198d9a33306af7909f917c2d2d1c9fce38b009c9cb55fe4b650c97a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_cost_compare-0.1.1.tar.gz:

Publisher: publish.yml on mazulo/claude-cost-compare

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claude_cost_compare-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_cost_compare-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f9cea87d671f6bc596f591081d79254441600a5b25511eab837a3651408f373
MD5 c18b1a56af6201c0a537584ec4934da1
BLAKE2b-256 1c4e72dd72a7bb77cc9b2f065c98cd72af370f805ee5231c95e85a6b54a4d291

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_cost_compare-0.1.1-py3-none-any.whl:

Publisher: publish.yml on mazulo/claude-cost-compare

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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