Skip to content

feat: fix --breakdown broken flag#1083

Closed
IXackerr wants to merge 1 commit into
ryoppippi:mainfrom
IXackerr:main
Closed

feat: fix --breakdown broken flag#1083
IXackerr wants to merge 1 commit into
ryoppippi:mainfrom
IXackerr:main

Conversation

@IXackerr
Copy link
Copy Markdown

@IXackerr IXackerr commented May 19, 2026

Summary

  • The --breakdown flag was silently ignored in the multi-agent ("all") table — it only showed per-agent rows (Claude, Kilo, etc.) but never per-model cost/token breakdowns
  • Per-model breakdowns now render under each agent row when --breakdown is passed: Date → All → - Claude → - opus-4-6 / - haiku-4-5
  • Model breakdown data is included in --json output via modelBreakdowns on each row
  • Codex adapter also gets per-model breakdowns from its CodexGroup.models map

Root cause

When the Rust CLI replaced the TypeScript implementation, AllRow was introduced without a model_breakdowns field. summary_rows() discarded UsageSummary.model_breakdowns during conversion, and print_table() never checked shared.breakdown.

Test plan

  • ccusage --breakdown shows per-model rows with tokens and cost under each agent
  • ccusage (no flag) output is unchanged
  • ccusage --breakdown --json includes modelBreakdowns array per row
  • All 177 existing tests pass (2 pre-existing platform-specific failures unrelated)

Summary by cubic

Fixes the --breakdown flag in ccusage so per-model token and cost breakdowns appear under each agent and in the aggregated “all” row. Also includes these breakdowns in --json output and adds Codex per-model breakdowns.

  • Bug Fixes
    • Added model_breakdowns to AllRow, aggregated across agents, sorted by cost, and rendered when --breakdown is set.
    • Included modelBreakdowns in --json output for each row.
    • Codex now reports per-model breakdowns from CodexGroup.models and uses calculate_codex_model_cost.
    • Output without the flag is unchanged.

Written for commit 0e5c4e7. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • New Features
    • Usage reports now include per-model cost breakdowns.
    • JSON output now displays model breakdown information for each row.
    • Table display now renders model-level breakdown rows when breakdown mode is enabled.

Review Change Stack

@github-actions
Copy link
Copy Markdown

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this May 19, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4c81b19c-9928-4aa1-9d13-d748a6e582e5

📥 Commits

Reviewing files that changed from the base of the PR and between 8378395 and 0e5c4e7.

📒 Files selected for processing (2)
  • rust/crates/ccusage/src/adapter/all.rs
  • rust/crates/ccusage/src/adapter/codex.rs

📝 Walkthrough

Walkthrough

This PR extends the usage-report data model to include per-model cost breakdowns. Codex row generation builds sorted ModelBreakdown entries per model; aggregation merges breakdowns across rows by model name; JSON and table output conditionally render the breakdowns when breakdown mode is enabled.

Changes

Per-Model Cost Breakdowns

Layer / File(s) Summary
Data model extension for model breakdowns
rust/crates/ccusage/src/adapter/all.rs (imports, struct, summary_rows)
AllRow struct gains a model_breakdowns field; imports are updated for ModelBreakdown types; summary_rows populates breakdowns from UsageSummary.
Codex breakdown generation and cost helper refactor
rust/crates/ccusage/src/adapter/all.rs (codex_group_row), rust/crates/ccusage/src/adapter/codex.rs
codex_group_row constructs per-model breakdowns with non-cached input token computation and sorts by descending total cost; cost helper renamed to calculate_codex_model_cost, exposed as pub(crate), and integrated into group-cost mapping.
Aggregation of breakdowns across rows
rust/crates/ccusage/src/adapter/all.rs (AllAccumulator, aggregate helper)
New aggregate_model_breakdowns helper merges ModelBreakdown entries by model name, summing token and cost fields; aggregated results are sorted and embedded into the "all" row.
Output rendering for model breakdowns
rust/crates/ccusage/src/adapter/all.rs (row_json, print_table, push_model_breakdown_rows)
JSON output includes modelBreakdowns field; table rendering conditionally displays breakdown rows via new push_model_breakdown_rows helper when breakdown mode is enabled, supporting both agent and direct model breakdowns.
Test fixture updates for model breakdowns
rust/crates/ccusage/src/adapter/all.rs (test literals), rust/crates/ccusage/src/adapter/codex.rs (test calls)
All test AllRow literals populated with model_breakdowns: Vec::new(); Codex cost helper test calls updated to use renamed calculate_codex_model_cost function.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ryoppippi/ccusage#1067: New AllRow/modelBreakdowns generation directly depends on Codex "non-cached" inputTokens semantics introduced in that PR.
  • ryoppippi/ccusage#1061: This PR's Codex cost helper rename and Speed::Fast pricing test updates overlap with that PR's Codex fast pricing behavior.
  • ryoppippi/ccusage#1028: Both PRs modify adapter/all.rs; this PR's per-model aggregation feeds into the unified "all" row wired by that PR.

Suggested labels

enhancement

Suggested reviewers

  • ryoppippi

Poem

🐰 A thousand models now find their place,
Breaking down costs with grace and space,
Aggregated, sorted, rendered clean—
Per-model clarity, no cache unseen!
The report now whispers what once was loud. ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant