opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[Feature Request]: add flag to see usage when using `opencode run`

Open FarrukhCyber opened this issue 2 months ago • 12 comments

Question

In the opnecode's interactive mode, the token usage and cost is shown on top right corner. Is there a way to get the same when running it in non-interactive mode such that at the end of execution it gives total cost and token usage?

FarrukhCyber avatar Oct 20 '25 21:10 FarrukhCyber

@FarrukhCyber are you trying to see it in ci? Or what's the environment you are running it in, there may already be a way for you to do this using opencode export but that's prolly not ideal

rekram1-node avatar Oct 20 '25 22:10 rekram1-node

I run opencode run <prompt> inside a python script

FarrukhCyber avatar Oct 20 '25 22:10 FarrukhCyber

@FarrukhCyber would you like some flag on opencode run that would print usage to stdout or a file or something

rekram1-node avatar Oct 20 '25 22:10 rekram1-node

yes ideally. Is this feature available?

FarrukhCyber avatar Oct 20 '25 22:10 FarrukhCyber

Not yet :)

just wanted to confirm what you wanted

rekram1-node avatar Oct 20 '25 22:10 rekram1-node

@rekram1-node I would be happy to implement this feature and open a PR. I'm not sure if this comes under core feature because contribution policy states that core feature requires a design review with the core team before implementation.

FarrukhCyber avatar Oct 21 '25 04:10 FarrukhCyber

i think a pr would be good, I should reword that to not sound so strict.

Edit: ill just assign to u so ppl know u wanted to work on it

rekram1-node avatar Oct 21 '25 05:10 rekram1-node

I also reworded the contributing guidelines to sound a little less "strict": https://github.com/sst/opencode/blob/dev/CONTRIBUTING.md#contributing-to-opencode

rekram1-node avatar Oct 21 '25 21:10 rekram1-node

@rekram1-node Do you think this feature can be implemented using just a plugin?

FarrukhCyber avatar Oct 22 '25 21:10 FarrukhCyber

We don't have a great way to indicate if the run is headless or not so Idk how the plugin would be able to surface it unless you just wanted to write it to a file

rekram1-node avatar Oct 22 '25 21:10 rekram1-node

To confirm even if I provide the approx cost in a custom provider and model setup in my config, when running headless, there is no current method to have it output total tokens/cost at the end correct?

And is this possible if I explore the typescript SDK, or something that just isn't exposed currently without feature work on it?

sheldonhull avatar Dec 10 '25 21:12 sheldonhull

when running headless, there is no current method to have it output total tokens/cost at the end correct?

You can do --format json

And is this possible if I explore the typescript SDK, or something that just isn't exposed currently without feature work on it?

If you are using an sdk you should have everything you need to get cost info

rekram1-node avatar Dec 11 '25 03:12 rekram1-node