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 }}
Repository navigation
[FEATURE]: provider: auto-detect context window from provider #52346
I have verified this feature I'm about to request hasn't been suggested before.
Related issues:#40908 and #10759 raise the same core concern. This issue adds the concrete Ollama serve-time detection case (num_ctx + ollama ps) and the config-precedence rule as a clarifying proposal.
Summary
The model's limit.context must be set manually in the OpenCode config. For local providers like Ollama this is problematic because the effective context window is determined at serve-time (e.g. via num_ctx or OLLAMA_CONTEXT_LENGTH), can change independently of the OpenCode config, and Ollama reports that value in both its own API and its /v1/models endpoint — but nothing in the OpenCode config is auto-filled from that signal.
Problem
I have a local Ollama instance running qwen3.8:27b with num_ctx 131072 (128K). Ollama reports this correctly:
$ ollama ps
NAME SIZE PROCESSOR CONTEXT UNTIL
qwen3.8:27b 17GB 100% GPU 131072 ...
The OpenAI-compatible endpoint also exposes it in /v1/models. Yet OpenCode's config only accepts a static number:
"limit": { "context": 65536 }
If Ollama's effective context changes (different model, different num_ctx, different hardware), the OpenCode value silently goes stale and the session runs at a lower-than-supported window with no warning.
Suggested behavior
When limit.context is not explicitly set in the config, auto-detect it from the provider at session start:
Ollama — read context_length from ollama ps or the Ollama /api/show response
OpenAI-compatible endpoints — read max_tokens from the /v1/models response
Use the detected value as the default. An explicit limit.context in config should always take precedence, so users who want to cap the window retain that control.
This is still a feature request, but it does not yet meet the Feature Request template requirements. Please update the title to start with [FEATURE]: and add the template's required verification checkbox. The description already explains the need and includes provider/system context.
changed the title [-]provider: auto-detect context window from provider[/-][+][FEATURE]: provider: auto-detect context window from provider[/+]on Sep 30, 2026
Closing — confirmed via the docs that OpenCode already auto-detects context, vision, and tool-use capabilities from Ollama when limit.context is not set in the config. The original issue was a user-side misconfiguration (hardcoded limit.context lower than the provider's actual window). The only genuinely missing piece would be a warning when an explicit limit is lower than the provider-reported window — leaving that as a separate ask if needed.
Activity
github-actions commentedon Sep 30, 2026
This issue doesn’t fully meet our contributing guidelines.
What needs to be fixed:
[FEATURE]:.Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
/modelsendpoint, including local servers such as Ollama.If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon Sep 30, 2026
This is still a feature request, but it does not yet meet the Feature Request template requirements. Please update the title to start with
[FEATURE]:and add the template's required verification checkbox. The description already explains the need and includes provider/system context.[-]provider: auto-detect context window from provider[/-][+][FEATURE]: provider: auto-detect context window from provider[/+]github-actions commentedon Sep 30, 2026
Thanks for updating the issue—it now meets the Feature Request requirements.
dlobster7401 commentedon Sep 30, 2026
Closing — confirmed via the docs that OpenCode already auto-detects context, vision, and tool-use capabilities from Ollama when limit.context is not set in the config. The original issue was a user-side misconfiguration (hardcoded limit.context lower than the provider's actual window). The only genuinely missing piece would be a warning when an explicit limit is lower than the provider-reported window — leaving that as a separate ask if needed.