Skip to content

One invocation for multiple report sections: --sections and --by-agent on unified commands #1392

Description

@ben-vargas

What do you want to change?

Two additive flags on the unified commands:

  • --sections daily,monthly,session — emit several groupings in one JSON envelope from a single run, instead of one invocation per section.
  • --by-agent — include the per-agent breakdown on each unified row, instead of one invocation per agent.

With no flags, output stays byte-identical to today.

Why?

I poll ccusage from an app that wants daily, monthly, and session views plus per-agent detail. Today that's 3 unified invocations plus one per agent — each one re-scanning every store, re-parsing every file, and re-loading pricing, even though daily/weekly/monthly are all derived from the same entries. With a dozen agents that's ~15 full pipeline runs per refresh, and it gets slower as stores grow.

There's also a consistency problem: agents append to their stores constantly, so sections fetched by separate invocations can disagree with each other (the session total moves between call 1 and call 3). One invocation reads the stores once, so everything in the envelope is from the same snapshot.

The per-agent side is the same story: the unified run already computes per-agent breakdowns internally and throws them away at serialization time.

How? (optional)

--sections maps to at most two store scans (daily/weekly/monthly share one load; session adds one), and each section is produced by the same code path its standalone command uses, so section output matches a standalone run exactly. --by-agent serializes the existing internal per-agent accumulator as an agents array on daily/weekly/monthly rows (session rows are already per-agent). Table output renders requested sections sequentially; --by-agent is JSON-only.

I have this implemented — tests include fixture equivalence against standalone runs and a no-flags byte-identical check — and can open a PR.

Activity

  1. pullfrog commented on Jul 4, 2026

    @pullfrog
    Contributor
  2. ben-vargas commented on Jul 10, 2026

    @ben-vargas
    ContributorAuthor

    Closed with merge of #1396

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions