anomalyco / anomalyco/opencode

openai: ChatGPT OAuth reports 400k context for long-context models

Open
#47,646 2 comments 2 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Sep 6, 2026.

2.0
Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

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

  1. Connect the openai provider using ChatGPT OAuth.

  2. Select a long-context OpenAI model such as openai/gpt-6-astra, openai/gpt-5.6-sol, or openai/gpt-5.5.

  3. 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'
    
  4. Grow a session to approximately 140,000 tokens.

  5. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.