opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: show live token usage during streaming

Open arsham opened this issue 1 month ago • 5 comments

Token counts only showed up after messages finished, so you had no idea how many tokens were being used until it was done.

Now token usage shows live while streaming:

  • IN↓/OUT↑ format shows what you're sending vs receiving

  • ~X tok estimates appear immediately and update in real-time

  • ~X think shows reasoning token usage separately

  • Tool results are now properly counted when sent back to the API

  • Added sentEstimate and contextEstimate fields to track what's actually being sent

Makes it way easier to keep an eye on token budget instead of being surprised at the end.

Showcase

user-tokens-showcase

arsham avatar Nov 24 '25 21:11 arsham

I like this :+1:

Sewer56 avatar Nov 26 '25 19:11 Sewer56

looking forward to it!

iamhenry avatar Nov 26 '25 19:11 iamhenry

@rekram1-node any plans to include this feature in upcoming releases?

modelnova-ai avatar Nov 28 '25 18:11 modelnova-ai

@arsham - found a bug in this one while using it in my fork:

the upstream code has:

assistantMessage.finish = "tool-calls" assistantMessage.time.completed = Date.now() await Session.updateMessage(assistantMessage) if (result && part.state.status === "running") { await Session.updatePart({ ...part, state: { status: "completed", // ... rest of completed state }, } satisfies MessageV2.ToolPart) }

But your commit 7faa5e2cbc ("feat: real-time token tracking in TUI") accidentally removed completion handling code when refactoring the subtask execution.

shuv1337 avatar Dec 06 '25 20:12 shuv1337

The implication of the bug is that custom /commands that have subtask: true set will complete it's task and then spawn another task trying to do the same thing, over and over until manual intervention

shuv1337 avatar Dec 06 '25 20:12 shuv1337