Repository navigation
Commands Reference
Complete reference for all claude-stats CLI commands, flags, and usage examples.
These flags are available on every command:
| Flag | Default | Env Variable | Description |
|---|---|---|---|
--db <path> |
~/.claude-stats/claude-stats.db |
CLAUDE_STATS_DB |
Path to the SQLite database |
--claude-dir <path> |
~/.claude/projects |
CLAUDE_STATS_CLAUDE_DIR |
Directory containing Claude Code JSONL files |
--timezone <zone> |
Local |
CLAUDE_STATS_TIMEZONE |
Timezone for date grouping (e.g., America/New_York, UTC) |
--verbose |
false |
CLAUDE_STATS_VERBOSE |
Enable debug logging to stderr |
--no-color |
false |
NO_COLOR |
Disable color output |
Flags take precedence over environment variables. See Configuration for details.
Launches the interactive TUI dashboard. Equivalent to claude-stats tui.
claude-statsScans Claude Code's JSONL session files and loads them into the SQLite database.
claude-stats ingest [flags]| Flag | Default | Description |
|---|---|---|
--full |
false |
Force full re-ingest, ignoring file change detection |
--dry-run |
false |
Show what would be ingested without writing to database |
--since <date> |
(none) | Only process files modified after this date (YYYY-MM-DD) |
--project <name> |
(none) | Only process sessions matching this project name |
- Scans
--claude-dirfor.jsonlfiles - Checks each file against
ingest_metatable — skips files with unchanged size and modification time - Parses each JSONL file line by line, extracting messages, tool uses, and token counts
- Calculates costs from token counts using embedded pricing tables (or uses pre-calculated
costUSDif present) - Detects subagent files in
<session-id>/subagents/directories and merges their data into the parent session - Rebuilds the
daily_statsaggregation table
# Standard incremental ingest (fast — skips unchanged files)
claude-stats ingest
# Full re-ingest (useful after pricing updates or bug fixes)
claude-stats ingest --full
# Preview what would be ingested
claude-stats ingest --dry-run
# Only ingest recent files
claude-stats ingest --since 2026-03-01
# Only ingest a specific project
claude-stats ingest --project my-app
# Combine flags
claude-stats ingest --since 2026-03-01 --project my-app --verbose-
Normally: never. The TUI auto-ingests on launch, and
ingestis incremental. -
After upgrading claude-stats: If a new version changes cost calculation or schema, run
ingest --full. -
After deleting the database: Run
ingestto rebuild from scratch. -
Debugging: Use
--verboseto see which files are being processed.
Launches the interactive TUI dashboard.
claude-stats tui [flags]| Flag | Default | Description |
|---|---|---|
--skip-ingest |
false |
Skip the automatic incremental ingest on launch |
# Launch with auto-ingest (default)
claude-stats tui
# Skip ingest for faster startup
claude-stats tui --skip-ingest
# Use a specific database
claude-stats tui --db /path/to/stats.dbSee the TUI Guide for detailed tab descriptions and keyboard shortcuts.
Run a one-shot query against the database from the command line. Supports natural language questions and raw SQL.
claude-stats query <question> [flags]| Argument | Required | Description |
|---|---|---|
question |
Yes | The question to ask (natural language or SQL) |
| Flag | Default | Description |
|---|---|---|
--sql |
false |
Interpret input as raw SQL instead of natural language |
--format <fmt> |
table |
Output format: table, json, csv
|
--limit <n> |
20 |
Maximum rows to return |
claude-stats query "total cost"
claude-stats query "cost today"
claude-stats query "cost this week"
claude-stats query "cost this month"
claude-stats query "cost last 30 days"
claude-stats query "cost yesterday"
claude-stats query "most expensive session"
claude-stats query "how many sessions"
claude-stats query "how many messages"
claude-stats query "top 5 models"
claude-stats query "cost by project"
claude-stats query "cost for my-project"
claude-stats query "sessions today"
claude-stats query "sessions this week"
claude-stats query "average cost per session"
claude-stats query "longest session"
claude-stats query "most used tools"
claude-stats query "busiest day"
claude-stats query "daily cost"See the Query Guide for the full list of supported patterns.
# Simple counts
claude-stats query --sql "SELECT count(*) as total FROM sessions"
# Cost by day
claude-stats query --sql "SELECT date_key, total_cost_usd FROM daily_stats ORDER BY date_key DESC LIMIT 14"
# Most used tools
claude-stats query --sql "SELECT tool_name, count(*) as uses FROM tool_uses GROUP BY tool_name ORDER BY uses DESC LIMIT 10"
# Sessions with high cache efficiency
claude-stats query --sql "SELECT session_id, project_name, total_cache_read_tokens * 100.0 / total_input_tokens as cache_pct FROM sessions WHERE total_input_tokens > 0 ORDER BY cache_pct DESC LIMIT 10"Table (default) — Human-readable ASCII table with column alignment:
project_name | total_cost
----------------+-----------
my-app | 45.23
other-project | 12.87
(2 rows)
JSON — Array of objects, useful for piping to jq:
claude-stats query "cost by project" --format json | jq '.[0]'CSV — RFC 4180 CSV, useful for spreadsheets:
claude-stats query "cost by project" --format csv > costs.csvUse --verbose with natural language queries to see the generated SQL:
claude-stats query "cost today" --verbose
# Prints the SQL to stderr, results to stdoutSearch full session transcripts (including subagent transcripts) for a keyword and print matching sessions. Use it to find the session ID of a past conversation so you can resume it with claude --resume <session-id>.
Unlike query, which works on the aggregated database, search scans the original JSONL transcript files, so it finds keywords anywhere in a conversation — message text, Claude's thinking, and tool inputs (file paths, commands).
claude-stats search <keyword> [flags]| Argument | Required | Description |
|---|---|---|
keyword |
Yes | The keyword or phrase to search for (case-insensitive by default) |
| Flag | Default | Description |
|---|---|---|
--project <name> |
Only search sessions from this project | |
--limit <n> |
20 |
Maximum sessions to return |
--format <fmt> |
table |
Output format: table, json, csv
|
--case-sensitive |
false |
Match case exactly |
# Find sessions that mention a keyword
claude-stats search "flamingo migration"
# Only search one project
claude-stats search "auth refactor" --project my-app
# Grab the newest matching session ID and resume it
claude --resume "$(claude-stats search "auth refactor" --format csv | tail -n +2 | head -1 | cut -d, -f1)"Results are sorted newest-first (the session you want to resume is usually recent). Each row shows the full session ID, project, last-active date, the role of the first matching message, how many messages matched, and a snippet of the first match.
Sessions must be ingested (claude-stats ingest) before they can be found; the search reads each session's transcript from the file path recorded at ingest time and skips sessions whose files have since been deleted.
Export structured reports and data for use outside the TUI.
Export all sessions as CSV or JSON.
claude-stats export sessions [flags]| Flag | Default | Description |
|---|---|---|
--format <fmt> |
csv |
Output format: csv, json
|
-o, --output <file> |
stdout | Write to file instead of stdout |
CSV columns: session_id, project, started_at, messages, cost_usd, duration_s
# CSV to stdout (pipe to file or another tool)
claude-stats export sessions
# JSON to file
claude-stats export sessions --format json -o sessions.json
# CSV to file
claude-stats export sessions -o sessions.csvExport one session transcript as Markdown with full message content.
claude-stats export session <session-id> [flags]| Flag | Default | Description |
|---|---|---|
-o, --output <file> |
stdout | Write Markdown to file instead of stdout |
The transcript export:
- Uses the session's original JSONL source file (plus any
subagents/*.jsonlfiles) - Preserves full message content instead of
content_preview - Renders messages in chronological order with UTC timestamps
# Markdown to stdout
claude-stats export session abc123-session-id
# Markdown to file
claude-stats export session abc123-session-id -o session.mdGenerate a cost summary report.
claude-stats export cost-summary [flags]| Flag | Default | Description |
|---|---|---|
--format <fmt> |
markdown |
Output format: markdown, json
|
-o, --output <file> |
stdout | Write to file instead of stdout |
The Markdown report includes:
- Overview — Total sessions, messages, cost, tokens, most active project, primary model
- Monthly Costs — Last 12 months with cost, sessions, and messages
- Cost by Model — Breakdown by model with cost and message count
- Cost by Project — Breakdown by project with cost and session count
# Markdown to stdout
claude-stats export cost-summary
# Markdown to file
claude-stats export cost-summary -o report.md
# JSON for programmatic use
claude-stats export cost-summary --format json -o report.jsonCopy the SQLite database file for backup or sharing.
claude-stats export dump -o <file>| Flag | Default | Description |
|---|---|---|
-o, --output <file> |
(required) | Output path for the database copy |
claude-stats export dump -o backup.db
claude-stats export dump -o ~/Dropbox/claude-stats-backup.dbThe dump is a full copy of the SQLite file. You can open it with any SQLite client (sqlite3, DB Browser, etc.).
Generate shell completion scripts for tab-completion of commands and flags.
claude-stats completion <shell>| Argument | Required | Description |
|---|---|---|
shell |
Yes | One of: bash, zsh, fish
|
Bash:
claude-stats completion bash > /etc/bash_completion.d/claude-stats
# Or for current user only:
claude-stats completion bash > ~/.local/share/bash-completion/completions/claude-statsZsh:
claude-stats completion zsh > "${fpath[1]}/_claude-stats"
# Then restart your shell or run:
compinitFish:
claude-stats completion fish > ~/.config/fish/completions/claude-stats.fishAfter installing, restart your shell. Then type claude-stats and press Tab to see available commands and flags.
Print version, build date, Go version, and OS/architecture.
claude-stats versionOutput:
claude-stats v0.2.0
Built: 2026-03-07T18:00:00Z
Go: go1.26.0
OS/Arch: darwin/arm64
# Quick overview
claude-stats query "cost today"
claude-stats query "cost this week"
# Or launch the TUI
claude-stats# Generate a cost report
claude-stats export cost-summary -o "report-$(date +%Y-%m).md"
# Or as JSON for processing
claude-stats export cost-summary --format json | jq '.summary.total_cost'# Export sessions
claude-stats export sessions -o sessions.csv
# Or query specific data
claude-stats query --sql "SELECT date_key, total_cost_usd FROM daily_stats" --format csv > daily.csv
# Export one full chat transcript as Markdown
claude-stats export session abc123-session-id -o session.mdclaude-stats export dump -o "backup-$(date +%Y%m%d).db"# See what files would be processed
claude-stats ingest --dry-run --verbose
# Force full re-ingest
claude-stats ingest --full --verbose