Hi maintainers,
I am trying to build some scripting which relies on the output of the --json ccusage command. As part of this work, I have uncovered some bugs in the way all the ccusage apps currently report data. This bug report is one of them.
I will submit a PR resolving this issue soon, creating an issue first to track the problem and my thinking around fixing it.
Issue Description
The ccusage apps have inconsistent behavior when no usage data exists. The reference app (ccusage) is itself inconsistent, and the other apps do not follow a consistent pattern. This makes it difficult to write scripts that work across all apps.
Current Behavior
ccusage (Reference App)
Behaviour today:
| Command |
Output when no data exists |
daily --json |
[] (no totals field) |
monthly --json |
{ monthly: [], totals: {all zeros} } |
session --json |
[] (no totals field) |
weekly --json |
{ weekly: [], totals: {all zeros} } |
Pattern: ccusage is inconsistent - only monthly and weekly include a totals field with zeros.
ccusage-codex
Behaviour today:
| Command |
Output when no data exists |
daily --json |
{ daily: [], totals: null } |
monthly --json |
{ monthly: [], totals: null } |
session --json |
{ sessions: [], totals: null } |
weekly --json |
Flag not supported |
Pattern: All commands return totals: null.
ccusage-opencode
Behaviour today:
| Command |
Output when no data exists |
daily --json |
{ daily: [], totals: null } |
monthly --json |
{ monthly: [], totals: null } |
session --json |
{ sessions: [], totals: null } |
weekly --json |
{ weekly: [], totals: null } |
Pattern: All commands return totals: null.
ccusage-amp
Behaviour today:
| Command |
Output when no data exists |
daily --json |
{ daily: [], totals: null } |
monthly --json |
{ monthly: [], totals: null } |
session --json |
{ sessions: [], totals: null } |
weekly --json |
Flag not supported |
Pattern: All commands return totals: null.
ccusage-pi
Behaviour today:
| Command |
Output when no data exists |
daily --json |
[] (no totals field) |
monthly --json |
[] (no totals field) |
session --json |
[] (no totals field) |
weekly --json |
Flag not supported |
Pattern: All commands return [] with no totals field.
Changes needed:
- ccusage: Update
daily and session to include totals with zeros (already does in monthly and weekly)
- ccusage-codex: Change
totals: null → totals: {zeros}, add support for weekly
- ccusage-opencode: Change
totals: null → totals: {zeros}
- ccusage-amp: Change
totals: null → totals: {zeros}, add support for weekly
- ccusage-pi: Change
[] → { daily: [], totals: {zeros} }, add support for weekly
Hi maintainers,
I am trying to build some scripting which relies on the output of the
--jsonccusage command. As part of this work, I have uncovered some bugs in the way all the ccusage apps currently report data. This bug report is one of them.I will submit a PR resolving this issue soon, creating an issue first to track the problem and my thinking around fixing it.
Issue Description
The ccusage apps have inconsistent behavior when no usage data exists. The reference app (
ccusage) is itself inconsistent, and the other apps do not follow a consistent pattern. This makes it difficult to write scripts that work across all apps.Current Behavior
ccusage (Reference App)
Behaviour today:
daily --json[](no totals field)monthly --json{ monthly: [], totals: {all zeros} }session --json[](no totals field)weekly --json{ weekly: [], totals: {all zeros} }Pattern: ccusage is inconsistent - only
monthlyandweeklyinclude a totals field with zeros.ccusage-codex
Behaviour today:
daily --json{ daily: [], totals: null }monthly --json{ monthly: [], totals: null }session --json{ sessions: [], totals: null }weekly --jsonPattern: All commands return
totals: null.ccusage-opencode
Behaviour today:
daily --json{ daily: [], totals: null }monthly --json{ monthly: [], totals: null }session --json{ sessions: [], totals: null }weekly --json{ weekly: [], totals: null }Pattern: All commands return
totals: null.ccusage-amp
Behaviour today:
daily --json{ daily: [], totals: null }monthly --json{ monthly: [], totals: null }session --json{ sessions: [], totals: null }weekly --jsonPattern: All commands return
totals: null.ccusage-pi
Behaviour today:
daily --json[](no totals field)monthly --json[](no totals field)session --json[](no totals field)weekly --jsonPattern: All commands return
[]with no totals field.Changes needed:
dailyandsessionto include totals with zeros (already does inmonthlyandweekly)totals: null→totals: {zeros}, add support forweeklytotals: null→totals: {zeros}totals: null→totals: {zeros}, add support forweekly[]→{ daily: [], totals: {zeros} }, add support forweekly