[Feature Request] Track Overall Token Usage (Usage Stats) #1121

Closed
opened 2026-02-16 17:29:32 -05:00 by yindo · 13 comments
Owner

Originally created by @x4132 on GitHub (Aug 5, 2025).

Originally assigned to: @thdxr on GitHub.

Currently, opencode tracks token usage in a single thread, including pricing when using API models. However, there is no tool to track overall usage or spend with the tool. Is it possible to add a slash command (e.g. /usage or /stats) that would track the overall spend and/or token usage across sessions in a specific time interval? This would be helpful for claude code users especially since otherwise there is no way to know how much usage you are getting out of your account.

Originally created by @x4132 on GitHub (Aug 5, 2025). Originally assigned to: @thdxr on GitHub. Currently, opencode tracks token usage in a single thread, including pricing when using API models. However, there is no tool to track overall usage or spend with the tool. Is it possible to add a slash command (e.g. /usage or /stats) that would track the overall spend and/or token usage across sessions in a specific time interval? This would be helpful for claude code users especially since otherwise there is no way to know how much usage you are getting out of your account.
yindo closed this issue 2026-02-16 17:29:32 -05:00
Author
Owner

@x4132 commented on GitHub (Aug 9, 2025):

@thdxr BTW i would be open to implement/make a PR for this if you'd like

@x4132 commented on GitHub (Aug 9, 2025): @thdxr BTW i would be open to implement/make a PR for this if you'd like
Author
Owner

@marcinpz commented on GitHub (Sep 19, 2025):

what about having performance stats in logs?

@marcinpz commented on GitHub (Sep 19, 2025): what about having performance stats in logs?
Author
Owner

@djmaze commented on GitHub (Oct 1, 2025):

There seems to be a WIP stats command half-implemented in the repo already: https://github.com/sst/opencode/blob/dev/packages/opencode/src/cli/cmd/stats.ts

@djmaze commented on GitHub (Oct 1, 2025): There seems to be a WIP stats command half-implemented in the repo already: https://github.com/sst/opencode/blob/dev/packages/opencode/src/cli/cmd/stats.ts
Author
Owner

@aleks-mariusz commented on GitHub (Oct 5, 2025):

along the same lines, how about we have a tokens-per-second output as well please?

@aleks-mariusz commented on GitHub (Oct 5, 2025): along the same lines, how about we have a tokens-per-second output as well please?
Author
Owner

@taqtiqa-mark commented on GitHub (Oct 12, 2025):

Given I have a primary agent active.
When the primary agent has `token_reports: true`
Then token usage data is logged at the default reporting tick resolution (15 seconds).

And

Given I am in an active session.
And given the primary agent has `token_reports: true` (boolean)
And given the primary agent has `token_reports_tick: 5` (seconds)
When I use the top level built in `/tokens` or `/usage` or `/consumption`
Then I see the table of token usage:
| Time | Session | Command | Agent | Model | T Sent | T Received | T Total | Sent Cost Guesstimate | Received Cost Guesstimate | Total Cost Guestimate |

@aleks-mariusz is the above what you had in mind? In your case you would set token_reports_tick: 1 in your primary agent file.

@taqtiqa-mark commented on GitHub (Oct 12, 2025): ```gherkin Given I have a primary agent active. When the primary agent has `token_reports: true` Then token usage data is logged at the default reporting tick resolution (15 seconds). ``` And ```gherkin Given I am in an active session. And given the primary agent has `token_reports: true` (boolean) And given the primary agent has `token_reports_tick: 5` (seconds) When I use the top level built in `/tokens` or `/usage` or `/consumption` Then I see the table of token usage: | Time | Session | Command | Agent | Model | T Sent | T Received | T Total | Sent Cost Guesstimate | Received Cost Guesstimate | Total Cost Guestimate | ``` @aleks-mariusz is the above what you had in mind? In your case you would set `token_reports_tick: 1` in your primary agent file.
Author
Owner

@kaanmertkoc commented on GitHub (Nov 2, 2025):

hey! i would also like to make this feature happen!

@x4132 are you currently developing a PR? Or is there any other related PR's that are trying to implement this feature? I am new to this repo!

@kaanmertkoc commented on GitHub (Nov 2, 2025): hey! i would also like to make this feature happen! @x4132 are you currently developing a PR? Or is there any other related PR's that are trying to implement this feature? I am new to this repo!
Author
Owner

@rekram1-node commented on GitHub (Nov 2, 2025):

@kaanmertkoc I think if you want to finish the implementation here that'd be awesome

@rekram1-node commented on GitHub (Nov 2, 2025): @kaanmertkoc I think if you want to finish the implementation [here](https://github.com/sst/opencode/blob/dev/packages/opencode/src/cli/cmd/stats.ts) that'd be awesome
Author
Owner

@kaanmertkoc commented on GitHub (Nov 2, 2025):

@kaanmertkoc I think if you want to finish the implementation here that'd be awesome

yes, thanks! i will try to finish it 🫡🫡🫡 thank you for your quick response.

@kaanmertkoc commented on GitHub (Nov 2, 2025): > [@kaanmertkoc](https://github.com/kaanmertkoc) I think if you want to finish the implementation [here](https://github.com/sst/opencode/blob/dev/packages/opencode/src/cli/cmd/stats.ts) that'd be awesome yes, thanks! i will try to finish it 🫡🫡🫡 thank you for your quick response.
Author
Owner

@rekram1-node commented on GitHub (Nov 2, 2025):

no problem!

@rekram1-node commented on GitHub (Nov 2, 2025): no problem!
Author
Owner

@x4132 commented on GitHub (Nov 2, 2025):

@kaanmertkoc go ahead lol, I haven’t done anything yet

On Sun, Nov 2, 2025 at 09:09 kaanmertkoc @.***> wrote:

kaanmertkoc left a comment (sst/opencode#1634)
https://github.com/sst/opencode/issues/1634#issuecomment-3478114131

hey! i would also like to make this feature happen!

@x4132 https://github.com/x4132 are you currently developing a PR? Or
is there any other related PR's that are trying to implement this feature?
I am new to this repo!


Reply to this email directly, view it on GitHub
https://github.com/sst/opencode/issues/1634#issuecomment-3478114131, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AHRBWFPAMD2PE36JDIMZU3L32Y3EPAVCNFSM6AAAAACDGLA3Y6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINZYGEYTIMJTGE
.
You are receiving this because you were mentioned.Message ID:
@.***>

@x4132 commented on GitHub (Nov 2, 2025): @kaanmertkoc go ahead lol, I haven’t done anything yet On Sun, Nov 2, 2025 at 09:09 kaanmertkoc ***@***.***> wrote: > *kaanmertkoc* left a comment (sst/opencode#1634) > <https://github.com/sst/opencode/issues/1634#issuecomment-3478114131> > > hey! i would also like to make this feature happen! > > @x4132 <https://github.com/x4132> are you currently developing a PR? Or > is there any other related PR's that are trying to implement this feature? > I am new to this repo! > > — > Reply to this email directly, view it on GitHub > <https://github.com/sst/opencode/issues/1634#issuecomment-3478114131>, or > unsubscribe > <https://github.com/notifications/unsubscribe-auth/AHRBWFPAMD2PE36JDIMZU3L32Y3EPAVCNFSM6AAAAACDGLA3Y6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINZYGEYTIMJTGE> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Author
Owner

@kaanmertkoc commented on GitHub (Nov 3, 2025):

Hey @rekram1-node! I've been working on implementing this and have a draft PR ready https://github.com/sst/opencode/pull/3832.

What I did: Went with the simpler approach traverse all sessions/messages to aggregate stats. No storage schema changes needed, just working with what's already there.

Current state: Works kinda alright on my setup (M4 Pro, 24GB RAM: 14 sessions, ~1.5k messages = ~1.3s), but I'm not sure how it scales for users with 100+ or 1000+ sessions.

Wanted to get feedback:

  • Is this acceptable for v1?
  • What's typical session volume per user?
  • If anyone's willing to test with their setup, that would help me understand real world performance.

This is my first contribution, so happy to iterate based on what you think makes sense. Let me know!

@kaanmertkoc commented on GitHub (Nov 3, 2025): Hey @rekram1-node! I've been working on implementing this and have a draft PR ready https://github.com/sst/opencode/pull/3832. **What I did:** Went with the simpler approach traverse all sessions/messages to aggregate stats. No storage schema changes needed, just working with what's already there. **Current state:** Works kinda alright on my setup (M4 Pro, 24GB RAM: 14 sessions, ~1.5k messages = ~1.3s), but I'm not sure how it scales for users with 100+ or 1000+ sessions. Wanted to get feedback: - Is this acceptable for v1? - What's typical session volume per user? - If anyone's willing to test with their setup, that would help me understand real world performance. This is my first contribution, so happy to iterate based on what you think makes sense. Let me know!
Author
Owner

@rekram1-node commented on GitHub (Nov 3, 2025):

@kaanmertkoc just at a glance it looks good, I have a decent # of sessions so ill test it but it seems like it will be good to merge

@rekram1-node commented on GitHub (Nov 3, 2025): @kaanmertkoc just at a glance it looks good, I have a decent # of sessions so ill test it but it seems like it will be good to merge
Author
Owner

@kaanmertkoc commented on GitHub (Nov 3, 2025):

@kaanmertkoc just at a glance it looks good, I have a decent # of sessions so ill test it but it seems like it will be good to merge

That's very good to hear! Just let me know about the results :)

@kaanmertkoc commented on GitHub (Nov 3, 2025): > @kaanmertkoc just at a glance it looks good, I have a decent # of sessions so ill test it but it seems like it will be good to merge That's very good to hear! Just let me know about the results :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1121