Repository navigation
Description
Summary
When OpenAI models are used through a ChatGPT OAuth connection, OpenCode overwrites their effective context limits with 400,000 tokens. This affects multiple long-context OpenAI models whose catalog limits are approximately 1.05 million tokens, causing the TUI to substantially overstate context usage.
For example, approximately 140,000 tokens are shown as 35–36% usage instead of approximately 13–14%.
Environment
- opencode version:
v0.0.0-beta-19192 - OS:
Darwin 24.6.0 (arm64) - Terminal: Ghostty (
TERM=xterm-256color,COLORTERM=truecolor) - Shell:
/bin/zsh - Install/channel: beta
- Active plugins: none found in project or global configuration
Reproduction
-
Connect the
openaiprovider using ChatGPT OAuth. -
Select a long-context OpenAI model such as
openai/gpt-6-astra,openai/gpt-5.6-sol, oropenai/gpt-5.5. -
Inspect the effective model metadata with:
opencode2 api get /api/model | jq -r '.data[] | select(.providerID=="openai" and .limit.context==400000) | [.id,.limit.context,.limit.input,.limit.output] | @tsv'
-
Grow a session to approximately 140,000 tokens.
-
Observe the context usage percentage in the TUI.
Expected Behavior
OpenCode should use the actual context limit supported by each model and connection rather than applying a blanket 400,000-token limit.
Models whose catalog metadata declares a 1,050,000-token context should report approximately 13–14% usage at roughly 140,000 tokens.
Actual Behavior
The affected models report an effective limit of 400,000 context tokens and 272,000 input tokens. On the tested installation, this includes:
gpt-6-astra
gpt-6-astra-fast
gpt-5.6-sol
gpt-5.6-sol-fast
gpt-5.6-luna
gpt-5.6-luna-fast
gpt-5.6-terra
gpt-5.6-terra-fast
gpt-5.5
gpt-5.5-fast
gpt-5.4
gpt-5.4-fast
For example, the API reports:
{"id":"gpt-6-astra","providerID":"openai","limit":{"context":400000,"input":272000,"output":128000},"baseURL":"https://chatgpt.com/backend-api/codex"}The TUI percentage arithmetic appears correct: it divides the latest token count by model.limit.context. The inflated percentage comes from the effective model limit.
Additional Context
The OpenAI provider's ChatGPT OAuth catalog transform applies a blanket override to eligible models:
draft.limit = { ...draft.limit, context: 400_000, input: 272_000 }This discards model-specific catalog limits. For example, several affected models declare:
{"context":1050000,"input":922000,"output":128000}This is consistently reproducible across multiple OpenAI models connected through ChatGPT OAuth. No user-defined model or provider limit overrides are configured.
Activity
github-actions commentedon Sep 6, 2026
This issue might be a duplicate of existing issues. Please check:
russrapper15-png commentedon Sep 6, 2026
AleksQuantum commentedon Sep 30, 2026
The issue still seems to be present
marwasha commentedon Oct 1, 2026
This issue just appeared to me, v1 had the full 1mil context window
maxiedaniels commentedon Oct 1, 2026
Ya just migrated to v2, this is happening for me too. I had 6.1 trace the cause:
"""
OpenCode v2.0.21, opencode.provider.openai registers a model transform that, when its OpenAI OAuth connection is active, applies this to eligible OpenAI models:
js
model.limit = {
...model.limit,
context: 400000,
input: 272000
}
That includes gpt-6.1-sol. It preserves the catalog’s 128K output limit but overwrites its context and input limits.
"""
barreiroleo commentedon Oct 1, 2026
Just in case, the workaround for 6.1 #44821 (comment)
marwasha commentedon Oct 4, 2026
Proposed V2 fix: #53080. It removes the blanket ChatGPT OAuth 400K/272K override so each model retains its catalog context/input limits, with regression coverage for long-context models, a fast alias, and a smaller-context model. The regression fails before the fix and passes afterward; focused tests and the full local lint/typecheck pass. The PR is ready for maintainer review.
Update: a Linux x64 build of PR head dc65500 reports 1,050,000 context / 922,000 input tokens on the ChatGPT route for GPT-6.1 Sol, Astra, Astra Fast, GPT-5.6 Sol, and GPT-5.5. This verifies effective metadata, not endpoint capacity.
Independent confirmation from another affected user would help: if you test the PR, please share the model, ChatGPT plan, effective limits, and whether ordinary longer sessions work without premature compaction or context errors. Please omit credentials and private prompts; there is no need to run a costly maximum-context probe.
marwasha commentedon Oct 4, 2026
Put together the following MR to address this
#53080
nicholaicascio commentedon Oct 11, 2026
This issue just keeps getting reported and the staff always finds a reason to close it.
FYI the workaround that @barreiroleo posted works, and your agent can set it up easily.
rekram1-node commentedon Oct 12, 2026
The only reason this exists is so that people using their openai subscriptions in opencode have a similar experiences as you would in other harnesses like codex (as far as plan usage goes). Without the limit people complain that opencode eats their usage much faster because it doesn't compact as early.
Annoyingly for everyone we didn't make it very intuitive as to why this happens, or how to disable that and that's obviously a big failure on our part and I apologize.
On other notes, Openai is changing the way some of the quotas work so this may not be an issue at all soon:
https://x.com/thsottiaux/status/2109430343346581527?s=20
barreiroleo commentedon Oct 12, 2026
I don't think you guys are to blame for any of this; you're just following OpenAI's criteria. Even Codex users don't know how requests beyond X tokens were charged.
Thanks for the follow up
KaranSiddhu commentedon Oct 18, 2026
uninstall the v2 and install the v1 again - really disappointed with this
angelcervera commentedon Oct 20, 2026
I checked the current Codex source, and it distinguishes between the default context and the configurable maximum.
For GPT-6 Astra, the bundled catalog declares:
context_window: 272,000max_context_window: 872,000Codex also supports a
model_context_windowoverride, capped at the model’s maximum.I just migrated from 1.19.3, where Astra was working well for me with a 1M context window, and encountered this restriction in V2.
This is based on source inspection, not an endpoint capacity or subscription billing test. Codex can also fetch updated model metadata from the service.
dr1ss commentedon Oct 21, 2026
I confirm, Astra context is deemed smaller than what it actually is by opencode 2. starts compacting before the 272,000 mark
rekram1-node commentedon Oct 23, 2026
#58194
In the next update u can opt out of it by just disabling the context cap plugin:
We are going to keep the context limits as is (with the lower cap) to decrease ur overall spend/usage. If u want to opt out just add this to ur config, also documenting it