Skip to content

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

Closed

Description

@x4132

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.

Activity

  1. self-assigned this
    on Aug 6, 2025
  2. x4132 commented on Aug 10, 2025

    @x4132
    Author

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

  3. marcinpz commented on Sep 19, 2025

    @marcinpz

    what about having performance stats in logs?

  4. djmaze commented on Oct 1, 2025

    @djmaze

    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

  5. aleks-mariusz commented on Oct 5, 2025

    @aleks-mariusz

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

  6. taqtiqa-mark commented on Oct 13, 2025

    @taqtiqa-mark
    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.

  7. kaanmertkoc commented on Nov 2, 2025

    @kaanmertkoc
    Contributor

    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!

  8. rekram1-node commented on Nov 2, 2025

    @rekram1-node
    Contributor

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

  9. kaanmertkoc commented on Nov 2, 2025

    @kaanmertkoc
    Contributor

    @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.

  10. rekram1-node commented on Nov 2, 2025

    @rekram1-node
    Contributor

    no problem!

  11. x4132 commented on Nov 2, 2025

    @x4132
    Author
  12. kaanmertkoc commented on Nov 3, 2025

    @kaanmertkoc
    Contributor

    Hey @rekram1-node! I've been working on implementing this and have a draft PR ready #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!

  13. rekram1-node commented on Nov 3, 2025

    @rekram1-node
    Contributor

    @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

  14. kaanmertkoc commented on Nov 3, 2025

    @kaanmertkoc
    Contributor

    @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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions