From john-skills
Tracks input, output, and cache token costs for Claude Code API calls using Python scripts, calculating USD costs from Anthropic pricing. Invoke via /cost-tracking or stop phrases like 'stop tracking'.
npx claudepluginhub jbdamask/john-claude-skills --plugin john-skillsThis skill uses the workspace's default tool permissions.
Track the exact token cost of any Claude Code operation by marking a start and stop point in the session JSONL.
Tracks Claude Code session costs, sets budget alerts, and optimizes token spend with task budgets, cost drivers, and strategies. Useful for mid-session checks and multi-session planning.
Runs local Python CLI dashboard analyzing Claude Code JSONL transcripts for per-prompt token costs, heatmaps, cache analytics, project comparisons, and optimization tips.
Share bugs, ideas, or general feedback.
Track the exact token cost of any Claude Code operation by marking a start and stop point in the session JSONL.
When the user invokes /cost-tracking:
Determine the current session JSONL path. It lives at:
~/.claude/projects/<project-hash>/<session-id>.jsonl
Find the project directory by looking for the most recently modified .jsonl file under ~/.claude/projects/. The project hash is a mangled version of the working directory path (slashes replaced with dashes, e.g., -Users-johndamask-myproject).
Determine the cost tracking output directory:
~/.claude/projects/<project-hash>/cost-tracking/
Run the start script:
python3 <skill-dir>/scripts/start_tracking.py <session_jsonl_path> <cost_tracking_dir>
Store the returned tracking_id — mention it to the user and remember it for the stop step.
Confirm: "Cost tracking started. I'll calculate costs when you say 'stop tracking'."
When the user says "stop tracking", "stop cost tracking", or asks about the cost:
Run the stop script with the tracking_id from the start step:
python3 <skill-dir>/scripts/stop_tracking.py <tracking_id> <cost_tracking_dir>
The script outputs a formatted cost report and writes:
tokens.jsonl — per-entry token log with timestamp, model, input_tokens, output_tokenssummary.json — aggregated cost breakdown by modelPresent the report to the user.
Pricing is stored in resources/pricing.json (last updated 2026-03-08, source: https://platform.claude.com/docs/en/about-claude/pricing). The stop script loads this file at runtime. It distinguishes between 5-minute and 1-hour cache writes using the cache_creation.ephemeral_* fields in the session JSONL. If pricing appears stale, fetch the pricing page and update resources/pricing.json.