Skip to content

web and tui reports token usage differently. #3322

Closed

Description

@simonxabris

Description

TUI uses the following logic to calculate token usage:

https://github.com/sst/opencode/blob/a99bd3aa2c0f7100d0bcbfa4a11d818b7c753661/packages/tui/internal/components/chat/messages.go#L884-L904

While web does this:

https://github.com/sst/opencode/blob/a99bd3aa2c0f7100d0bcbfa4a11d818b7c753661/packages/web/src/components/Share.tsx#L273-L294

Difference is that the TUI takes the last message and adds up the tokens, web version aggregates all tokens across all messages.

That's why for example for this link: https://opencode.ai/s/IVO2CNuh

Web reports input tokens usage at 400k, while TUI only ~70K

As far as I can tell the TUI version is the actually correct one. If this is actually a bug I'm happy to do a PR to align the web tokens report to the TUI.

OpenCode version

0.15.10

Steps to reproduce

  • Create a session with a share link
  • Check token usage in TUI
  • Check token usage at the end of share page

Screenshot and/or share link

https://opencode.ai/s/IVO2CNuh

Operating System

mac

Terminal

Ghostty

Activity

  1. github-actions commented on Oct 21, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node commented on Oct 21, 2025

    @rekram1-node
    Collaborator

    we shall fix

  3. riatzukiza commented on Oct 22, 2025

    @riatzukiza
    Contributor

    I'll take a swing at this.

  4. riatzukiza commented on Oct 24, 2025

    @riatzukiza
    Contributor
    Image Image

    The issue is less of a bug, and more bad UX. both of the numbers reflected a meaningful reality, the context number is "how many tokens are currently part of the agents context window" and the numbers on the website were "how many tokens did we have to send to, and receive from, the API, to get to the current state"

    And you send the full context each time you make a request, and you get back some amount of tokens that then become a part of the context.

  5. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions