Skip to content

[FEATURE]: JSON output for opencode stats CLI command #14702

@ccmetz

Description

@ccmetz

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Feature Request

It would be great to be able to run opencode stats --format json and receive json output for the stats (essentially the SessionStats object).

Why?

This would be extremely helpful for anyone who wants to use their opencode stats to build their own custom dashboards for tracking token usage, cost, etc. This is actually what I was in the process of doing until I took a step back and thought "man, it would be really great if I could just get the stats in a json object instead of having to query the sqlite db".

Suggested Implementation

If this feature sounds worth it to the OpenCode team, I'd love to make my first contribution and open a PR for it. I was thinking of adding a couple of new flags to opencode stats:

  • --format (choices: ascii or json, defaults to ascii which displays the current table output)
    • Allows the user to select an output format for the stats
  • --pretty (boolean)
    • If output format is json, this option will pretty-print the json with indentations of 2 spaces

Example output:

Image

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions