cost-report
Generate a local Claude Code cost report from the ECC cost-tracker metrics log.
- Kind
- Prompt
- Works with
- Claude Code, Codex
- Source
- affaan-m/ECC @ d3b8a3e90890
- Path
- commands/cost-report.md
- License
- MIT
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
# Cost Report
Summarize local Claude Code spend by day, model, and session from the metrics
log that ECC's `stop:cost-tracker` hook writes.
## Where the data lives
The tracker appends one JSON object per session-stop to
`~/.claude/metrics/costs.jsonl`. Each row is a **cumulative snapshot for that
session**, so the report takes the **latest row per `session_id`** and sums
across sessions (summing every row would multiply-count).
Row schema:
`{ timestamp, session_id, transcript_path, model, input_tokens, output_tokens, cache_write_tokens, cache_read_tokens, estimated_cost_usd }`
## What this command does
1. Check that `~/.claude/metrics/costs.jsonl` exists. If it does not, tell the
user the tracker is not set up yet (it populates after the first session ends
with the `stop:cost-tracker` hook enabled).
2. Reduce rows to the latest snapshot per session and aggregate.
3. Present a compact report, or export recent rows as CSV when the argument is `csv`.
`node` is used instead of `sqlite3`/`jq` so this works identically on macOS,
Linux, and Windows.
## Report
```bash
node -e '
const fs=require("fs"),os=require("os"),path=require("path");
…