Daily AI usage cost analysis with before/after comparison and model health signals
Project description
ai-cost-compare
Daily AI spend (Claude Code, Cursor), before/after windows, and model routing health — in your terminal.
Turn local usage data into three Rich tables: daily cost, split-window comparison, and per-model verdicts. Claude via ccusage; Cursor via dashboard CSV (or optional API token).
Not a ccusage fork — an interpretation layer on top. ccusage reports what you spent; this CLI adds before/after windows, mix shifts, and routing health verdicts.
Quick start · Demo · ccusage vs this tool · 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.
🔀 ccusage vs this tool
| ccusage | ai-cost-compare | |
|---|---|---|
| Role | Usage analytics — read local logs, report spend | Interpretation layer — explain what changed and if routing looks healthy |
| Scope | Many agents, daily/weekly/monthly/session views | Claude Code focus: before/after split + model mix verdicts |
| Output | Descriptive tables & totals | Daily cost + Before vs After + Real Signal (Opus/Sonnet/Haiku) |
| Install both? | ✅ Required (data source) | ✅ Optional companion on top |
Use ccusage for “what did I spend?” Use this when “did something break after I changed config on Tuesday?”
🖥 Demo
Sample fixture output · --range 7 --cutoff 2026-05-08
Same output as plain text
ai-cost-compare --range 7 --cutoff 2026-05-08
CLAUDE DAILY COST · 2026-05-06 → 2026-05-08
┌─────────────┬────────┬───────────┬────────┬───────────┬──────┬────────┬──────┐
│ Date │ Era │ Cost │ Tokens │ Mix │ Opus │ Sonnet │ Haiku│
├─────────────┼────────┼───────────┼────────┼───────────┼──────┼────────┼──────┤
│ 2026-05-06 │ Before │ $2.68 │ 3.2M │ ████████… │ 100% │ 0% │ 0% │
│ 2026-05-07 │ Before │ $24.26 │ 49.0M │ ████████… │ 87% │ 0% │ 13% │
│ 2026-05-08 │ Today │ $80.88 │ 117.9M │ ████████… │ 97% │ 0% │ 3% │
└─────────────┴────────┴───────────┴────────┴───────────┴──────┴────────┴──────┘
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 ai-cost-compare
# or
uv tool install ai-cost-compare
3. Run:
ai-cost-compare --range 5
📦 Install
PyPI / uv
pip install ai-cost-compare
uv tool install ai-cost-compare
uvx ai-cost-compare --help # run without installing
Homebrew
brew tap mazulo/ai-cost-compare https://github.com/mazulo/ai-cost-compare
brew install ai-cost-compare
npm install -g ccusage # still required
One-liner (no tap):
brew install https://raw.githubusercontent.com/mazulo/ai-cost-compare/main/Formula/ai-cost-compare.rb
Requirements
- Python 3.11+ (pip/uv) or Homebrew
- ccusage on your
PATH(v18+; v20periodJSON field supported)
📖 Usage
Claude Code (default)
ai-cost-compare and ai-cost-compare claude are equivalent. Legacy installs: claude-cost-compare / cccompare still work.
# Last 5 days vs today (default)
ai-cost-compare --range 5
# 7-day window split at a specific date
ai-cost-compare claude --range 7 --cutoff 2026-05-13
# Daily summary only — skip comparison tables
ai-cost-compare --summary --since 2026-05-01
Requires ccusage on your PATH.
Cursor IDE
Option A — CSV export:
- Go to cursor.com/dashboard/usage and export a CSV
- Run:
ai-cost-compare cursor --file ~/Downloads/usage.csv --range 7 --cutoff 2026-05-13
Option B — session token (auto-fetch):
- Install the API extra:
pip install 'ai-cost-compare[cursor-api]' - Open any cursor.com page while logged in
- Open browser DevTools → Application → Cookies →
cursor.com - Copy the value of
WorkosCursorSessionToken - Add it to
~/.config/ai-cost-compare/config.toml(created automatically on first run):
[cursor]
session_token = "paste-your-token-here"
- Run:
ai-cost-compare cursor --range 5
The config file is created with instructions the first time you run ai-cost-compare cursor.
Shared 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 | |
--file |
-f |
Cursor only: path to exported CSV |
--cursor-token |
Cursor only: session token (overrides config) |
🧠 How it works
flowchart LR
P[Provider] --> B[Parser]
B --> C[Window stats]
C --> D[Before / After deltas]
C --> E[Model verdicts]
D --> F[Rich terminal report]
E --> F
- Provider —
claude(ccusage JSON) orcursor(CSV / optional API). - Parse — normalizes dates, costs, and per-model buckets (provider taxonomy).
- Analyze — splits records at
--cutoff, computes averages and mix shifts. - Verdict — provider-specific routing health rules.
- Render — Rich tables with era labels, mix bars, and color-coded costs.
🛠 Development
git clone https://github.com/mazulo/ai-cost-compare.git
cd ai-cost-compare
uv sync --dev
uv run pytest
uv run ai-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/ai_cost_compare/__init__.py, push to main, then run the Publish workflow from GitHub Actions. It will:
- Run tests and publish to PyPI
- Update the Homebrew formula checksum
- Create a git tag and GitHub Release
- Refresh Homebrew Python resources on macOS
Details: docs/RELEASING.md
📄 License
MIT — see LICENSE.
Built for developers who want spend visibility across Claude Code and Cursor without leaving the terminal.
⭐ Star on GitHub if this saves you from an Opus routing surprise.
Project details
Release history Release notifications | RSS feed
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 ai_cost_compare-0.3.2.tar.gz.
File metadata
- Download URL: ai_cost_compare-0.3.2.tar.gz
- Upload date:
- Size: 644.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc6da1afb0a53c64b70ce86702e10aa6f721167ea8e6671befb5528b68f71b15
|
|
| MD5 |
6157fa2e630cb59a4ac968775a2de2d1
|
|
| BLAKE2b-256 |
5df41adce4384f0cd25285942c8f2c40ee12774a0b57ac7941ffbb1b882c1f95
|
Provenance
The following attestation bundles were made for ai_cost_compare-0.3.2.tar.gz:
Publisher:
publish.yml on mazulo/ai-cost-compare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_cost_compare-0.3.2.tar.gz -
Subject digest:
bc6da1afb0a53c64b70ce86702e10aa6f721167ea8e6671befb5528b68f71b15 - Sigstore transparency entry: 1914449800
- Sigstore integration time:
-
Permalink:
mazulo/ai-cost-compare@6200b9d619c1c089b5c835b720f5a4721c67c46c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mazulo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6200b9d619c1c089b5c835b720f5a4721c67c46c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ai_cost_compare-0.3.2-py3-none-any.whl.
File metadata
- Download URL: ai_cost_compare-0.3.2-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
506e225a37256903e83320023e24e6362301ebe2dd2c39c8b919635826437814
|
|
| MD5 |
9dd1609c74fb16f835317738848af2f7
|
|
| BLAKE2b-256 |
efc600d0824b6695669a9d6a2b3d96da4c59e6f3c080f8141a2c252b73f0c5a0
|
Provenance
The following attestation bundles were made for ai_cost_compare-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on mazulo/ai-cost-compare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_cost_compare-0.3.2-py3-none-any.whl -
Subject digest:
506e225a37256903e83320023e24e6362301ebe2dd2c39c8b919635826437814 - Sigstore transparency entry: 1914449863
- Sigstore integration time:
-
Permalink:
mazulo/ai-cost-compare@6200b9d619c1c089b5c835b720f5a4721c67c46c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mazulo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6200b9d619c1c089b5c835b720f5a4721c67c46c -
Trigger Event:
workflow_dispatch
-
Statement type: