Skip to content

Conversation

@mjyoo2
Copy link

@mjyoo2 mjyoo2 commented Jan 20, 2026

Summary

Add modelBreakdowns field to @ccusage/opencode JSON output for feature parity with ccusage (Claude Code).
Currently @ccusage/opencode only provides modelsUsed (model name array), while ccusage provides detailed modelBreakdowns with per-model token counts and costs.

Changes

  • Add modelBreakdowns array to JSON output in daily, weekly, monthly, and session reports
  • Each breakdown includes: modelName, inputTokens, outputTokens, cacheCreationTokens, cacheReadTokens, cost
  • Backward compatible - modelsUsed array is preserved

Before/After

Before

{
  "daily": [{
    "date": "2026-01-20",
    "inputTokens": 228,
    "outputTokens": 346277,
    "totalCost": 95.38,
    "modelsUsed": ["claude-opus-4-5", "gpt-5.2-codex"]
  }]
}

After

{
  "daily": [{
    "date": "2026-01-20",
    "inputTokens": 228,
    "outputTokens": 346277,
    "totalCost": 95.38,
    "modelsUsed": ["claude-opus-4-5", "gpt-5.2-codex"],
    "modelBreakdowns": [
      {
        "modelName": "claude-opus-4-5",
        "inputTokens": 200,
        "outputTokens": 340000,
        "cacheCreationTokens": 7268400,
        "cacheReadTokens": 82593000,
        "cost": 94.50
      },
      {
        "modelName": "gpt-5.2-codex",
        "inputTokens": 28,
        "outputTokens": 6277,
        "cacheCreationTokens": 0,
        "cacheReadTokens": 0,
        "cost": 0.88
      }
    ]
  }]
}

Summary by CodeRabbit

  • New Features
    • All reports enhanced with per-model breakdowns. Daily, weekly, monthly, and session reports now display comprehensive metrics for each AI model used, including input tokens, output tokens, cache tokens, and associated costs. Breakdowns are sorted by cost for easier identification of resource allocation.

✏️ Tip: You can customize this high-level summary in your review settings.

Add per-model token breakdown to all opencode commands for consistency
with ccusage output. This enables tracking usage across different models.

Modified commands:
- daily: includes modelBreakdowns in JSON output
- monthly: includes modelBreakdowns in JSON output
- weekly: includes modelBreakdowns in JSON output
- session: includes modelBreakdowns in JSON output

Each breakdown contains:
- modelName, inputTokens, outputTokens
- cacheCreationTokens, cacheReadTokens, cost

Implementation matches ccusage exactly:
- TokenStats type for aggregation
- createModelBreakdowns() helper function
- Sorted by cost descending
- Skip <synthetic> model
- Fallback to 'unknown' for missing model names
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

This PR introduces per-model token and cost aggregation across four report command files (daily, monthly, session, weekly). Each command now accumulates metrics separately per model, creates sorted breakdowns, and extends output structures with a modelBreakdowns array. Synthetic model entries are skipped during aggregation.

Changes

Cohort / File(s) Summary
Per-model aggregation across report commands
apps/opencode/src/commands/daily.ts, apps/opencode/src/commands/monthly.ts, apps/opencode/src/commands/session.ts, apps/opencode/src/commands/weekly.ts
Introduces TokenStats and ModelBreakdown types to track per-model input/output/cache tokens and costs. Adds createModelBreakdowns helper to convert per-model aggregates into a sorted array by cost. Implements per-model aggregation logic using Map<string, TokenStats> while skipping synthetic entries. Extends report data structures with modelBreakdowns arrays and updates export flows accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • ryoppippi

Poem

🐰 A rabbit's ode to model breakdowns:
Per-model tokens now shine so bright,
Aggregates sorted by cost in sight,
Synthetic entries hop away,
ModelBreakdowns guide the day! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: adding modelBreakdowns to JSON output across opencode commands (daily, weekly, monthly, session).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant