anomalyco / anomalyco/opencode

tui: tok/s excludes reported reasoning tokens in V2

Open
#48,705 0 comments 0 reactions 1 assignee View on GitHub

@simonklee is already working on this.

Since Sep 12, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

OpenCode V2's tok/s indicator excludes reported reasoning tokens from the numerator. This understates total generated-token throughput for reasoning-heavy responses.

The footer sums assistant.tokens.output, which is populated from Usage.visibleOutputTokens. That value is the provider's inclusive output count minus its reported reasoning count; reasoning is stored separately in assistant.tokens.reasoning.

The indicator should count both non-reasoning output and reasoning tokens, using a duration that covers the generation of both. For providers such as OpenAI, the raw API output count already includes reasoning, so the calculation must use OpenCode's normalized counters without double-counting the provider total.

Plugins

No plugins are required for the code-level reproduction below.

OpenCode version

V2, upstream source at 2df00955cb933e977427535d2505e50cbc689c69.

Steps to reproduce
  1. Construct a completed assistant message with tokens.output = 20, tokens.reasoning = 80, and a 10-second interval between time.created and time.streamed.
  2. Pass it to turnTokensPerSecond in packages/tui/src/routes/session/rows.ts, with no other assistant messages in the current prompt's history.
  3. The calculation returns 2 tok/s: 20 / 10. Counting all 100 generated tokens over the same interval would give 10 tok/s.

This isolates the missing reasoning count from provider-specific timing behavior. In normal use, it affects the footer whenever a provider reports reasoning tokens separately and the tok/s indicator is enabled.

Screenshot and/or share link

Calculation:
https://github.com/anomalyco/opencode/blob/2df00955cb933e977427535d2505e50cbc689c69/packages/tui/src/routes/session/rows.ts#L349-L369

Session usage normalization:
https://github.com/anomalyco/opencode/blob/2df00955cb933e977427535d2505e50cbc689c69/packages/core/src/session/usage.ts#L11-L19

Operating System

macOS (Darwin 25.6.0, arm64); the calculation is platform-independent.

Terminal

iTerm2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.