Skip to content

Inconsistent totals handling when no data exists across ccusage apps #832

Description

@vedang

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

Activity

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

    priority:mediumA normal bug or meaningful improvement.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions