Skip to content

fix(cc-economics): accept ccusage v20 'period' field via serde alias#2838

Closed
Greonzhin wants to merge 1 commit into
rtk-ai:developfrom
Greonzhin:fix/ccusage-v20-period
Closed

fix(cc-economics): accept ccusage v20 'period' field via serde alias#2838
Greonzhin wants to merge 1 commit into
rtk-ai:developfrom
Greonzhin:fix/ccusage-v20-period

Conversation

@Greonzhin

Copy link
Copy Markdown

Problem

rtk cc-economics (and its --daily / --weekly breakdowns) fails with ccusage >= 20:

rtk: Failed to fetch ccusage monthly data: Failed to parse ccusage JSON output:
Invalid JSON structure for monthly data: missing field `month` at line 39 column 5

ccusage v20 switched its root daily / weekly / monthly commands to a unified multi-agent schema where the period-key field is always named period (plus new agent / metadata fields, which serde already ignores):

{ "monthly": [ { "agent": "all", "period": "2026-05", "inputTokens": 15838, "totalCost": 659.17, ... } ] }

src/analytics/ccusage.rs requires date / week / month respectively, so deserialization fails for all three granularities. All other required fields (inputTokens, outputTokens, totalTokens, totalCost) are unchanged in v20.

Fix

Add #[serde(alias = "period")] to the three entry structs. This is backward-compatible: old ccusage versions still emit date / week / month, new ones emit period, and the two never appear together.

Verification

  • Reproduced on rtk 0.42.4 and dev-0.44.0-rc.308 with ccusage 20.0.14 (pnpm global, Windows 11).
  • Verified the equivalent field-mapping end-to-end on the same machine via a PATH shim that routes rtk's exact invocations to ccusage claude <granularity> (which still emits the legacy field names): cc-economics, --daily, --weekly, and --all all render correctly with the legacy names mapped.
  • Note: this branch is not compiled locally (no Rust toolchain on this machine) — the change is attribute-only; CI should verify the build.

🤖 Generated with Claude Code

@CLAassistant

CLAassistant commented Jul 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aeppling

aeppling commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hey @Greonzhin
thanks for this contribution, already solved in #2732

@aeppling aeppling closed this Jul 7, 2026
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.

3 participants