opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add model usage statistics with input/output token breakdown to stats command

Open processtrader opened this issue 2 weeks ago • 5 comments

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

processtrader avatar Dec 28 '25 12:12 processtrader

/review

rekram1-node avatar Dec 28 '25 18:12 rekram1-node

should prolly require a flag to output this btw, and maybe a flag to limit # of models cause mine is huge

rekram1-node avatar Dec 28 '25 19:12 rekram1-node

should prolly require a flag to output this btw, and maybe a flag to limit # of models cause mine is huge

that sounds fair! yeah sure, perhaps

stats --days X --models Y

just to follow the convention about days followed by the number of models we want to display? and if so, what sorting would we need? top Y in terms of usage?

processtrader avatar Dec 28 '25 19:12 processtrader

@rekram1-node I pushed a change, so it is a flag now, with the option to also limit the amount of models sorted by top messages

processtrader avatar Dec 28 '25 19:12 processtrader

/review

rekram1-node avatar Dec 28 '25 22:12 rekram1-node

@rekram1-node do you think we could go with this? thanks!

processtrader avatar Dec 30 '25 15:12 processtrader