Skip to content

github copilot: 2x token (counts total=total+cached) compacts at 64k, instead of 128k #3314

Closed as not planned

Description

@hchaudhary1

Description

  • The TUI shows 2X the actual tokens being used.
  • This ends up forcing opencode to compact much, much earlier than needed.
  • Taking a look at the console from the share link I can see that the JSON itself looks valid (1/2 TUI) and the correct number of tokens seems to be presented in the console.

OpenCode version

0.15.8

Steps to reproduce

  • To reproduce this you can use Grok 4 fast from OpenRouter or you can also use any model that's connected via GitHub Copilot (GPT-5-mini).
  • enter "hi" into prompt
  • e.g. https://opencode.ai/s/IVO2CNuh

Screenshot and/or share link

Image

Operating System

mac

Terminal

zsh

Activity

  1. github-actions commented on Oct 21, 2025

    @github-actions
    Contributor

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

    • Inconsistent Session Token Count #1937: Reports identical behavior where TUI shows 2X the actual tokens, causing premature auto /compact, while share link shows correct counts. Multiple users have reported this at ~50% rate across various providers and models.

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

  2. hchaudhary1 commented on Oct 21, 2025

    @hchaudhary1
    Author

    very annoying...any hack for this...? especially with copilot, effective context is 64k

    • wondering if I can somehow override and "fool" opencode to think max model input-context is 2x -- i.e. 256k

    EDIT:
    I guess, I can do something like this, to artificially double max context?

    {
      "provider": {
        "openai": {
          "models": {
            "gpt-4o": {
              "limit": {
                "context": 131072,
                "output": 8192
              }
            }
          }
        }
      }
    }
  3. hchaudhary1 commented on Oct 21, 2025

    @hchaudhary1
    Author

    same issue on bunx opencode-ai@opentui
    0.0.0-opentui-202510210139

  4. self-assigned this
    on Oct 21, 2025
  5. rekram1-node commented on Oct 21, 2025

    @rekram1-node
    Contributor

    Hm will look into that

  6. simonxabris commented on Oct 21, 2025

    @simonxabris

    I'm currently working on an opencode client and I had to look into how opencode reports token usage and for a while I thought I found the same issue, but then I realized that I forgot to add the cached tokens to calculate the actual number of tokens used. If you add cache tokens for this chat, it adds up to the same value in both the TUI and the JSON in the share link:

    Input: 35844
    Output: 404
    Cache read: 35712

    This is how the TUI calculates token usage

    https://github.com/sst/opencode/blob/a99bd3aa2c0f7100d0bcbfa4a11d818b7c753661/packages/tui/internal/components/chat/messages.go#L897-L901

  7. rekram1-node commented on Oct 21, 2025

    @rekram1-node
    Contributor

    edit: maybe this is just a bug in the web view

  8. hchaudhary1 commented on Oct 21, 2025

    @hchaudhary1
    Author

    Webview token count (at the bottom of webview) is a completely different issue folks.

    This issue is causing frequent compacts. The issue is with the TUI or backend

    This is like a P0 issue... a basic feature is not working correctly.

  9. rekram1-node commented on Oct 21, 2025

    @rekram1-node
    Contributor

    @hchaudhary1 the max context size is 128k for gpt-5-mini on github copilot, are you sure that isn't the cause?

    I will look more into your session to verify

  10. hchaudhary1 commented on Oct 21, 2025

    @hchaudhary1
    Author

    Yes, but why do you compact at 64k?
    When we hit 64k, OC thinks it's hitting 128k, and then compacts. I hope I'm explaining correctly 😀

  11. rekram1-node commented on Oct 21, 2025

    @rekram1-node
    Contributor

    It shouldn't compact at 64k, i guess I just wanted to verify that you understood the decreased context limit since most people that have said this with copilot normally are unaware of the substantially smaller context window than the real model has

    But if it is actually compacting at 64k that's a big issue and we need to fix, ill look into it mroe

  12. hchaudhary1 commented on Oct 21, 2025

    @hchaudhary1
    Author

    Bingo.

  13. changed the title [-]2x token reported in TUI (share link obj ok) - compacts too early[/-] [+]github copilot: 2x token (counts total=total+cached) compacts at 64k, instead of 128k[/+] on Nov 2, 2025
  14. github-actions commented on Mar 25, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

  15. removed
    bugSomething isn't working
    on May 3, 2026
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