Skip to content

cc-economics: monthly totals and the summary keep only the last per-project ccusage row #4761

Closed

Description

@KuSh

rtk cc-economics --monthly and the default rtk cc-economics summary report only the last ccusage row for a month when ccusage emits more than one row per month. ccusage 18 does this when per-project grouping is on ("groupByProject": true in its config file). The rows carry no project field in JSON, and merge_monthly in src/analytics/cc_economics.rs calls set_ccusage once per row on the same map entry, so each row overwrites the previous one.

Measured with ccusage 18.0.11 on real Claude Code logs, config {"commands":{"monthly":{"groupByProject":true}}}: ccusage returns 27 rows for 3 months.

month sum of ccusage rows rtk cc-economics --monthly
2026-08 $713.21 $27.58
2026-09 $7,237.07 $104.18
2026-10 $5,310.88 $26.33

The summary view builds its totals from the same merge_monthly, so its spend figure and the derived cost-per-token are understated by the same amount. Daily is not affected: ccusage 18 emits one row per day there.

#4409 fixes the same overwrite for weekly rows with aggregate_weekly_periods in src/analytics/ccusage.rs. Summing duplicate monthly rows the same way would close this. The test would feed two rows for the same month and assert the summed cost and token counts.

Activity

  1. rtk-wshm-sync-bot commented on Oct 23, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 95%

    Summary

    merge_monthly in src/analytics/cc_economics.rs overwrites instead of sums duplicate per-project ccusage rows for a month, understating monthly and summary totals by up to ~75%.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/analytics/cc_economics.rs
    • src/analytics/ccusage.rs

    Suggested Actions

    1. Apply the same sum-based fix used in fix(analytics): align weekly spending joins and aggregate project rows #4409's aggregate_weekly_periods to merge_monthly
    2. Add a regression test feeding two rows for the same month, asserting summed cost/tokens
    3. Verify the default summary view (which reuses merge_monthly) is fixed by the same change
    4. Reference ccusage 18 groupByProject config and the 27-row/3-month repro data from the issue

    Triaged automatically by wshm · This is an automated analysis, not a human review.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions