Skip to main content

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

App preview

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
  • 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:

  1. Open an issue first for anything beyond small fixes
  2. Run uv run pytest -v before submitting a PR
  3. 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

claude_code_cost_explorer-0.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_code_cost_explorer-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file claude_code_cost_explorer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for claude_code_cost_explorer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 90c8019675957e5773b4e623825f790b9f87f45df2d256fdc5147321016d591f
MD5 9f99621d7c9475e3b3f2dffa688924d3
BLAKE2b-256 43d9ce7f133587b04f254253824b859e34de1bc5fdbef3d284e862d26e86de05

See more details on using hashes here.

File details

Details for the file claude_code_cost_explorer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_code_cost_explorer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fac02b63614be20fea1b0b2d6ac971a9a2fc7e26082b60d2a8857629367ec77
MD5 c8cd8dffe2dc03646506b1fe3e6904cb
BLAKE2b-256 a47b741723bb7453691236a6ca14f6923090db3c1749f7dc709701e65c81c4e8

See more details on using hashes here.

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