This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Run the script:
./claude-costs.py(script is already executable) - Run with different options:
./claude-costs.py -d 7(analyze last 7 days),./claude-costs.py -v(verbose mode) - Dependencies: Automatically installed via
uvon first run (requires Python 3.9+)
This is a single-file Python CLI application that analyzes Claude Code usage costs from local metadata files:
- Data Source: Reads
.jsonlfiles from~/.claude/projects/containing usage metadata - Cost Calculation: Uses hardcoded pricing tables for different Claude models with cache discounts
- Main Components:
parse_jsonl_files(): Extracts usage data from JSONL files, handles both legacycostUSDand new token-based formatscalculate_token_cost(): Computes actual costs with cache savings based on model pricing- Display functions create sparklines and bar charts for activity visualization
- The script relies on undocumented Claude Code file structures that may break without warning
- Pricing is hardcoded in the
PRICINGdictionary and needs manual updates when Claude pricing changes - Uses
uvscript runner with inline dependencies (rich, typer) - no separate requirements file
/ide/- IDE integration lock files tracking active connections/local/- Claude Code installation (node_modules, ripgrep binaries)/projects/- Project conversation logs as .jsonl files/statsig/- Analytics and evaluation caches/todos/- Todo list JSON files for task tracking/.claude/- Local settings and permissions
Current format (v1.0.19) includes:
message- Full Claude message with content and usage statssessionId- Unique session identifiertimestamp- ISO timestampversion- Claude Code versionuserType- "external" for CLI userscwd- Current working directory
Usage objects contain these fields:
input_tokens- Regular input tokensoutput_tokens- Generated output tokenscache_creation_input_tokens- Tokens for cache writes (25% premium)cache_read_input_tokens- Cached tokens (90% discount)service_tier- Usually "standard"
Note: Thinking tokens are NOT currently tracked separately in Claude Code v1.0.19, despite models like Opus 4 using internal reasoning.