web and tui reports token usage differently. #2205

Open
opened 2026-02-16 17:34:39 -05:00 by yindo · 5 comments
Owner

Originally created by @simonxabris on GitHub (Oct 21, 2025).

Originally assigned to: @riatzukiza on GitHub.

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

Originally created by @simonxabris on GitHub (Oct 21, 2025). Originally assigned to: @riatzukiza on GitHub. ### 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
yindo added the help-wantedbuggood first issue labels 2026-02-16 17:34:39 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 21, 2025):

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

  • #3314: Reports same TUI vs web token discrepancy issue where TUI shows 2x actual tokens and web reports different values
  • #1937: Describes inconsistent session token counting across TUI and other interfaces, affecting multiple providers

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

@github-actions[bot] commented on GitHub (Oct 21, 2025): This issue might be a duplicate of existing issues. Please check: - #3314: Reports same TUI vs web token discrepancy issue where TUI shows 2x actual tokens and web reports different values - #1937: Describes inconsistent session token counting across TUI and other interfaces, affecting multiple providers Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 21, 2025):

we shall fix

@rekram1-node commented on GitHub (Oct 21, 2025): we shall fix
Author
Owner

@riatzukiza commented on GitHub (Oct 22, 2025):

I'll take a swing at this.

@riatzukiza commented on GitHub (Oct 22, 2025): I'll take a swing at this.
Author
Owner

@riatzukiza commented on GitHub (Oct 24, 2025):

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.

@riatzukiza commented on GitHub (Oct 24, 2025): <img width="1312" height="174" alt="Image" src="https://github.com/user-attachments/assets/c9810139-6a1b-43b3-bb29-a3ca20fbead3" /> <img width="364" height="300" alt="Image" src="https://github.com/user-attachments/assets/e719ae08-0e68-45a8-a934-730bab1b8be3" /> 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.
Author
Owner

@mohamedbouddi7777-dev commented on GitHub (Feb 14, 2026):

سلام العمله جديده على انا اعطينا التعليمات وسنرى في التقديم

@mohamedbouddi7777-dev commented on GitHub (Feb 14, 2026): سلام العمله جديده على انا اعطينا التعليمات وسنرى في التقديم
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2205