Skip to content

Inconsistent Session Token Count #1937

Closed

Description

@spoons-and-mirrors

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 🤦‍♂️

Activity

  1. github-actions commented on Aug 14, 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 of token counts jumping unexpectedly or regressing during sessions.

  2. rekram1-node commented on Sep 14, 2025

    @rekram1-node
    Collaborator

    will be fixed in next release

  3. rekram1-node commented on Sep 15, 2025

    @rekram1-node
    Collaborator

    nvm this solution sucked

  4. rekram1-node commented on Sep 15, 2025

    @rekram1-node
    Collaborator

    this is just the input + cached tokens double counting

  5. spoons-and-mirrors commented on Sep 26, 2025

    @spoons-and-mirrors
    ContributorAuthor

    this PR seems to fix it:
    #2653

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions