Inconsistent Session Token Count #1307

Closed
opened 2026-02-16 17:30:22 -05:00 by yindo · 5 comments
Owner

Originally created by @spoons-and-mirrors on GitHub (Aug 14, 2025).

Originally assigned to: @thdxr on GitHub.

Summary

I noticed this issue while working on the footer token counter, but this happens on opencode official releases as well.

After discussing the issue on discord, several users saw a similar behavior.
While some could NOT reproduce it over dozens of tries, others witnessed it at close to a 50% rate.

This issue was seen on multiple providers and models so far:

  • github-copilot/gpt-4.1
  • openai/gpt-4.1
  • google/gemini-2.5-pro

It isn't clear whether opencode sends system prompt etc in duplicate or if the token count mechanism suffers from a counting error.
This is issue likely hits every models and providers, for some users? Could lead to preemptive auto /compact in a session and probably other shenanigans?

Image Image

I also been seeing session token count regress at times for no apparent reason 🤦‍♂️

Originally created by @spoons-and-mirrors on GitHub (Aug 14, 2025). Originally assigned to: @thdxr on GitHub. ## Summary I noticed this issue while working on the footer token counter, but this happens on opencode official releases as well. After discussing the issue on discord, several users saw a similar behavior. While some could NOT reproduce it over dozens of tries, others witnessed it at close to a 50% rate. This issue was seen on multiple providers and models so far: - `github-copilot/gpt-4.1` - `openai/gpt-4.1` - `google/gemini-2.5-pro` It isn't clear whether opencode sends system prompt etc in duplicate or if the token count mechanism suffers from a counting error. This is issue likely hits every models and providers, for some users? Could lead to preemptive auto /compact in a session and probably other shenanigans? <img width="329" height="54" alt="Image" src="https://github.com/user-attachments/assets/10f6fa77-650a-477a-90b8-e168161ab50c" /> <img width="326" height="60" alt="Image" src="https://github.com/user-attachments/assets/2a18189f-77d9-42b5-b129-492ad111e553" /> I also been seeing session token count regress at times for no apparent reason 🤦‍♂️
yindo closed this issue 2026-02-16 17:30:22 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 14, 2025):

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

  • #1714: GPT5 incorrect context counting - Shows similar inconsistent token count behavior with context window errors despite lower session counts
  • #924: Dramatic increase in token consumption - Reports sudden token consumption spikes after upgrades, similar inconsistency pattern
  • #1071: token count not working for some providers - Shows token counts displaying as "0/0%" for certain providers/models
  • #423: Context usage count is always 0 for some local openai-compatible providers - Token counting issues with OpenAI-compatible providers
  • #229: Missing validation for token calculations causes display issue - Addresses core token calculation bugs that could cause display inconsistencies

Feel free to ignore if none of these address your specific case of token counts jumping unexpectedly or regressing during sessions.

@github-actions[bot] commented on GitHub (Aug 14, 2025): This issue might be a duplicate of existing issues. Please check: - #1714: GPT5 incorrect context counting - Shows similar inconsistent token count behavior with context window errors despite lower session counts - #924: Dramatic increase in token consumption - Reports sudden token consumption spikes after upgrades, similar inconsistency pattern - #1071: token count not working for some providers - Shows token counts displaying as "0/0%" for certain providers/models - #423: Context usage count is always 0 for some local openai-compatible providers - Token counting issues with OpenAI-compatible providers - #229: Missing validation for token calculations causes display issue - Addresses core token calculation bugs that could cause display inconsistencies Feel free to ignore if none of these address your specific case of token counts jumping unexpectedly or regressing during sessions.
Author
Owner

@rekram1-node commented on GitHub (Sep 13, 2025):

will be fixed in next release

@rekram1-node commented on GitHub (Sep 13, 2025): will be fixed in next release
Author
Owner

@rekram1-node commented on GitHub (Sep 14, 2025):

nvm this solution sucked

@rekram1-node commented on GitHub (Sep 14, 2025): nvm this solution sucked
Author
Owner

@rekram1-node commented on GitHub (Sep 14, 2025):

this is just the input + cached tokens double counting

@rekram1-node commented on GitHub (Sep 14, 2025): this is just the input + cached tokens double counting
Author
Owner

@spoons-and-mirrors commented on GitHub (Sep 26, 2025):

this PR seems to fix it:
https://github.com/sst/opencode/pull/2653

@spoons-and-mirrors commented on GitHub (Sep 26, 2025): this PR seems to fix it: https://github.com/sst/opencode/pull/2653
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1307