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.1.tar.gz (16.1 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.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for claude_code_cost_explorer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dafe3c296b50ae79e4d889a42d7b943cf039dbbe89ca205aa2472a03d43d9f7d
MD5 a62e7f123fe5b198be12d19da203d95e
BLAKE2b-256 c12427ef41651526ca7fedc01a11d26e1c7f36f56806c00e30f7ea9203aa68d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude_code_cost_explorer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 832c701c46c3067348cf306a5dddbf645c9082098a5925cfef03c461292e78af
MD5 748371802aeccb22131259a0811c2410
BLAKE2b-256 9b79d552eace9707e6f2d8ed9c330ad251097fb7c767fa71c5a2e0a2a883cf48

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