[PR #6296] feat: add model usage statistics with input/output token breakdown to stats command #11823

Closed
opened 2026-02-16 18:16:45 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6296

State: closed
Merged: Yes


Summary

This PR enhances the stats command to provide granular visibility into model usage. It introduces a new "MODEL USAGE" section that displays message counts, a breakdown of input vs. output tokens, and historical accumulated costs for each model used across sessions.

Changes

  • Interface Update: Extended SessionStats to include a modelUsage record.
  • Aggregation Logic: Updated aggregateSessionStats to collect and sum usage metrics (messages, tokens, cost) per provider/model from assistant messages.
  • New Flag: Added --models X, when given will show the models and the top X, if X is not given will show them all, sorted by total messages
  • UI Enhancement: Modified displayStats to render a sorted table of model usage, showing:
    • Message count
    • Input Token count
    • Output Token count
    • Total Cost

Example Output

image image
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6296 **State:** closed **Merged:** Yes --- ### Summary This PR enhances the `stats` command to provide granular visibility into model usage. It introduces a new "MODEL USAGE" section that displays message counts, a breakdown of input vs. output tokens, and historical accumulated costs for each model used across sessions. ### Changes - **Interface Update**: Extended `SessionStats` to include a `modelUsage` record. - **Aggregation Logic**: Updated `aggregateSessionStats` to collect and sum usage metrics (messages, tokens, cost) per provider/model from assistant messages. - **New Flag**: Added `--models X`, when given will show the models and the top X, if X is not given will show them all, sorted by total messages - **UI Enhancement**: Modified `displayStats` to render a sorted table of model usage, showing: - Message count - Input Token count - Output Token count - Total Cost ### Example Output <img width="484" height="156" alt="image" src="https://github.com/user-attachments/assets/5e596f36-ffee-46a6-be1b-d8175ec84b13" /> <img width="713" height="873" alt="image" src="https://github.com/user-attachments/assets/f93f5aa8-698e-4307-a0bf-706ba02cf403" />
yindo added the pull-request label 2026-02-16 18:16:45 -05:00
yindo closed this issue 2026-02-16 18:16:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11823