fix(cc-economics): accept ccusage v20 'period' field via serde alias#2838
Closed
Greonzhin wants to merge 1 commit into
Closed
fix(cc-economics): accept ccusage v20 'period' field via serde alias#2838Greonzhin wants to merge 1 commit into
Greonzhin wants to merge 1 commit into
Conversation
Contributor
|
Hey @Greonzhin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rtk cc-economics(and its--daily/--weeklybreakdowns) fails with ccusage >= 20:ccusage v20 switched its root
daily/weekly/monthlycommands to a unified multi-agent schema where the period-key field is always namedperiod(plus newagent/metadatafields, which serde already ignores):{ "monthly": [ { "agent": "all", "period": "2026-05", "inputTokens": 15838, "totalCost": 659.17, ... } ] }src/analytics/ccusage.rsrequiresdate/week/monthrespectively, 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 emitdate/week/month, new ones emitperiod, and the two never appear together.Verification
ccusage claude <granularity>(which still emits the legacy field names):cc-economics,--daily,--weekly, and--allall render correctly with the legacy names mapped.🤖 Generated with Claude Code