You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
github copilot: 2x token (counts total=total+cached) compacts at 64k, instead of 128k #3314
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).
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.
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:
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
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
Activity
github-actions commentedon Oct 21, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
hchaudhary1 commentedon Oct 21, 2025
very annoying...any hack for this...? especially with copilot, effective context is 64k
EDIT:
I guess, I can do something like this, to artificially double max context?
{ "provider": { "openai": { "models": { "gpt-4o": { "limit": { "context": 131072, "output": 8192 } } } } } }hchaudhary1 commentedon Oct 21, 2025
same issue on
bunx opencode-ai@opentui0.0.0-opentui-202510210139
rekram1-node commentedon Oct 21, 2025
Hm will look into that
simonxabris commentedon Oct 21, 2025
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
rekram1-node commentedon Oct 21, 2025
edit: maybe this is just a bug in the web view
hchaudhary1 commentedon Oct 21, 2025
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.
rekram1-node commentedon Oct 21, 2025
@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
hchaudhary1 commentedon Oct 21, 2025
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 😀
rekram1-node commentedon Oct 21, 2025
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
hchaudhary1 commentedon Oct 21, 2025
Bingo.
[-]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[/+]fix: resolve 4 bugs — payload bloat, MCP subagents, tool names, token…
github-actions commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.