Auto-detect Ollama model context limits #7681

Open
opened 2026-02-16 18:07:55 -05:00 by yindo · 0 comments
Owner

Originally created by @felipemadero on GitHub (Jan 26, 2026).

Originally assigned to: @thdxr on GitHub.

Problem

When using Ollama as a provider, the context percentage in the status bar doesn't display because opencode doesn't know the model's context limit. Users have to manually configure limit.context for each model in their config.

Proposed Solution

Query Ollama's native API to automatically detect context limits:

  1. Detect Ollama servers by checking if GET / returns "Ollama is running"
  2. Fetch model info via POST /api/show to get num_ctx from model parameters
  3. Fall back to 4096 (Ollama's default) if not specified in the Modelfile
  4. User config limit.context takes priority if set

This enables the context percentage display without manual configuration.

Originally created by @felipemadero on GitHub (Jan 26, 2026). Originally assigned to: @thdxr on GitHub. ## Problem When using Ollama as a provider, the context percentage in the status bar doesn't display because opencode doesn't know the model's context limit. Users have to manually configure `limit.context` for each model in their config. ## Proposed Solution Query Ollama's native API to automatically detect context limits: 1. Detect Ollama servers by checking if `GET /` returns `"Ollama is running"` 2. Fetch model info via `POST /api/show` to get `num_ctx` from model parameters 3. Fall back to 4096 (Ollama's default) if not specified in the Modelfile 4. User config `limit.context` takes priority if set This enables the context percentage display without manual configuration.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7681