- 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.
Environment
- OpenCode version: 2.0.20
- OS: Windows 11 (10.0.26200)
- Provider: Ollama (local)