Repository navigation
Commit a2ca34a
authored
feat(ccusage): add native Rust CLI (#977)
* feat(ccusage): add native Rust CLI
Introduce a Rust workspace member for the ccusage command path and wire the existing package entry point to execute the native binary when available. The TypeScript modules remain available for library exports and existing tests, while the command implementation now uses native JSONL parsing, parallel file discovery, and release settings tuned for small binaries.
Update package scripts and the Nix dev shell so Rust builds and tests are part of the normal workflow. Darwin shells export SDKROOT for the Nix Apple SDK so cargo can link reliably on macOS.
* chore(ccusage): preserve executable entrypoint
Keep the package bin target executable after replacing the TypeScript entrypoint with the Rust wrapper. The package.json bin field points at apps/ccusage/src/index.ts for development and publishing, so the source file should retain its executable bit.
* test(ccusage): extend large JSONL stress timeout
Allow the 600MB data-loader stress test enough time on slower local IO and CI environments. The test exercises the same streaming path and assertion coverage; only the Vitest timeout changes so the suite can complete reliably.
* docs(ccusage): record Rust benchmark
Document the Rust versus TypeScript benchmark command, measured runtime, binary size, and output comparison for the rewrite. This gives the PR a concrete performance and size record without mixing measurement notes into implementation changes.
* fix(ccusage): align Rust loader with TypeScript output
Preserve TypeScript-compatible file discovery and deduplication order so duplicate message/request pairs resolve identically. Match the TypeScript validation shape for optional JSON fields, including rejecting null values that Valibot does not accept, and align session ordering with the existing command behavior. Split CLI argument definitions into a dedicated Rust module while keeping command execution behavior unchanged.
* docs(ccusage): refresh Rust benchmark
Update the benchmark after the Rust loader was aligned with the TypeScript output. The documented measurement now uses the command invocation that explicitly passes the subcommand through Bun, records the current release binary size, and notes that the canonicalized daily JSON output is identical.
* feat(ccusage): align native pricing and terminal output
Add a build-time Claude pricing snapshot for offline and fallback cost calculation, while keeping runtime LiteLLM fetching for calculate mode or auto mode entries missing costUSD.
Move the native terminal output toward the TypeScript CLI presentation with boxed headings and responsive bordered tables. The loader now assigns costs after dedupe so auto mode can skip pricing work when every entry already has costUSD.
* docs(ccusage): update native performance benchmark
Record the latest daily JSON measurements for both default auto mode and offline mode after adding native pricing fallback and terminal output parity.
* perf(ccusage): skip redundant cost reassignment
Keep costUSD assignment in the parallel file parsing path for display and auto mode. The post-dedupe pricing pass now only runs when calculate mode is requested or auto mode has entries missing costUSD.
* Revert "perf(ccusage): skip redundant cost reassignment"
This reverts commit 251137ea277216f81da3adebb5d7c6fe56a0c794.
* Revert "docs(ccusage): update native performance benchmark"
This reverts commit 936fdb7a52d9be5167e01a33f73048da8ed2d867.
* Revert "feat(ccusage): align native pricing and terminal output"
This reverts commit b4b933dafc64a985e3f42f3655b16610c3b4ed55.
* perf(ccusage): speed up TypeScript usage loading
Port the useful hot-path ideas from the native Rust loader in #977 back into the TypeScript implementation. Usage rows now avoid Valibot on the JSONL hot path, skip lines that cannot contain token usage before parsing, and preserve chronological duplicate behaviour without the previous timestamp pre-sort pass.
Cache date formatters and handle the default local and UTC date formats directly so daily grouping avoids repeated Intl formatter construction for the common paths.
The benchmarked bundled CLI stays under two seconds on the local Claude data set and now runs in the same range as the Rust implementation for offline JSON output.
Refs #977
Co-authored-by: ryoppippi <[email protected]>
* Revert "perf(ccusage): speed up TypeScript usage loading"
This reverts commit ea0196c112f659e7d549cd24a5b078d7f8187e70.
* perf(ccusage): reduce native JSONL parse work
Avoid parsing JSON for transcript lines that cannot contain usage tokens in the native loader. The file-order timestamp prepass now extracts compact JSONL timestamps directly and falls back to the existing serde_json path when that fast path does not apply.
This keeps daily, session, monthly, and blocks JSON output identical while cutting the local offline daily benchmark from roughly 1.25s median to roughly 0.65s median.
Refs #977
* Revert "perf(ccusage): reduce native JSONL parse work"
This reverts commit 32c27ca736eb9aaf8384a7884938a17cdec03bf5.
* perf(ccusage): speed up TypeScript usage loading
Remove Valibot from the JSONL usage hot path by adding a lightweight parser for assistant usage rows, while keeping malformed and nullable fields rejected like the schema path.
Read JSONL files with bounded file-level parallelism based on available CPU parallelism, preserve main-compatible timestamp ordering and first-wins deduplication, and add --single-thread for sequential reads when needed.
Cache date formatters and fast-path local/UTC date formatting to avoid repeated Intl formatter construction during daily grouping.
Refs #977
Co-authored-by: ryoppippi <[email protected]>
* perf(ccusage): reduce native JSONL parse work
Skip native loader JSON parsing for transcript lines that cannot contain usage tokens, and extract compact timestamp fields directly during the file ordering prepass.
This preserves Rust JSON output for daily, session, monthly, and blocks while bringing the local offline daily benchmark down to roughly 0.65s.
Refs #977
Co-authored-by: ryoppippi <[email protected]>
* perf(ccusage): use Bun glob for usage discovery
Use Bun.Glob when available to enumerate JSONL usage files while retaining the tinyglobby fallback for Node and other runtimes.
Route block loading through the shared discovery helper so all report modes use the same Bun-aware path.
Local scan benchmark over 3124 JSONL files: tinyglobby 47.7ms, Bun.Glob 28.1ms. Full report runtime remains dominated by JSONL parsing, so warm daily and blocks timings are effectively unchanged.
Refs #977
* perf(ccusage): avoid trimming JSONL lines
Replace per-line trim-based blank checks with a small whitespace scanner so normal JSONL records avoid allocating a trimmed string.
Verified daily/session/monthly output equality and blocks equality with projection removed after the change.
Refs #977
* fix(ccusage): keep complete duplicate usage entries
Prefer the duplicate message/request entry with the largest token total instead of keeping the first record encountered. Claude logs can contain an initial partial usage record followed by a more complete one with the same message id and request id; keeping the partial record under-counts the native reports.
Add a native regression test that loads duplicate JSONL entries through the normal loader and verifies the more complete usage and cost are retained.
Benchmark: mitata on Apple M3 Pro, node 24.15.0, built JS CLI from /Users/ryoppippi/ghq/github.com/ryoppippi/ccusage-wt/perf/apps/ccusage/dist/index.js, Rust release CLI at target/release/ccusage, LOG_LEVEL=0, --offline --json, min_samples=5.
Results: JS daily 3.85s, session 3.99s, monthly 3.94s, blocks 8.36s. Rust daily 630.05ms, session 643.02ms, monthly 622.38ms, blocks 649.11ms.
Rust binary size: target/release/ccusage is 2.0M on arm64 macOS.
Correctness: built JS and Rust outputs matched for daily/session/monthly/blocks token totals after sorting by stable keys. Cost totals can still differ by floating-point formatting only.
Verification: direnv exec . cargo test -p ccusage.
* perf(ccusage): read Rust usage data in one pass
Load each JSONL file once and collect both the earliest timestamp and usage entries from that pass. This removes the previous sorted_usage_files pre-scan, which opened and read every file before opening the same files again for aggregation.
Directory traversal now uses DirEntry::file_type() to avoid extra path metadata checks during JSONL discovery. The loader also supports --single-thread for deterministic runs, while the default path keeps Rayon file-level parallelism.
Bring the non-statusline table output closer to the JavaScript CLI without adding table dependencies: responsive compact columns, model multiline rows, breakdown rows, daily project sections with projectAliases, session Last Activity, and detailed blocks --active output.
Remove tokio because the Rust CLI no longer uses async runtime features. The release binary is now 1.9M on arm64 macOS, down from the previous 2.0M local release build.
Benchmark on Apple M3 Pro, release binary, LOG_LEVEL=0, --offline --json, hyperfine --warmup 1 --runs 5. Process checks before each run showed no hyperfine/mitata/zig benchmark process; cmux and WindowServer were still active, so treat this as local noisy data.
Rust current: daily 393.7ms ± 16.1ms, session 398.7ms ± 25.7ms, monthly 383.8ms ± 6.4ms, weekly 389.1ms ± 9.4ms, blocks 398.9ms ± 14.2ms. Previous PR body baseline was daily 630.05ms, session 643.02ms, monthly 622.38ms, blocks 649.11ms.
Verified with direnv exec . cargo test -p ccusage, direnv exec . cargo build -p ccusage --release, and JS/Rust token-total parity checks for daily/session/monthly/weekly/blocks against the built JavaScript CLI.
* perf(ccusage): shrink Rust timezone support
Replace chrono-tz with Jiff system zoneinfo lookups for date grouping. chrono-tz embedded the generated IANA timezone table in the binary, while Jiff can read the system zoneinfo database on Unix, so the Rust CLI keeps IANA timezone support without carrying the static table in the executable.
Release binary size on arm64 macOS dropped from 1.9M to 948K after this change (ls: 970K). Reliable runtime benchmark data is not included because process checks showed a concurrent Zig build-exe process at about 99% CPU and cmux at about 170% CPU.
Verified with direnv exec . cargo fmt --all, direnv exec . cargo test -p ccusage, direnv exec . cargo build -p ccusage --release, JS/Rust token-total parity checks for daily/session/monthly/weekly/blocks, and timezone parity checks for UTC, Asia/Tokyo, America/New_York, and Europe/London.
* perf(ccusage): parse Rust usage timestamps once
Avoid the extra timestamp extraction pass on valid usage lines by reusing the parsed UsageEntry timestamp for both file ordering and LoadedEntry construction. Non-usage lines and malformed usage lines still use the existing compact timestamp fallback, so file ordering semantics remain conservative.
Also drops the unused chrono serde feature. The release binary size stayed unchanged at 970,464 bytes on arm64 macOS, but the dependency edge is no longer requested by chrono.
Benchmark: noisy local run with cmux around 170% CPU, hyperfine --warmup 1 --runs 3, built JS via node vs Rust release. daily: JS 3.113s ± 0.024s, Rust 460.0ms ± 22.8ms, Rust 6.77x faster. session: JS 3.188s ± 0.029s, Rust 426.2ms ± 45.6ms, Rust 7.48x faster. monthly: JS 3.148s ± 0.028s, Rust 393.3ms ± 59.1ms, Rust 8.01x faster. blocks: JS 3.460s ± 0.046s, Rust 543.5ms ± 57.1ms, Rust 6.37x faster.
Validation: cargo fmt --check; cargo test; cargo build --release; JS/Rust JSON parity for daily/session/monthly/weekly/blocks.
* perf(ccusage): skip Rust content deserialization
Avoid deserializing and retaining message.content for every Rust usage row. The only runtime use was block usage-limit reset extraction, so read_usage_file now extracts that timestamp from the raw JSONL line only when isApiErrorMessage is true and stores it on LoadedEntry.
This keeps usageLimitResetTime behaviour for blocks while reducing work and memory for normal content-bearing transcript rows. Binary size was unchanged at 970,464 bytes on arm64 macOS.
Benchmark: noisy local run with cmux around 190% CPU and mediaanalysisd around 90% CPU, hyperfine --warmup 1 --runs 3, built JS via node vs Rust release. daily: JS 3.325s ± 0.460s, Rust 643.4ms ± 6.9ms, Rust 5.17x faster. session: JS 3.472s ± 0.299s, Rust 534.1ms ± 16.0ms, Rust 6.50x faster. monthly: JS 3.233s ± 0.260s, Rust 510.9ms ± 17.6ms, Rust 6.33x faster. blocks: JS 3.687s ± 0.146s, Rust 580.7ms ± 12.4ms, Rust 6.35x faster.
Validation: cargo fmt --check; cargo test; cargo build --release; JS/Rust JSON parity for daily/session/monthly/weekly/blocks.
* perf(ccusage): share Rust file metadata strings
Store per-file project, session id, and project path metadata in Arc<str> and clone the Arc into each LoadedEntry instead of allocating a fresh String per parsed usage row. This keeps output types as owned strings only at summary/output boundaries while reducing hot-path metadata allocation for large JSONL files.
Binary size was unchanged at 970,464 bytes on arm64 macOS.
Benchmark: noisy local run with cmux around 200% CPU and mediaanalysisd around 95% CPU, hyperfine --warmup 1 --runs 3, built JS via node vs Rust release. daily: JS 4.269s ± 0.191s, Rust 855.3ms ± 134.3ms, Rust 4.99x faster. session: JS 4.360s ± 0.413s, Rust 785.2ms ± 31.2ms, Rust 5.55x faster. monthly: JS 4.196s ± 0.413s, Rust 707.2ms ± 30.2ms, Rust 5.93x faster. blocks: JS 4.277s ± 0.094s, Rust 757.4ms ± 86.9ms, Rust 5.65x faster. Treat absolute numbers as noisy due system load.
Validation: cargo fmt --check; cargo test; cargo build --release; JS/Rust JSON parity for daily/session/monthly/weekly/blocks.
* perf(ccusage): accumulate Rust summaries in one pass
Avoid building per-group entry vectors before producing daily, weekly, monthly, and session summaries. Each group now owns an accumulator that updates token totals, costs, model breakdowns, and session metadata as entries are scanned.
Parse the supported TS timestamp forms directly on the hot JSONL path and use Arc-backed session keys to avoid formatting a project/session string for every row.
Validation:
- direnv exec . cargo fmt
- direnv exec . cargo test
- direnv exec . cargo build --release
- JS/Rust JSON token and cost parity: daily, session, monthly, weekly, blocks
Binary size:
- target/release/ccusage: 953,984 bytes (previous rust PR baseline: 970,464 bytes)
Benchmarks (noisy; cmux ~170%, Arc ~100%, lazygit ~30% CPU):
- main JS daily: 12.205s ± 0.252s
- perf JS daily: 1.772s ± 0.051s
- Rust daily: 442.9ms ± 18.3ms
- main JS session: 9.346s ± 0.126s
- perf JS session: 1.983s ± 0.243s
- Rust session: 523.5ms ± 66.4ms
- main JS blocks: 10.937s ± 1.765s
- perf JS blocks: 2.100s ± 0.134s
- Rust blocks: 486.4ms ± 17.5ms
* perf(ccusage): drop chrono clock dependency
Replace Utc::now() calls with a small SystemTime-based UTC helper so chrono no longer needs its clock feature. This removes iana-time-zone and related platform dependency graph from the Rust binary while preserving command behavior.
Validation: direnv exec . cargo fmt; direnv exec . cargo check; direnv exec . cargo test; direnv exec . cargo build --release. JS/Rust parity matched for daily/session/monthly/weekly/blocks token and cost fields.
Benchmark on local Claude data, noisy system with cmux around 170% CPU: binary size 953,984 -> 937,472 bytes; rust daily 348.5ms ± 12.7ms; rust session 367.0ms ± 10.3ms; rust blocks 378.2ms ± 6.8ms; JS daily 1.333s ± 0.012s; JS session 1.707s ± 0.293s; JS blocks 1.632s ± 0.067s.
* perf(ccusage): replace anyhow in Rust CLI
Remove the anyhow dependency from the Rust binary and use a small local CliError type plus a local bail macro/context helper. This keeps the current command error text shape without pulling anyhow into the release build.
Size: target/release/ccusage 937,472 bytes -> 937,200 bytes (-272 bytes).
Validation: direnv exec . cargo fmt; direnv exec . cargo check; direnv exec . cargo test; direnv exec . cargo build --release; JS/Rust token and cost parity matched for daily/session/monthly/weekly/blocks.
Benchmark note: attempted hyperfine A/B against 80ba182 while Chrome/cmux were consuming several cores, so the timing run had severe noise and outliers. Observed r=3 means were daily 1.531s -> 1.319s, session 1.220s -> 1.469s, blocks 1.468s -> 2.612s; no speed claim is made from that run.
* perf(ccusage): format Rust dates without strftime
Replace fixed date and time rendering with manual formatting helpers so the Rust CLI does not pull in Jiff/chrono generic strftime machinery for simple table and JSON date strings.
This keeps timezone conversion through Jiff but avoids the generic formatter on the hot display paths. cargo-bloat shows Jiff text dropping from about 75.6 KiB to 25.0 KiB, and the release binary drops from 937,200 bytes to 804,480 bytes.
Validated with cargo fmt, cargo check, cargo test, cargo build --release, and JS/Rust token and cost parity for daily, session, monthly, weekly, and blocks.
* perf(ccusage): avoid chrono format parsing in Rust CLI
Replace the remaining fixed RFC3339/date parsing and formatting call sites with small dedicated helpers. This keeps the accepted timestamp shapes, adds offset timestamp coverage, and avoids pulling chrono format parse/output machinery into the release binary.
Release binary size drops from 804,480 bytes to 787,808 bytes. cargo-bloat shows chrono text dropping from about 12.5 KiB to 2.9 KiB.
Validated with cargo fmt, cargo check, cargo test, cargo build --release, cargo-bloat, and JS/Rust token and cost parity for daily, session, monthly, weekly, and blocks.
* perf(ccusage): replace clap in Rust CLI
Replace clap derive parsing with a small parser that covers the ccusage command surface used by the Rust binary. This removes clap, clap_builder, clap_derive, clap_lex, anstyle, and heck from the release dependency graph.
Release binary size drops from 787,808 bytes to 654,464 bytes. cargo-bloat no longer reports clap_builder in the release text section.
Validated with cargo fmt, cargo check, cargo test, cargo build --release, --help/--version smoke checks, and JS/Rust token and cost parity for daily, session, monthly, weekly, and blocks.
* perf(ccusage): replace rayon in Rust loader
Replace Rayon file loading with a small scoped-thread worker split based on available parallelism. The CLI keeps parallel JSONL loading without carrying the Rayon and crossbeam dependency graph in the release binary.
Release binary size drops from 654,464 bytes to 637,472 bytes. cargo-bloat no longer reports rayon_core in the release text section.
Validated with cargo fmt, cargo check, cargo test, cargo build --release, cargo-bloat, and JS/Rust token and cost parity for daily, session, monthly, weekly, and blocks.
* perf(ccusage): remove chrono from Rust CLI
Replace the remaining chrono usage with a compact UTC millisecond timestamp and ISO date helper. The CLI only needs fixed-format UTC parsing/formatting, week-start date arithmetic, and block duration maths, while timezone date rendering still uses the existing Jiff dependency.
This removes chrono, num-traits, and autocfg from the Rust dependency graph.
Release binary size on arm64 macOS:
- before: 637,472 bytes at 4caad29
- after: 620,880 bytes
- change: -16,592 bytes
Validation:
- cargo fmt
- cargo check
- cargo test
- cargo build --release
- JS/Rust token and cost parity for daily/session/monthly/weekly/blocks
- target/release/ccusage --version
- target/release/ccusage daily --help
* feat(ccusage): add Rust pricing fetch and JS-style tables
Move Rust pricing into a dedicated module modeled after the Zig implementation, with an embedded Claude pricing fallback and native TLS LiteLLM fetch for online runs. The CLI now logs fetch start/completion like the JavaScript version, skips fetching for --offline and display mode, and keeps LOG_LEVEL=0 quiet for benchmark runs.
Align the Rust table renderer with the JavaScript/Zig output by using JS-style title boxes, horizontal separators between logical rows, responsive width scaling, stable date columns, multiline headers, model bullets, and block table formatting.
Validation: direnv exec . cargo fmt --all; direnv exec . cargo test -p ccusage; direnv exec . cargo build -p ccusage --release.
Release size: 620,880 bytes on branch baseline; 620,928 bytes after table-only changes; 757,040 bytes with embedded pricing plus native TLS online fetch. The rustls fetch attempt was rejected at 2,464,224 bytes. Runtime benchmark was deferred because Arc/cmux/lazygit were consuming CPU.
* fix(ccusage): preserve ANSI in Rust table truncation
Keep ANSI escape sequences intact when truncating responsive table cells so colored compact rows do not leak broken reset sequences or stray separators. This fixes the compact total row rendering seen in narrow terminals while keeping no-color output unchanged.
Main comparison note: Rust intentionally does not byte-match origin/main for duplicate message/request rows because it keeps the most complete duplicate entry. Example on 2026-01-09 daily: main outputTokens=62,totalTokens=490914,totalCost=1.62067595 while Rust outputTokens=911,totalTokens=491763,totalCost=1.64190095.
Validation: direnv exec . cargo fmt --all; direnv exec . cargo test -p ccusage; direnv exec . cargo build -p ccusage --release; COLUMNS=100 target/release/ccusage --offline with and without --no-color. Release size: 757,024 bytes.
* perf(ccusage): avoid Rust dedupe key allocations
Replace per-entry messageId/requestId string concatenation with a hashed lookup and collision-safe string comparison. This keeps duplicate replacement semantics unchanged while avoiding allocation of a combined key for every usage entry during global deduplication.
Also rename the Rust color helper from colour/Colour to color/Color so the existing spell-check workflow passes on this branch.
The rejected alternatives were opt-level=s, which increased binary size from 757024 to 854416 bytes without a speed win, and a manual JSON fast path, which slowed daily runs. Baseline/current JSON output matched for daily, session, and blocks.
* chore: pin Rust toolchain
Add rust-overlay to the flake and source the dev shell Rust compiler from rust-toolchain.toml so local development and CI use the same Rust 1.85.1 toolchain.
Include clippy and rustfmt in the pinned toolchain and replace the direct nixpkgs cargo/rustc/rustfmt packages. Fix the one clippy warning exposed by running the pinned toolchain with -D warnings.
* perf(ccusage): balance Rust workers by file size
Distribute Rust JSONL worker chunks by file size instead of contiguous file-count chunks. Large Claude JSONL files can otherwise leave one worker with the long tail while other workers finish early.
The final merge restores loaded files to the original file index order before aggregation, preserving dedupe and floating-point accumulation order. A regression test covers balanced chunk assignment.
Fixed snapshot parity with CLAUDE_CONFIG_DIR=/tmp/ccusage-data-snapshot/config: daily/session/blocks output matched the previous Rust binary byte-for-byte, with blocks compared after removing the time-dependent projection field.
Benchmarks on the fixed snapshot, LOG_LEVEL=0, --offline --json, hyperfine --warmup 3 --runs 12:
- daily old: 366.0ms ± 13.9ms; new: 364.8ms ± 83.7ms (effectively unchanged/noisy)
- session old: 407.0ms ± 40.5ms; new: 334.6ms ± 30.3ms (~1.22x faster)
- blocks old: 368.0ms ± 15.3ms; new: 342.5ms ± 13.9ms (~1.07x faster)
Binary size: 773k -> 790k (+17k).
Validation:
- nix develop --command cargo fmt --all --check
- nix develop --command cargo test --release
- nix develop --command cargo build --release
* perf(ccusage): tune Rust release optimization level
Switch the Rust release profile from opt-level z to opt-level 2. This keeps LTO, single codegen unit, panic abort, and symbol stripping, but gives LLVM enough room to optimize the hot JSONL/read/aggregation paths.
On real local Claude data with LOG_LEVEL=0, opt-level 2 produced a 952,784 byte arm64 macOS binary. The previous opt-level z build was 789,728 bytes and measured around daily 294.8ms, session 305.6ms, blocks 296.9ms in the latest JS comparison. The opt-level 2 build measured daily 245.5ms ± 3.6ms, session 248.7ms ± 3.6ms, and blocks 257.3ms ± 6.6ms. opt-level 3 was similar speed but larger at 1,002,544 bytes; opt-level s was smaller than 3 at 887,152 bytes but slower; opt-level 1 was both larger and slower.
Validation: direnv exec . cargo build --release; direnv exec . cargo test; JS/Rust daily totalTokens parity; JS/Rust blocks summed totalTokens parity.
* fix(ccusage): remove stale Rust locale option
The JavaScript ccusage CLI no longer exposes a --locale option, and the Rust implementation parsed the value without using it anywhere. Remove the stale field, parser branch, and help text so the Rust CLI surface matches the JavaScript CLI more closely.
This is a parity cleanup rather than a size win: the arm64 macOS release binary stayed at 952,784 bytes after strip/LTO.
Validation: direnv exec . cargo fmt --all --check; direnv exec . cargo test; direnv exec . cargo build --release; target/release/ccusage --help no longer lists --locale; target/release/ccusage --locale en-CA exits with code 2.
* perf(ccusage): optimize Rust dependencies for size
Mention: #977
Keep the workspace release profile at opt-level=2 for the ccusage crate, but compile non-workspace dependencies with opt-level="s". This keeps the hot ccusage code speed-oriented while letting std-adjacent dependency code shrink under fat LTO.
A/B on Apple M3 Pro, macOS 15.7.3, real local Claude JSONL data, LOG_LEVEL=0, hyperfine --warmup 4 --runs 10:
daily --offline --json: baseline 242.5ms +/- 3.5ms, dependency-size profile 242.0ms +/- 3.4ms.
session --offline --json: baseline 249.6ms +/- 4.9ms, dependency-size profile 246.5ms +/- 5.3ms.
blocks --offline --json: baseline 254.0ms +/- 5.2ms, dependency-size profile 250.9ms +/- 2.7ms.
Release binary size changed from 952,784 bytes to 936,640 bytes, 16,144 bytes smaller.
Rejected profile check: making the global release profile opt-level="s" and overriding only package.ccusage back to opt-level=2 produced a larger 1,080,576-byte binary, so this commit uses the inverse package override instead.
Validation: direnv exec . cargo fmt --all --check; direnv exec . cargo test; direnv exec . cargo build --release; wc -c target/release/ccusage.
* perf(ccusage): skip non-usage JSONL lines earlier
Mention: #977
Use the same usage-object marker as the JavaScript loader when deciding whether a Rust JSONL line should go through serde_json usage parsing. The previous input_tokens marker could match unrelated content and cause unnecessary parse attempts before falling back to timestamp extraction.
Real local Claude data, Rust release binary, LOG_LEVEL=0, hyperfine via comma, reverse-order confirmation against 7281959:
- daily --offline --json: 245.5ms -> 237.7ms
- session --offline --json: 250.7ms -> 240.8ms
- blocks --offline --json: 254.2ms -> 245.1ms
Release binary size stays exact 936,640 bytes. Stable JSON parity matched against 7281959 for daily, session, monthly, weekly, and blocks with projection removed.
Validation: direnv exec . cargo fmt --all --check; direnv exec . cargo test -p ccusage; direnv exec . cargo build --release -p ccusage.
* perf(ccusage): place rust worker results by index
Store parallel file-load results directly at their original file index instead of collecting index/file pairs, sorting them, and then mapping away the indexes.
This preserves output order while removing the reorder sort from the Rust worker merge path.
Fixed-snapshot parity matched for daily/session/monthly/weekly JSON and stable blocks JSON. Release binary size changed from 936640 bytes to 936624 bytes.
Benchmark on the fixed snapshot: daily --offline --json 252.9ms +/- 6.2ms baseline vs 251.3ms +/- 5.2ms indexed merge; session 256.1ms +/- 3.9ms vs 257.3ms +/- 4.9ms; blocks 261.3ms +/- 5.5ms vs 262.0ms +/- 4.5ms. Treat as size/tiny daily win with session/blocks effectively unchanged.
Validation: direnv exec . cargo fmt --all --check; direnv exec . cargo test -p ccusage; direnv exec . cargo build --release -p ccusage.
Refs #977
* ci(ccusage): compare rust performance against main
Add a Rust PR performance workflow that checks out the base branch, builds the base JavaScript CLI, builds the Rust PR release binary, generates synthetic Claude JSONL fixtures, and posts an upserted PR comment with same-run hyperfine ratios.
The comparison intentionally measures base/main through the fastest known JS path, bun -b dist/index.js, while measuring the PR side as target/release/ccusage directly. That keeps the comment focused on implementation runtime instead of Node launcher overhead.
The generated large fixture is shaped from aggregate local Claude-log statistics only: thousands of JSONL files, many small sessions, and a long tail of larger sessions. This avoids storing real prompts or outputs while exercising the multi-file loading path that matters for large user logs.
Local smoke result with the 1GiB shaped fixture: main JS/Bun daily --offline --json 15.099s, Rust PR 284.1ms, about 53.15x faster. CI will publish its own same-run numbers on the PR.
* ci(ccusage): benchmark rust package bin without shell
Resolve the ccusage package bin from apps/ccusage/package.json for both the base checkout and the Rust PR checkout, then execute that entry through the Bun executable already running the CI script.
This keeps the Rust comparison aligned with the command users install and run, including the JavaScript wrapper that launches the native binary, while avoiding pnpm exec and shell quoting in the measured command via hyperfine --shell none.
Package metadata is read with Bun.file rather than node:fs synchronous reads.
* feat(ccusage): add rust codex reports
Port the Codex token_count parser and direct Codex daily, monthly, and session reports into the Rust CLI.
The implementation reads CODEX_HOME sessions, mirrors Codex cached-input accounting, adds embedded gpt-5 pricing for offline reports, and keeps the change covered by Rust parser, CLI, and JSON aggregation tests.
* feat(ccusage): support rust claude namespace
Accept the main CLI namespace form for Claude reports in the Rust parser.
The alias delegates to the existing daily, monthly, weekly, session, blocks, and statusline commands so nested Claude invocations remain behaviourally equivalent to the legacy direct commands.
* feat(ccusage): add rust opencode reports
Port OpenCode daily, weekly, monthly, and session reports into the Rust CLI.
The loader reads OpenCode SQLite databases first, falls back to legacy storage/message JSON files, and deduplicates message IDs so database rows win over duplicate JSON records. It uses the smaller sqlite crate with bundled linkage to keep the native binary portable while reducing the release size compared with rusqlite.
Validated with focused OpenCode tests, the full Rust workspace tests, pnpm format, pnpm typecheck, and the full pnpm test suite.
* feat(ccusage): add rust amp reports
Add the Rust amp command for daily, monthly, and session reports while moving agent-specific Rust code under adapter modules to mirror the TypeScript adapter layout.
Amp thread JSON loading now reads usageLedger events, attaches cache tokens from assistant messages, preserves credits in JSON and table totals, and uses the same shared summary foundation as the OpenCode Rust adapter.
This keeps high-volume JSONL optimization concerns separate from the lower-volume agent JSON adapters; Claude and Codex parser hot paths should continue to follow marker-based parsing rather than full JSON object parsing where possible.
* ci(ccusage): reuse perf benchmark for rust
Extend the existing PR performance comparison script with a head runtime option so the same Claude and Codex fixture matrix can benchmark either the published package bin or the Rust release binary.
The Rust perf workflow now calls the shared benchmark script with --head-runtime rust, generates matching Codex large fixtures, writes the job summary, and drops the duplicate Rust-only comparison script.
* feat(ccusage): add rust pi reports
Add the pi-agent command path to the Rust CLI with daily, monthly, and session report support plus the --pi-path option from the TypeScript adapter.
The Rust adapter reads pi-agent JSONL session files, keeps only assistant usage entries, maps cache and cost fields into the shared usage summary shape, and preserves project and session metadata for reports.
* feat(ccusage): add rust all-agent reports
Route root daily, weekly, monthly, and session commands through an all-agent Rust adapter so they match the TypeScript command structure from origin/main. Keep the claude namespace on the existing Claude-specific report commands for flags such as instances, project aliases, and session IDs.
Aggregate Claude, Codex, OpenCode, Amp, and pi-agent rows into period-level all-agent JSON/table output, including agent metadata for JSON consumers and per-agent rows for session reports.
* perf(ccusage): parallelize rust codex loading
Load Codex JSONL session files in parallel by default using the existing size-balanced chunking strategy. Keep --single-thread as an escape hatch so benchmark and debugging runs can force the old sequential path.
Threading is scoped to file-level parsing, then events are sorted and deduplicated with the existing logic to preserve report output.
* perf(ccusage): reduce rust codex aggregation overhead
Avoid sorting the full Codex event vector before aggregation because reports already order periods through BTreeMap and lastActivity is computed by timestamp comparison.
Resolve the report timezone once per Codex aggregation/filter pass instead of per event, which removes repeated system timezone lookups on large JSONL corpora.
Add embedded fallback pricing for gpt-5.2-codex and gpt-5.3-codex so Rust Codex costs match the TypeScript adapter when offline.
* refactor(ccusage): move rust codex reports into adapter
Move Codex report aggregation, JSON rendering, table rendering, filtering, and cost helpers out of main.rs into crates/ccusage/src/adapter/codex.rs.
Keep the JSONL loader in place for now so this commit is a pure structure change. The all-agent adapter now reuses the codex adapter aggregation helpers instead of reaching through main.rs.
* perf(ccusage): aggregate rust codex reports during loading
Avoid building a global Codex token event vector for native report commands. The Codex command now groups usage while session files are read, so date filtering and period aggregation happen in the same pass as parsing.
Keep output parity by sharing sharded dedupe state across worker threads and CODEX_HOME session roots. The existing event loader remains available for other call sites, backed by the same visitor parser.
On the 1GiB synthetic Codex fixture, the release binary now runs about 4.8x faster than the TypeScript command and 4.3x faster than the native single-thread path.
* fix(ccusage): address rust cli review findings
Update native help output so it lists the agent namespace commands accepted by the parser.
Make fuzzy pricing lookup deterministic by selecting the longest matching model key with a stable tie-break, and add a timeout to the LiteLLM pricing fetch so offline fallback cannot be blocked indefinitely.
Also fix the benchmark snippet so the documented hyperfine command can be copied directly.
* fix(ccusage): address rust review followups
Guard benchmark PR comment upserts on forked pull requests so read-only fork tokens do not fail the workflow.
Use a Rust-specific marker for native performance comments, share all-agent pricing across Codex and Amp loading, and remove duplicated Codex event accumulation logic.
Keep the OpenCode provider validation explicit and add pricing regression coverage for overlapping model keys.
* build(ccusage): publish native platform packages
Add per-platform optional native packages for the Rust ccusage binary and make the published JS wrapper prefer the matching installed native binary before falling back to Bun or Node.
Stage native binaries into package-specific bin directories at build time, verify that native packages cannot be packed without their binary, and collect matrix-built artifacts before pkg-pr-new preview and npm publish.
* fix(ccusage): resolve native package prepack script
* refactor(ccusage): split rust cli modules
Move command orchestration, date utilities, and shared report types out of main.rs so the Rust implementation follows the existing TypeScript package shape more closely. The public crate-level names are re-exported to keep adapter code stable while reducing main.rs to the remaining loader, aggregation, and rendering helpers.
This is behavior-preserving; cargo fmt only adjusted a few existing pricing lines. Verified with pnpm run format, pnpm typecheck, direnv exec . pnpm run test, and direnv exec . cargo test -p ccusage.
* ci(ccusage): verify preview package with pnpm dlx
Add a pkg.pr.new preview E2E path that invokes the generated package through pnpm dlx. The existing npx path stays in place, while the new check covers the install command the PR is expected to support for manual testing.
Verified with actionlint on .github/workflows/ci.yaml.
* feat(ccusage): support rust codex speed pricing
Add the Codex speed option to the Rust CLI so codex reports accept the same auto, standard, and fast modes as the TypeScript command.
Thread the resolved speed through Codex report cost calculation and all-agent Codex aggregation. Fast mode now applies the pricing fast multiplier, while auto keeps reading Codex config.toml service_tier like the TypeScript adapter.
Also list the implemented Amp and pi-agent namespaces in the Rust help output, with parser tests covering the public command list.
* feat(ccusage): load rust cli config files
Add a Rust config loader that mirrors the ccusage JSON config merge path: defaults, command entries, shared agent command entries, and agent-specific defaults/commands are applied before parsing explicit CLI options.
This makes --config and auto-discovered .ccusage/ccusage.json settings affect Rust CLI reports instead of being parsed and ignored. Codex speed and pi path config are covered alongside shared options and Claude report-specific options.
The loader lives in a dedicated Rust config module to keep the CLI parser aligned with the TypeScript source layout.
* fix(ccusage): accept legacy rust agent commands
Normalize pre-nested agent command names such as codex:monthly before Rust CLI parsing, matching the TypeScript compatibility path.
The normalization only rewrites supported agent/report pairs, so unsupported legacy names still flow through the existing unknown-command errors.
* fix(ccusage): match rust cli guard errors
Add the Rust-side compatibility guards from the TypeScript command entrypoint for removed report flag aliases, removed --agent filters, and agent/report combinations that are not supported.
This keeps native parsing behavior aligned with the existing JS CLI while preserving the agent/report support table in one helper used by legacy colon commands as well.
* ci(ccusage): test preview package on windows arm
Add windows-11-arm to the preview package E2E matrix so pkg.pr.new installs are exercised on the Windows ARM native package as well as the existing x64 runner.
Use Node to validate JSON output instead of jq so the check does not depend on image-specific command availability across Windows runners.
* ci(ccusage): allow pnpm dlx preview installs
pkg.pr.new publishes the platform packages as URL optional dependencies. pnpm 11 rejects those transitive exotic dependencies by default during dlx, so pass block-exotic-subdeps=false for the preview E2E commands.
Also replace the remaining jq JSON check with Node so the preview job uses only the runtime installed by setup-node across all runners.
* ci(ccusage): run pnpm dlx against native preview packages
Keep the npx preview E2E on the top-level ccusage package so the Node wrapper still gets exercised.
For pnpm dlx, use the pkg.pr.new URL for the current platform native package directly. This avoids pnpm Windows URL optionalDependency handling while still proving that each native package, including win32 arm64, can be fetched and executed through pnpm dlx.
* fix(ccusage): resolve rust home paths on windows
Add a shared home directory resolver that falls back from HOME to USERPROFILE and HOMEDRIVE/HOMEPATH.
Use it from the Rust Claude, Codex, OpenCode, Amp, pi-agent, and config path discovery code so native Windows binaries work when the runner or user environment does not define HOME.
* feat(ccusage): show rust usage load progress
Add a Rust progress helper that mirrors the TypeScript usage-log loading text and suppresses itself for JSON, non-TTY, and LOG_LEVEL=0 runs.
Wire the helper through the Claude, Codex, OpenCode, Amp, and pi-agent loader entry points so table-mode commands expose loading status without contaminating JSON output.
Also apply cargo fmt to nearby Rust files after the new module landed.
* refactor(ccusage): split rust table output
Move the Rust table renderer, color helper, terminal-width detection, and box-title rendering out of main.rs into table.rs.
This keeps the existing public crate-level helper names through re-exports so adapters and command code do not change behavior while main.rs becomes closer to the TypeScript command/output split.
Validation: pnpm run format; pnpm typecheck; direnv exec . pnpm run test.
* refactor(ccusage): split rust session blocks
Move Rust session block grouping, projection, JSON, and table rendering helpers out of main.rs and into a dedicated blocks module.
This mirrors the TypeScript session-blocks structure more closely while preserving the existing crate-level call sites and behavior. The extraction keeps the large Rust entry file smaller without changing the tested CLI surface.
* refactor(ccusage): split rust cost calculation
Move Claude usage cost calculation into a dedicated Rust cost module that mirrors the TypeScript calculate-cost boundary.
The extraction keeps main.rs focused on orchestration while preserving the same tiered pricing and precomputed-cost behavior covered by existing tests.
* fix(ccusage): match rust project name paths
Move Rust project-name formatting helpers into a dedicated module that mirrors the TypeScript project-names boundary.
Add coverage for Windows user project paths and normalize those paths before display, matching the TypeScript formatter instead of leaking raw C:\Users-style paths.
* refactor(ccusage): split rust usage summaries
Move daily, weekly, monthly, and session summary aggregation into a dedicated Rust summary module.
This keeps the public crate helpers used by commands and adapters intact while reducing main.rs and matching the TypeScript grouping boundaries more closely.
* refactor(ccusage): split rust usage output
Move shared Rust JSON output, jq piping, usage table rendering, and display formatting helpers into a dedicated output module.
The extraction keeps the existing crate-level helpers available to commands and adapters while reducing main.rs and separating presentation from loading and aggregation.
* refactor(ccusage): split rust claude loader helpers
Move Claude loader path discovery, file traversal, timestamp parsing, date filtering, and reset-time parsing helpers into a dedicated Rust module.
The extraction keeps shared crate-level helpers available to commands and adapters while reducing main.rs and aligning the Rust layout with the TypeScript Claude loader boundary.
* refactor(ccusage): split rust claude loader
Move Claude JSONL loading, parallel file reading, deduplication, validation, and usage entry construction into the Rust Claude loader module.
This keeps the crate root focused on command dispatch and shared helpers while matching the TypeScript adapter/data-loader boundary more closely. The change preserves the existing loader API for commands and agent aggregation.
* refactor(ccusage): split rust codex loader
Move Codex session discovery, JSONL token event parsing, parallel session reads, and event deduplication into a dedicated Rust loader module.
This preserves the crate-level loader API used by all-agent reports and Codex reporting while reducing main.rs and matching the TypeScript adapter boundary more closely.
* refactor(ccusage): split rust shared helpers
Move Rust logging and small JSON/token helpers out of main.rs into focused modules.
This keeps the crate root closer to the TypeScript main entrypoint while preserving existing crate-level helper exports for the adapters and commands.
* feat(ccusage): add rust statusline context fallback
Parse the latest assistant usage line from the transcript when Claude Code does not provide context_window in the statusline hook payload.
The fallback matches the TypeScript behavior by counting input tokens plus cache creation and cache read tokens, ignoring output tokens, and using the 200k context limit default.
* feat(ccusage): add rust statusline cache
Implement the Rust statusline hybrid cache path used by the TypeScript command.
The command now stores statusline output under the ccusage-semaphore temp directory, reuses fresh entries when the transcript mtime is unchanged, marks in-progress updates, and falls back to stale output while a live updater is running.
This keeps hook invocations from repeating the full usage scan on every prompt while preserving transcript-based invalidation.
* feat(ccusage): match rust statusline context limits
Read LiteLLM max_input_tokens into the Rust pricing map and use it when statusline calculates context usage from a transcript.
This matches the TypeScript fallback path that uses the hook model id to choose a model-specific context limit instead of always assuming 200k tokens.
The statusline context formatter now applies the configured low and medium thresholds when choosing the percentage color.
* fix(ccusage): fail rust statusline without input
Return an error when the statusline command receives empty stdin instead of printing an error and exiting successfully.
This matches the TypeScript command behavior where hook input is required and empty input exits non-zero.
* fix(ccusage): align rust binary version
Keep the Rust crate version in sync with the npm package version so native package users see the published ccusage version from --version.
Add a regression test that reads the app package manifest and checks CARGO_PKG_VERSION against it to prevent future release metadata drift.
* fix(ccusage): address rust review findings
Include the Codex session id in token event deduplication so matching token counts from distinct sessions are preserved.
Use a provider-agnostic empty table message and preserve project names for /Users/<name>/<repo> paths while keeping existing Development path behavior.
* refactor(ccusage): remove TypeScript CLI implementation
Keep the npm package as a native Rust CLI wrapper instead of shipping the previous TypeScript implementation beside the Rust binary.
The JavaScript entrypoint now only resolves and spawns the platform optional native package. The old Bun and Node fallback entrypoints, TypeScript adapters, CLI commands, and their snapshot tests are removed so the package has one runtime implementation.
Update package scripts, tsdown and Vitest config, schema syncing, README/runtime docs, and CI references to match the native package layout. This also drops obsolete TypeScript runtime dependencies from the ccusage app manifest.
* ci(ccusage): stage native binary for package perf
The package perf workflow runs the PR through the published dist/cli.js wrapper. After removing the TypeScript fallback, that wrapper requires the platform optional native package to contain the freshly built Rust binary.
Stage the Linux arm64 binary into the workspace native package before running compare-pr-performance so the package runtime path matches the published package layout.
* refactor(ccusage): organize native rust workspace
Move the Rust workspace under rust/ so it matches the app-oriented monorepo layout instead of living at the repository root. Extract the terminal table renderer into a ccusage-terminal crate and remove the now-unused TypeScript internal and terminal helper packages.
Update package scripts, CI, release, benchmark, and native staging paths for the new workspace. The Linux package artifacts are now built with musl targets and verified as static binaries so pnpm dlx and bunx can run on NixOS without the glibc dynamic loader stub failure.
Align the Rust all-agents table with the TypeScript implementation by showing the Detected line in the title box and rendering per-agent breakdown rows under each All row while keeping compact mode columns consistent.
* fix(ccusage): use rustls for native https
Switch minreq from native-tls to rustls so Linux musl builds do not need OpenSSL discovery or dynamic system TLS libraries. This keeps the native package compatible with static Linux artifacts for NixOS while preserving online pricing fetch support.
* perf(ccusage): keep rustls limited to static linux
Use target-specific minreq TLS features so the musl Linux builds keep rustls for static NixOS-compatible binaries, while macOS and Windows return to native-tls and system TLS.
This brings the local macOS arm64 release binary back from 3,870,912 bytes to 2,003,792 bytes without changing the Linux musl static build path.
* fix(ccusage): ignore package runner separator
Accept a leading -- before ccusage options so package runner commands such as pnpm dlx <preview-url> -- --offline are parsed the same way as direct CLI execution.
This keeps the preview command that reproduced the NixOS dynamic-linker issue usable after the Rust parser replacement.
* Revert "fix(ccusage): ignore package runner separator"
This reverts commit a4c7b52e0ee47a7272ee1790ca99f0b8b07d7a7e.
* fix(ccusage): match rust all report display
Align the Rust all-agent report with the current TypeScript CLI output.
The all report now keeps source detection separate from date-filtered rows, so the Detected line still lists every available agent even when only one has rows in the selected range. The human table total token column also follows the TypeScript display total of input, output, cache creation, and cache read tokens.
Codex pricing now preserves whether LiteLLM supplied an explicit cache-read rate. When that rate is missing, Codex cached input falls back to normal input pricing like the TypeScript adapter. The embedded offline fallback also includes gpt-5.5 so offline runs do not fuzzy-match it to gpt-5.
The standalone Codex table now uses the same title, model bullets, and Cache Read column placement as bunx ccusage.
* perf(ccusage): slim native launcher
Reduce the published JavaScript launcher work before handing off to the native binary.
The launcher now resolves platform packages with direct early returns instead of allocating a Map at startup. It also avoids the per-run fs executable probe and uses spawnSync, removing the top-level await path from the bin entry.
This only affects the wrapper around the Rust binary. The real-data Claude benchmark remains dominated by the Rust loader, but short commands and package-runner startup have less JavaScript work.
* build(ccusage): use workspace native package deps
Reference the platform native packages through workspace:* in the monorepo instead of pinning the current version by hand.
This keeps local installs and lockfile resolution tied to the workspace packages while pnpm still converts the optional dependencies to the concrete package version in the packed tarball.
* perf(ccusage): scan claude jsonl as bytes
Profile the Rust Claude loader with macOS sample and reduce work in the JSONL scan path.
The loader now reads files as bytes, searches for usage records with memchr, and parses matching JSONL records with serde_json::from_slice. It also stops scanning non-usage lines for fallback timestamps because those lines do not produce usage entries for reports.
On the local real Claude dataset, direct Rust claude --offline --json improved from roughly 253ms to 228ms, with single-thread time dropping from roughly 1.07s to 0.94s. The release binary remains about 1.9 MiB on darwin arm64.
* perf(ccusage): aggregate claude daily summaries directly
Add a Claude daily fast path that reads only the fields needed for daily aggregation instead of materializing full LoadedEntry values. The path keeps the same dedupe, project grouping, cost modes, and TypeScript-style path ordering so JSON and table output stay compatible.
Accept CLAUDE_CONFIG_DIR values that point directly at a projects directory, which avoids a common local setup failure while preserving the existing config-root behavior.
Update embedded Codex pricing fallbacks for newer GPT-5 models and match the TypeScript adapter default fast-tier multiplier so offline Rust output stays aligned with bunx ccusage.
* fix(ccusage): include nested claude agent progress in daily reports
Parse nested Claude agent progress usage rows in the Rust daily fast path so model first-seen ordering matches the TypeScript parser while global dedupe keeps duplicate subagent rows from changing totals.
Add a regression test with a parent progress row and duplicate subagent row to lock the modelsUsed order against bunx ccusage.
* fix(ccusage): keep native package bins private
Remove the ccusage bin entry from platform-specific native packages so bunx resolves the root launcher instead of an arbitrary optional dependency binary. Bun can install multiple optional native packages from pkg.pr.new, and exposing the same bin name lets Linux/NixOS execute the darwin package by mistake.
Update native package verification to check the packaged binary listed in files rather than requiring a public bin field.
* ci(ccusage): comment perf results per commit
Include base and PR git SHAs in the ccusage perf markdown so benchmark comments identify exactly which revision was measured.
Use a SHA-specific comment marker in the perf workflows. Re-runs for the same commit update that commit comment, while a new PR commit creates a separate benchmark comment instead of overwriting the previous one.
* ci(ccusage): benchmark the PR head commit
Checkout the pull request head SHA in perf workflows so the SHA rendered in benchmark comments matches the commit being measured and the SHA-specific comment marker.
* ci(ccusage): report rust binary size in perf comments
Measure the Rust release binary for both base and PR checkouts when it exists and render it in the artifact-size table alongside the packed npm tarball.
This makes the per-commit perf comment show whether native binary size changed, instead of only reporting the ccusage package artifact.
* fix(ccusage): repair native binary mode before launch
pkg.pr preview installs can extract native package binaries without executable bits, which makes npx fail with spawnSync EACCES before the Rust binary starts.
The npm launcher now restores 0755 on non-Windows binaries before spawning. The preview E2E pnpm dlx path also uses the root ccusage package URL, because platform packages no longer expose their own bin entries.
* ci(ccusage): benchmark pkg.pr preview packages
Perf comments now install the base ccusage package from pkg.pr.new by base SHA instead of rebuilding the base checkout locally. The package perf workflow also installs the PR pkg.pr.new package for the measured PR command, so the execution benchmark uses the same package path users run.
The comment reports the pre-benchmark package acquisition time separately from bunx cold and warm startup. This keeps download/cache effects visible without mixing them into the hyperfine execution tables.
* ci(ccusage): avoid preview publish race in perf
The perf job can start before pkg.pr.new has published the current PR SHA. Requiring the PR package URL for the measured command made the package perf comment fail while waiting for that preview.
Keep the base runtime sourced from pkg.pr.new, but run the PR package benchmark from the checked-out build. PR bunx startup remains a separate optional measurement after the execution benchmark, so preview readiness does not block the whole perf comment.
* ci(ccusage): clarify package runner cache timing
Rename the package runner startup columns so the comment distinguishes execution setup from the user-visible bunx temporary cache path.
Extend the perf workflow wait window for pkg.pr.new preview URLs so the PR package startup row has a better chance to appear after preview publishing finishes.
* ci(ccusage): benchmark preview packages head to head
Use the PR pkg.pr.new package as the head runtime when a head preview URL is provided, so normal perf compares main/base pkg.pr.new against the commit hash pkg.pr.new package.
Fetch the head package artifact size from pkg.pr.new as well, keeping the size table aligned with the artifacts users actually download through preview package runners.
* docs(skills): add ccusage rust workflow guidance
Add a repo-local Rust skill that keeps the native implementation aligned with the TypeScript adapter structure, pricing embedding expectations, and perf-book based optimization workflow.
Update ccusage testing and TDD guidance with repo-specific cargo commands, and keep the similarity skill on the new similarity-rs workflow for Rust duplication checks.
* refactor(ccusage): split opencode rust adapter
Move OpenCode loading and parsing into adapter-local modules instead of keeping file, SQLite, parser, and report code in one adapter file.
Keep tests with the loader module so the Rust layout follows the TypeScript adapter responsibility boundaries without compatibility re-export shims.
* build(ccusage): embed litellm pricing at compile time
Add a Rust build script that fetches LiteLLM model pricing into OUT_DIR so the native binary embeds a build-time snapshot like the TypeScript macro path.
Keep the checked-in pricing JSON as a fallback snapshot for offline builds or fetch failures, and rename it away from the Claude-only filename.
* ci(ccusage): skip pnpm dlx preview on windows
Windows pnpm dlx can install the root preview package while leaving the optional native package binary missing from its dlx cache, producing ENOENT for ccusage.exe.
Keep Windows covered through native package builds and npx preview E2E, while retaining pnpm dlx preview checks on Linux and macOS where the package cache path works.
* refactor(ccusage): split opencode rust path discovery
Move OpenCode data directory discovery into a dedicated paths module so the Rust adapter follows the TypeScript adapter boundaries more closely.
This keeps loader focused on SQLite, JSON file loading, and dedupe while preserving OPENCODE_DATA_DIR and default path behavior.
* build(ccusage): compact embedded pricing snapshot
Filter LiteLLM pricing during the Rust build so the embedded snapshot keeps only fields used by the runtime cost calculator and only model families ccusage reports need offline.
This preserves build-time fetching with a checked-in offline fallback while reducing the release binary constant data section substantially.
* build(ccusage): shrink native release binary
Optimize the native release build for binary size while keeping the OpenCode SQLite path enabled.
The release profile now uses opt-level z for the ccusage binary. Cargo env config also compiles bundled SQLite without features that ccusage does not use for read-only OpenCode message loading, such as extension loading, UTF-16 APIs, JSON SQL functions, and compile-option diagnostics.
Fresh macOS release measurements dropped from 2,102,992 bytes after pricing compaction to 1,704,656 bytes, with gzip size at 895,933 bytes. OpenCode SQLite loader tests and the full test suite pass with the trimmed SQLite build.
* perf(ccusage): use Bun native spawn for wrapper
Avoid routing the published CLI wrapper through Bun node:child_process compatibility when the command is executed by Bun.
The wrapper now selects Bun.spawnSync when global Bun is available and keeps node:child_process.spawnSync as the Node fallback. This preserves the native package launcher behavior while reducing package-runner overhead in bunx benchmarks.
Validated with format, typecheck, the full test suite, and local hyperfine comparisons between bun -b dist/cli.js and the Rust binary.
* perf(ccusage): spawn native wrapper asynchronously
Replace the published CLI wrapper synchronous native process launch with async spawn.
Bun executions now use Bun.spawn and Node executions use node:child_process.spawn. Both paths stream stdio through to the native binary and await process exit instead of using synchronous spawn APIs.
This targets the package-runner benchmark path where the JavaScript wrapper was slower than the direct Rust binary on large fixtures.
* ci(ccusage): benchmark installed package entry
Use the installed ccusage package bin target instead of the package manager .bin shim for package runtime benchmarks.
The benchmark still installs the pkg.pr.new package before measurement, but it now resolves node_modules/ccusage/package.json and runs the published bin entry directly. This avoids measuring pnpm shim behavior under Bun, which is not representative of bunx package execution.
A Vitest case covers the installed package bin resolution.
* fix(ccusage): align rust session json parity
Match the Rust session and all-agent JSON output to the TypeScript implementation for the stable comparison window. Claude sessions now use file-based session IDs, filter by last activity like TypeScript, and skip nullable schema fields that the TS loader rejects instead of letting serde Option absorb them.
Normalize agent session JSON for Amp, OpenCode, and pi-agent so direct reports omit TypeScript-only absent fields while pi-agent keeps its session metadata. The root all session report now keeps per-agent rows without fallback agents metadata, and the all session key matches the TypeScript "session" shape.
Add the exact Claude 3.5 Haiku dated fallback pricing key used by Amp logs so offline costs match TypeScript. OpenCode SQLite support remains enabled and covered by the existing SQLite loader tests.
* ci(ccusage): benchmark cached bunx execution
Add a large-fixture benchmark path that runs pkg.pr.new packages through bunx after the Bun install cache has already been populated by the startup measurement.
This separates package fetch/cache materialization from cached runner execution, so PR comments can show whether the Rust package path pays off on large real-world-shaped inputs when users rerun bunx from cache.
* ci(ccusage): diagnose package runtime overhead
Add a large-fixture diagnostic table that benchmarks the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same runner.
This separates JavaScript wrapper overhead from the published native package build, which is necessary because direct Rust benchmarks are fast while pkg.pr.new and bunx package paths are slow on CI large fixtures.
* perf(ccusage): use mimalloc for linux musl binaries
The CI package diagnostics show that the installed Linux native optional dependency is much slower than the workspace release binary, while the JavaScript wrapper adds little overhead.
Use mimalloc only for linux-musl builds so the NixOS-compatible static package path can avoid musl malloc contention without changing macOS, Windows, or native GNU builds.
* ci(ccusage): report native package binary size
The Rust release binary size row reports the workspace build, but package performance depends on the installed optional native package binary.
Add base and PR installed native package binary sizes to the perf comment artifact table so allocator and Linux packaging changes show their actual distributed binary-size impact.
* build(ccusage): reduce linux musl tls size
Replace the runtime pricing fetch dependency on minreq with ureq using rustls/ring. The build script still uses minreq for build-time pricing snapshots, but the shipped binary no longer pulls the AWS-LC runtime TLS implementation into the Linux musl artifact.
This keeps HTTPS pricing refreshes and timeout behavior while raising the response body limit above the ureq default 10MB cap. The final stripped x86_64 musl binary drops from 5,109,944 bytes to 3,348,408 bytes in the Docker build check, with large fixture runtime remaining within benchmark noise.
* perf(ccusage): stream json output through buffers
Avoid allocating formatted JSON into an intermediate String before wr…1 parent fa95686 commit a2ca34a
189 files changed
Lines changed: 15512 additions & 28476 deletions
File tree
- .agents/skills
- ccusage-agent-sources
- ccusage-development
- ccusage-rust
- ccusage-testing
- reduce-similarities
- tdd
- references
- .cargo
- .claude/skills
- .github
- scripts
- workflows
- apps/ccusage
- scripts
- src
- adapter
- amp
- claude
- codex
- opencode
- pi
- commands
- test
- snapshots/cli-output
- docs/guide
- packages
- ccusage-darwin-arm64
- ccusage-darwin-x64
- ccusage-linux-arm64
- ccusage-linux-x64
- ccusage-win32-arm64
- ccusage-win32-x64
- internal
- src
- terminal
- src
- rust
- crates
- ccusage-terminal
- src
- ccusage
- src
- adapter
- opencode
- commands
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
10 | 30 | | |
11 | 31 | | |
12 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
20 | | - | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
26 | | - | |
| 34 | + | |
27 | 35 | | |
28 | 36 | | |
29 | | - | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | | - | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
45 | | - | |
46 | | - | |
| 53 | + | |
| 54 | + | |
47 | 55 | | |
48 | 56 | | |
49 | 57 | | |
50 | | - | |
51 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
52 | 61 | | |
53 | 62 | | |
54 | 63 | | |
55 | | - | |
| 64 | + | |
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments