ccusage Agent Sources
Use this skill when touching data loading, token normalization, cost calculation,
or commands for any ccusage agent adapter.
Shared Report Concepts
Reports aggregate raw usage into daily, monthly, session, or billing-block summaries and output either tables or JSON.
The canonical command surface is the unified ccusage CLI:
ccusage daily
ccusage codex daily
ccusage opencode daily
ccusage amp daily
ccusage pi daily
Standalone agent wrapper packages have been removed. Use the unified ccusage <agent> ... commands in docs, tests, and examples, and do not reintroduce wrapper commands such as ccusage-codex, ccusage-opencode, ccusage-amp, or ccusage-pi.
Cost modes:
auto - prefer pre-calculated costUSD when available, otherwise calculate from tokens.
calculate - calculate from token counts and ignore pre-calculated costs.
display - use pre-calculated costs and show 0 when missing.
Pricing generally comes from LiteLLM's model_prices_and_context_window.json. The --offline flag forces embedded pricing snapshots where supported.
Agent Details
Read only the relevant reference before changing parser behavior, token mappings, data directory detection, fallback models, or agent-specific CLI flags:
- Claude Code:
references/claude-code.md
- Codex:
references/codex.md
- OpenCode:
references/opencode.md
- Amp:
references/amp.md
- pi-agent:
references/pi-agent.md
Implementation Notes
- Treat Codex, OpenCode, Amp, and pi-agent as agent subcommands under the unified
ccusage CLI.
- Reuse shared Rust modules for rendering, table layout, logging, date formatting,
progress, pricing, file walking, and aggregation where appropriate.
- Keep command names and flag semantics aligned unless the source data forces a difference.
- Internal workspace runtime libraries for bundled/private packages belong in
devDependencies.
Adapter Layout
New or migrated runtime agent implementations belong under
rust/crates/ccusage/src/adapter/<agent>/. Keep agent-specific code there. Split
files by responsibility when the implementation grows:
mod.rs - public adapter surface and command wiring.
paths.rs - environment variables, default directories, and path discovery.
parser.rs - raw record parsing and token/model mapping.
loader.rs - file walking, SQLite reads, dedupe, and date filtering entry points.
report.rs - JSON/table row shaping when agent-specific.
types.rs - source-local types when they are not shared outside the adapter.
Use apps/ccusage/src only for the remaining npm launcher, package scripts,
schema artifacts, and benchmarks. Do not add new TypeScript runtime adapter
logic unless the user explicitly scopes work to the package layer.
When moving an existing loader into an adapter, update internal imports to the
adapter path instead of adding compatibility re-export shims. Keep old root-level
modules only when they are part of the package's declared public exports or are
dedicated packaging entries.
Use shared ccusage foundation for rendering, table layout, logging, date
formatting, progress, pricing fetcher lifecycle, JSONL walking, SQLite loading,
dedupe, and aggregation wherever the source data permits. Agent adapters should
mainly own source-specific log discovery, parsing, token mapping, model mapping,
and source-specific metadata.
Treat "same foundation as Claude" as more than shared file walking. JSONL
adapters should use shared scanning helpers when stable row markers exist, and
high-volume paths should avoid returning large intermediate object vectors when
worker-side aggregation or typed transfer payloads can preserve the same output.
When several adapters expose the same raw-log shape, prefer a small shared Rust
helper over duplicating period/session aggregation. Keep highly specialized
loaders such as Codex parsing separate when their file format or pricing
semantics require it.
Adapter Migration Checklist
For each migrated or new agent:
- Put all source-specific runtime logic under
rust/crates/ccusage/src/adapter/<agent>/.
- Implement fast detection that short-circuits once a usable source file is found.
- Use shared file walking, JSONL scanning where applicable, SQLite loading,
logging, pricing fetcher lifecycle, date formatting, table rendering, and
all-agent aggregation.
- Keep adapter code responsible for source paths, raw parsing, token mapping, model mapping, source metadata, and agent-specific pricing.
- Add Rust fixture-backed tests for path discovery, parser behavior, aggregation totals, and important legacy compatibility.
- Add skipped local-data smoke tests when real user log directories are useful for catching schema drift.
- Add or update CLI JSON assertions and table snapshots for affected report modes.
- Audit every user-facing entrypoint that lists supported agents, commands, options, report modes, or examples. Update the root
README.md, apps/ccusage/README.md, docs/guide/, and VitePress navigation when the adapter changes what users can run or discover. Use the ccusage-docs skill for docs conventions.
- When adding a new agent guide, include README usage examples, docs guide content, related guide links, and VitePress navigation in the same change unless the user explicitly scopes documentation out.
- Validate terminal output with
cmux-debug when changing table layout, progress, spinners, or responsive behavior.
- Benchmark affected agents against main or the previous tag, and record whether JSON output still matches for the comparison window.
1---2name: ccusage-agent-sources3description: Guides ccusage agent source work for Rust CLI parsers, log paths, token mappings, costs, reports, and adapter command behavior.4---56# ccusage Agent Sources78Use this skill when touching data loading, token normalization, cost calculation,9or commands for any ccusage agent adapter.1011## Shared Report Concepts1213Reports aggregate raw usage into daily, monthly, session, or billing-block summaries and output either tables or JSON.1415The canonical command surface is the unified `ccusage` CLI:1617```sh18ccusage daily19ccusage codex daily20ccusage opencode daily21ccusage amp daily22ccusage pi daily23```2425Standalone agent wrapper packages have been removed. Use the unified `ccusage <agent> ...` commands in docs, tests, and examples, and do not reintroduce wrapper commands such as `ccusage-codex`, `ccusage-opencode`, `ccusage-amp`, or `ccusage-pi`.2627Cost modes:2829- `auto` - prefer pre-calculated `costUSD` when available, otherwise calculate from tokens.30- `calculate` - calculate from token counts and ignore pre-calculated costs.31- `display` - use pre-calculated costs and show `0` when missing.3233Pricing generally comes from LiteLLM's `model_prices_and_context_window.json`. The `--offline` flag forces embedded pricing snapshots where supported.3435## Agent Details3637Read only the relevant reference before changing parser behavior, token mappings, data directory detection, fallback models, or agent-specific CLI flags:3839- Claude Code: `references/claude-code.md`40- Codex: `references/codex.md`41- OpenCode: `references/opencode.md`42- Amp: `references/amp.md`43- pi-agent: `references/pi-agent.md`4445## Implementation Notes4647- Treat Codex, OpenCode, Amp, and pi-agent as agent subcommands under the unified `ccusage` CLI.48- Reuse shared Rust modules for rendering, table layout, logging, date formatting,49 progress, pricing, file walking, and aggregation where appropriate.50- Keep command names and flag semantics aligned unless the source data forces a difference.51- Internal workspace runtime libraries for bundled/private packages belong in `devDependencies`.5253## Adapter Layout5455New or migrated runtime agent implementations belong under56`rust/crates/ccusage/src/adapter/<agent>/`. Keep agent-specific code there. Split57files by responsibility when the implementation grows:5859- `mod.rs` - public adapter surface and command wiring.60- `paths.rs` - environment variables, default directories, and path discovery.61- `parser.rs` - raw record parsing and token/model mapping.62- `loader.rs` - file walking, SQLite reads, dedupe, and date filtering entry points.63- `report.rs` - JSON/table row shaping when agent-specific.64- `types.rs` - source-local types when they are not shared outside the adapter.6566Use `apps/ccusage/src` only for the remaining npm launcher, package scripts,67schema artifacts, and benchmarks. Do not add new TypeScript runtime adapter68logic unless the user explicitly scopes work to the package layer.6970When moving an existing loader into an adapter, update internal imports to the71adapter path instead of adding compatibility re-export shims. Keep old root-level72modules only when they are part of the package's declared public exports or are73dedicated packaging entries.7475Use shared ccusage foundation for rendering, table layout, logging, date76formatting, progress, pricing fetcher lifecycle, JSONL walking, SQLite loading,77dedupe, and aggregation wherever the source data permits. Agent adapters should78mainly own source-specific log discovery, parsing, token mapping, model mapping,79and source-specific metadata.8081Treat "same foundation as Claude" as more than shared file walking. JSONL82adapters should use shared scanning helpers when stable row markers exist, and83high-volume paths should avoid returning large intermediate object vectors when84worker-side aggregation or typed transfer payloads can preserve the same output.8586When several adapters expose the same raw-log shape, prefer a small shared Rust87helper over duplicating period/session aggregation. Keep highly specialized88loaders such as Codex parsing separate when their file format or pricing89semantics require it.9091## Adapter Migration Checklist9293For each migrated or new agent:9495- Put all source-specific runtime logic under `rust/crates/ccusage/src/adapter/<agent>/`.96- Implement fast detection that short-circuits once a usable source file is found.97- Use shared file walking, JSONL scanning where applicable, SQLite loading,98 logging, pricing fetcher lifecycle, date formatting, table rendering, and99 all-agent aggregation.100- Keep adapter code responsible for source paths, raw parsing, token mapping, model mapping, source metadata, and agent-specific pricing.101- Add Rust fixture-backed tests for path discovery, parser behavior, aggregation totals, and important legacy compatibility.102- Add skipped local-data smoke tests when real user log directories are useful for catching schema drift.103- Add or update CLI JSON assertions and table snapshots for affected report modes.104- Audit every user-facing entrypoint that lists supported agents, commands, options, report modes, or examples. Update the root `README.md`, `apps/ccusage/README.md`, `docs/guide/`, and VitePress navigation when the adapter changes what users can run or discover. Use the `ccusage-docs` skill for docs conventions.105- When adding a new agent guide, include README usage examples, docs guide content, related guide links, and VitePress navigation in the same change unless the user explicitly scopes documentation out.106- Validate terminal output with `cmux-debug` when changing table layout, progress, spinners, or responsive behavior.107- Benchmark affected agents against main or the previous tag, and record whether JSON output still matches for the comparison window.