Local web app to explore Claude Code API cost and token usage by day, session, and turn
Project description
Claude Code Cost Explorer
A local web app that reads your Claude Code conversation files in your local machine and shows you API cost and token usage — broken down by day, session, and individual message turn.
No data leaves your machine. No API key needed. Reads directly from ~/.claude/.
Screenshots
Navigation flow: Day view → click a date → Session list → click a session → Turn-by-turn breakdown
Each turn is a hyperlink:
- Conversation turns → full user message + full assistant response (with collapsible thinking blocks)
- Tool call turns →
[tool: Bash]or[3 tools: Read, Write, Glob]→ input params + raw output
Prerequisites
- uv — install once, handles everything else:
- macOS / Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh - Windows:
winget install astral-sh.uv
- macOS / Linux:
- Claude Code installed and used at least once (so
~/.claude/projects/exists)
Installation
git clone https://github.com/ranajoy-dutta/claude-code-cost-explorer.git
cd claude-code-cost-explorer
uv sync
That's it — uv sync creates the virtual environment and installs all dependencies automatically.
Running
uv run flask --app app run --port 5050
Open http://localhost:5050.
No venv activation needed — uv run handles it automatically.
How costs are calculated
Tokens are read directly from ~/.claude/projects/**/*.jsonl — Claude Code writes them on every API response. Costs use Claude's published pricing:
| Model | Input | Output | Cache write | Cache read |
|---|---|---|---|---|
| claude-opus-4-x | $15/MTok | $75/MTok | $18.75/MTok | $1.50/MTok |
| claude-sonnet-4-x | $3/MTok | $15/MTok | $3.75/MTok | $0.30/MTok |
| claude-haiku-4-x | $0.80/MTok | $4/MTok | $1/MTok | $0.08/MTok |
If Anthropic changes pricing or you're on a custom plan, update the PRICING table in cost.py.
Running tests
uv run pytest -v
Tips: Session naming
Session titles come from whatever name Claude Code assigned the session. Three ways to set one:
| How | When |
|---|---|
claude -n "my-feature" |
At startup — best option |
/rename my-feature |
During a conversation |
Press R in the /resume picker |
After the fact |
If you don't name a session, Claude assigns a random slug (e.g. jolly-spinning-mango). A deliberate name like payments-refactor makes the session list much easier to scan when comparing costs across similar work.
Notes
- ~79% of turns are tool-call responses, not direct replies to your messages — this is normal. Each
Read,Bash,Write, etc. generates its own API call with its own token usage. - Cache read tokens are 10× cheaper than input tokens. A session that looks expensive at first glance often has most of its cost in cache reads.
- Subagent sessions (parallel agents) are excluded from their parent session's cost to avoid double-counting.
Contributing
Bug reports and PRs are welcome! Please:
- Open an issue first for anything beyond small fixes
- Run
uv run pytest -vbefore submitting a PR - Keep the zero-dependency philosophy — no npm, no build step, no database
License
MIT — see LICENSE.
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
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 claude_code_cost_explorer-0.1.0.tar.gz.
File metadata
- Download URL: claude_code_cost_explorer-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c8019675957e5773b4e623825f790b9f87f45df2d256fdc5147321016d591f
|
|
| MD5 |
9f99621d7c9475e3b3f2dffa688924d3
|
|
| BLAKE2b-256 |
43d9ce7f133587b04f254253824b859e34de1bc5fdbef3d284e862d26e86de05
|
File details
Details for the file claude_code_cost_explorer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: claude_code_cost_explorer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fac02b63614be20fea1b0b2d6ac971a9a2fc7e26082b60d2a8857629367ec77
|
|
| MD5 |
c8cd8dffe2dc03646506b1fe3e6904cb
|
|
| BLAKE2b-256 |
a47b741723bb7453691236a6ca14f6923090db3c1749f7dc709701e65c81c4e8
|