Skip to content

[Bugs]: Context window is hardcoded to 200k for many models instead of resolving dynamically from actual provider/model metadata #35863

Closed as not planned

Description

@Believe-Yourself-ok

Description

OpenCode's context window handling relies on static/hardcoded values (models.generated.js / models.dev
catalog snapshots) instead of resolving each model's actual context window dynamically. This causes
auto-compaction, context tracking, and overflow checks to trigger far too early — even when the
selected model supports a much larger context (e.g. 1M).

This is not isolated to one provider — the same root cause shows up across multiple models:

Expected Behavior:
Context window per model should be resolved dynamically — either from the provider's live /models
endpoint when available, or from an up-to-date, easily-updatable model registry — instead of a
hardcoded fallback (200k) baked into the binary. This applies to ALL models/providers, not just
Anthropic's context1m case.

Actual Behavior:
Context window limit is compiled/cached at build time per model. When a provider updates a model's
actual context window (larger or smaller), OpenCode keeps using the stale hardcoded value until a
new release ships.

Proposed Solution:

  1. Attempt to fetch context window from the provider's live model-list API at session start (with caching)
  2. Fall back to a versioned, community-updatable model registry (not compiled into the binary) when
    live discovery isn't available
  3. Only fall back to a generic default (e.g. 200k) as a last resort, with a visible warning in TUI/GUI
    so users know the value is an estimate, not the real limit
  4. Respect user-defined limit.context overrides in opencode.json above all of the above (already
    partially supported)

Related: #15871, #24119, #27458, #24171, #16861

Plugins

N/A (core behavior)

OpenCode version

No response

Steps to reproduce

  1. Select a model whose real provider-side context window differs from OpenCode's compiled/cached value
    (e.g. any model with context1m enabled, or DeepSeek-V4-Pro, or GPT-5.5 Codex)
  2. Run a long session and monitor the context/compaction tracker in TUI
  3. Observe compaction/overflow triggers at ~200k (or another stale hardcoded value) instead of the
    model's actual advertised context window

Screenshot and/or share link

No response

Operating System

Win11

Terminal

PowerShell 7

Activity

  1. bjornnorman commented on Jul 27, 2026

    @bjornnorman

    In my case stopped at around 151K / 17% when using deepseek-v4-pro and forced a compaction. Some times it seems even earlier. Tried overriding the config in opencode json with the following - but it has no effect:

    "deepseek": { "models": { "deepseek-v4-pro": { "limit": { "context": 1048576, "input": 1048576, "output": 262144 } } } }

    I'm on the latest version of Opencode: 1.18.7

  2. ulascanndmrc commented on Jul 30, 2026

    @ulascanndmrc

    I would also like to support this request.

    One of the main reasons I subscribed to OpenCode Go was to use the full context window advertised by models such as DeepSeek V4 Pro, GLM-5.2, and Qwen3.7 Max.

    Using only ~190K for models that officially support 1M tokens is a significant limitation for long development sessions.

    It would be great if OpenCode could either:

    • expose the full supported context window when the backend supports it, or
    • clearly indicate the actual context limit for the selected backend.

    Thank you!

  3. github-actions commented on Sep 30, 2026

    @github-actions
    Contributor

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

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