Ledger: Claude Code Cost Dashboard
I run Claude Code around the clock on a Raspberry Pi, and I had no quick way to see what it was costing me each day. Anthropic's dashboard works, but it means opening a browser. I wanted a CLI command, an API, and a small local dashboard.
Ledger reads the JSONL session files Claude Code writes to ~/.claude/projects/, works out the cost of each conversation (including cache writes, cache reads, and per-model pricing), and serves it over a REST API. It runs as a service on the Pi and answers in Telegram.
What it does
- Reads the session files Claude Code already writes locally, so it doesn't need any external API.
- Calculates cost from input and output tokens, cache writes (1h and 5m TTL), cache reads, and each model's price.
- Serves a REST API where you can look up costs by session, project, date, or model.
- Has a terminal dashboard for a quick summary without a browser.
- Has a web dashboard with charts and per-session breakdowns.
- Answers
/costin Telegram with today's spend in under a second.
How it's built
src/currency.ts: price tables per model (Opus, Sonnet, Haiku, and so on), with a fallback price.server/pricing.ts: the cost calculation, including cache multipliers: 3.75x for 1h writes, 1.25x for 5m writes, 0.10x for reads.server/parser/: JSONL parsing, grouping messages into conversations, and working out the project name.server/analyzer/: per-session stats like cache hit rate, model usage, and web search count.server/server.ts: the Express API, on port 4200.bin/ledger.ts: the CLI and terminal UI (chalk + ink).
Usage
CLI
npm install -g @rezaiyan/ledger
ledger status # Today's spend
ledger status --short # Compact view
ledger sessions # All conversations
ledger last # Most recent session
REST API
npm run server:start
# Available endpoints:
GET /api/sessions # All parsed conversations
GET /api/sessions/:id # Single session details
GET /api/costs/today # Today's total cost
GET /api/costs/by-model # Cost breakdown by model
GET /api/projects # Cost per project
Development
npm install
npm run dev # Watch server + web bundler
npm run test # Run tests (Vitest)
npm run test:ui # Test UI dashboard
npm run build # Compile + bundle web frontend
Tests
- 20 unit tests for pricing, model matching, cache multipliers, and edge cases.
- 12 integration tests that run real JSONL files all the way through to cost totals.
- Everything runs on Vitest.
Why bother
Claude Code already keeps every session on disk. Ledger just reads it, so there are no API calls, no tokens leaving the machine, and no waiting. It works offline on the Pi and plugs into whatever I want: Telegram, a dashboard, or a script.
The pricing is easy to get wrong. If you miscount the cache, your estimate can be off by 20 to 40 percent. Ledger does the full breakdown and still handles the older session format.
Running it on a Pi
I run it as a systemd service:
sudo cp ledger.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start ledger
sudo systemctl enable ledger
The dashboard is at http://localhost:4200, and the API is reachable from anywhere on your network.
More
I wrote up why I built it and how the cache pricing works in this post.
- GitHub: rezaiyan/ledger
- npm: @rezaiyan/ledger
- License: MIT