ccusage-data-export
Use when exporting ccusage usage data to JSON.
SKILL.mdskills/ccusage-data-export/SKILL.md
GitHubccusage data export
Produce a folder of JSON usage reports from the ccusage CLI (a unified tracker for
Claude, Codex, OpenCode, Hermes, Amp, Copilot, Antigravity, pi, and others) for a
report or audit.
When to use
- Someone asks for a full ccusage data export, usage report, or cost/token totals.
- Need per-agent (Claude vs Codex vs Hermes vs OpenCode …) totals from ccusage.
- Need machine-readable (JSON) daily/monthly/session breakdowns.
Prerequisites
npxavailable; ccusage runs vianpx -y ccusage@latest(no install needed).- Output folder (default
~/ccusage-export).
Procedure
- Create the output folder:
mkdir -p ~/ccusage-export. - Learn flags:
npx -y ccusage@latest --helpplusdaily --help,monthly --help,session --help. Key flags:-j/--json,-s/--since,-u/--until,-z/--timezone,--all,--by-agent,--sections,-O/--offline,--no-cost,--last. There is NO--breakdownflag; per-model breakdowns are included by default asmodelBreakdownsin each JSON row. - Generate reports in ONE quick batch (ccusage reads live data; totals drift between
runs, so keep them consistent):
npx -y ccusage@latest daily --json --by-agent > /tmp/daily_byagent.jsonnpx -y ccusage@latest monthly --json > ~/ccusage-export/monthly.jsonnpx -y ccusage@latest session --json > ~/ccusage-export/session.json
- Derive
daily.jsonfrom the--by-agentsnapshot by dropping the per-rowagentssub-array (keeps the standard daily report on the same snapshot):import json, copy d = copy.deepcopy(json.load(open('/tmp/daily_byagent.json'))) for row in d['daily']: row.pop('agents', None) json.dump(d, open('~/ccusage-export/daily.json','w'), indent=2) - Per-agent split (
agents.json): aggregate the--by-agentdaily rows — each row'sagentsarray has one entry per agent present that day withtotalCost,totalTokens,inputTokens,outputTokens,cacheCreationTokens,cacheReadTokens,modelsUsed. Sum across dates per agent; collect date range from rowperiodvalues. Add session counts fromsession.json(each session row has anagentfield). Writeagents.jsonwithgrandTotalstaken from the daily snapshot so it matchesdaily.jsonexactly. - Verify all four files share identical grand totals (cost + tokens); fix if not.
- Report back ONLY: exact file paths, each file's size in bytes, grand totals from the daily report (total cost, total tokens, date range), and how the per-agent split was obtained. Do NOT paste JSON contents.
How the per-agent split is obtained
- ccusage supports grouping by agent via the
--by-agentflag on unified reports, and also exposes per-agent subcommands (ccusage <agent> daily|monthly|session|...for claude, codex, opencode, hermes, amp, copilot, antigravity, pi, and others). - Preferred:
--by-agentaggregation (one run, consistent snapshot) plus session counts fromsession.json. - Cross-check: run a couple of per-agent subcommands (
ccusage claude daily --json,ccusage codex daily --json) and confirm totals match the aggregated values. - If neither
--by-agentnor per-agent subcommands existed, say so plainly — do not fabricate a split.
Pitfalls
- No
--breakdownflag exists (despite the name being plausible). Per-model data is already inmodelBreakdownsby default; do not hunt for a flag. - Per-agent schemas differ. The unified report uses
totalCost/period; the codex subcommand usescostUSD/date(and addsreasoningOutputTokens). Normalize on the unified schema when aggregating; do not assume field names transfer. - Live-data drift. ccusage reads live logs; totals change between runs. Generate all
files in one quick batch and derive
daily.json+agents.jsonfrom the same--by-agentsnapshot so grand totals agree across files. --by-agentrow shape. Unified rows haveagent: "all"plus anagentsarray; each agent entry mirrors the row's token/cost fields. A single day can contain multiple agents — handle each entry separately, do not assume one agent per day.- Session count. Comes from
session.json(count rows whereagent == X), not from the daily report. The unified session report is grouped by session id, one row per session. - Unpriced models.
totals.unpricedModelslists models with no rate; their cost is excluded fromtotalCost. Report cost as reported; do not estimate. - npx noise. Install/progress messages go to stderr; redirect stdout to the file and stderr to a temp file so JSON stays clean.
- Detected agents vary by machine. Only agents with local data appear; do not hardcode
the list — read it from
metadata.agents/ rowagentsentries. - Report-back discipline. Return only paths, byte sizes, grand totals, and method. Do not paste JSON contents into the reply.