Skip to content

bug: unified session report sorts by ID instead of documented highest cost first #1718

Closed

Description

@ravsau

What happened?

ccusage session sorts the unified report by session ID instead of highest cost first. This makes expensive sessions hard to find and contradicts the session guide.

The guide explicitly covers the unified command, then says:

Sessions are sorted by cost (highest first) by default

In my 247-session JSON report, the first row cost about $0.04 while a later row cost $21.22. The rows were ordered lexically by session ID.

Steps to reproduce

With local usage containing multiple sessions whose costs do not follow session-ID order:

npx --yes [email protected] session --offline --json > sessions.json
jq '.session | map({id: .period, cost: .totalCost})' sessions.json
jq '.session | map(.totalCost) | . == (sort | reverse)' sessions.json

The last check returns false for my report. My captured run used --since 20260912 --until 20260913; those filters can be omitted or changed to a window containing your own sessions.

Expected behavior

Unified sessions should default to descending total cost, matching the guide.

The current source explains the discrepancy: the session branch calls sort_rows, which compares period, then agent. For session rows, period is the session ID. Reversing that order still does not rank by cost.

Related: #903 is closed and reported last-activity sorting. This report concerns session-ID ordering in the unified report in 20.0.20.

I'll work on a fix to restore highest-cost-first ordering for unified sessions, with deterministic ties and regression coverage for table and JSON output.

Version

20.0.20 via npm/npx, macOS arm64. Source inspected at 48dfe97f336ae6f7912b4b386116e962e246ae47.

Activity

  1. pullfrog commented on Sep 13, 2026

    @pullfrog
    Contributor
  2. added
    bugSomething isn't working
    priority:mediumA normal bug or meaningful improvement.
    triage:maintainableFits the repository's maintainable scope and needs review.
    on Sep 13, 2026
  3. github-actions commented on Sep 13, 2026

    @github-actions
    Contributor

    Pullfrog triage: priority:medium
    Kind: bug
    Maintenance fit: maintainable
    Confidence: high

    Unified session rows sort by period, which is session ID, while the session guide promises cost highest first. Reporter shows $0.04 first with $21.22 later. Code and docs confirm mismatch. Distinct from #903 last-activity report. Bounded sort fix preserves documented core promise.

    Decision: kept open.

  4. added a commit that references this issue on Sep 15, 2026
    ff0f032
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

    bugSomething isn't workingpriority:mediumA normal bug or meaningful improvement.triage:maintainableFits the repository's maintainable scope and needs review.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions