The problem
Claude Code bills by token. One number on the invoice. You finish a two-week sprint and have no idea whether the auth refactor cost $8 or $80, or which session blew the budget.
The data is already there. Claude Code writes a JSONL log for every session, and each API call records the token counts and the active git branch. This script reads those logs and turns them into a cost table per branch.
Usage
# All projects, all time python3 branch-cost-report.py # Last 7 days python3 branch-cost-report.py --days 7 # One project python3 branch-cost-report.py --project /path/to/repo # Since a date python3 branch-cost-report.py --since 2026-03-01 # JSON output for scripting python3 branch-cost-report.py --json
Example output
Scanning /home/user/.claude/projects ... Branch Cost Share Calls Input Output Sessions -------------------------------------------------------------------- feature/payments $12.40 38.2% 423 104.2k 89.1k 3 main $10.88 33.5% 381 92.4k 78.3k 8 feature/auth $7.23 22.3% 251 61.0k 52.4k 2 fix/nav-bug $1.94 6.0% 67 16.3k 14.0k 1 -------------------------------------------------------------------- TOTAL $32.45 100.0%
What's in the kit
- ✓branch-cost-report.py — the main script. Reads
~/.claude/projects/**/*.jsonl, extracts token usage per branch, computes cost, and prints the table. Python 3.6+, stdlib only. - ✓branch-costs.md — Claude skill. Install it and use
/branch-costsinside any Claude Code session to run the report for the current project. - ✓Pricing table built into the script for Opus, Sonnet, and Haiku, including cache write and cache read rates. Update one dict if Anthropic changes pricing.
Reading the results
Cache tokens are included in the calculation. Cache writes are charged at 1.25x the input rate; cache reads are around 10x cheaper. Long conversations with cold starts account for more of the bill than most people expect.
Pricing reference
Rates the script uses (per million tokens, as of early 2026):
| Model | Input | Output | Cache write | Cache read |
|---|---|---|---|---|
| Claude Opus | $15.00 | $75.00 | $18.75 | $1.50 |
| Claude Sonnet | $3.00 | $15.00 | $3.75 | $0.30 |
| Claude Haiku | $0.25 | $1.25 | $0.30 | $0.03 |
Requirements
- ✓Python 3.6 or newer. No packages to install.
- ✓Claude Code with at least one completed session (logs must exist at
~/.claude/projects/). - ✓Works on macOS, Linux, and WSL. Wherever Claude Code runs.