Repository navigation
Description
Description
The Context tab (the token/context breakdown panel opened from the circular context-usage indicator) shows — for the "Context Limit" and "Usage" stats when using a custom @ai-sdk/openai-compatible provider — even when an explicit limit.context is configured for that model in opencode.json.
Because the limit renders as —, the usage percentage is also —, so the whole context-tracking readout is unusable for these models, and there is no visible indication anywhere of the model's context window.
Root cause (from source)
packages/app/src/components/session/session-context-metrics.ts:
type Model = {
name?: string
limit: { // declared non-optional…
context: number
}
}
const build = (messages, providers) => {
const message = lastAssistantWithTokens(messages)
if (!message) return undefined
const provider = providers.find((item) => item.id === message.providerID)
const model = provider?.models[message.modelID]
const limit = model?.limit.context // …but accessed as if it can be missing
const total = tokenTotal(message)
return {
...
limit,
usage: limit ? Math.round((total / limit) * 100) : null,
}
}limit resolves to undefined whenever:
provider.models[message.modelID]returns no entry (the model the SDK reports for the assistant message is keyed differently than the config entry, e.g. gateway/router providers), or- the resolved
modelobject has nolimit(custom/local models whose window can't be auto-fetched and no override was merged into the resolved model).
Note the type declares limit: { context: number } as required, but the code reads model?.limit.context. If a resolved model exists but has no limit, model.limit is undefined and .context is an unsafe access. Either way the tab falls back to the em-dash.
packages/app/src/components/session/session-context-tab.tsx:
{ label: "context.stats.limit", value: () => formatter().number(ctx()?.limit) },
{ label: "context.stats.usage", value: () => formatter().percent(ctx()?.usage) },session-context-format.ts renders undefined/null as "—", so a missing limit surfaces as — with no fallback.
Expected behavior
The Context tab should display the model's context limit whenever it is knowable:
- If the user configured
limit.contextinopencode.json, always display and use it (config override should win over auto-detected metadata). - If not configured, fall back to models.dev / the provider's
/v1/modelsmetadata. - If still unknown, show a clear hint (e.g. "not set — configure
limit.context") instead of a bare—, so it's discoverable. model.limitshould be treated as optional in the type (limit?: { context?: number }) since custom/local providers legitimately lack it, and the access should be null-safe.
Actual behavior
"Context Limit" and "Usage" render as — in the Context tab; no context window is shown anywhere for the model.
Steps to reproduce
- Configure a custom OpenAI-compatible provider with an explicit limit:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"omniroute": {
"npm": "@ai-sdk/openai-compatible",
"name": "OmniRoute",
"options": { "baseURL": "http://localhost:20128/v1", "apiKey": "sk-..." },
"models": {
"hyperspaceaihai/anthropic--claude-opus-latest": {
"name": "opus",
"limit": { "context": 1000000, "output": 128000 }
}
}
}
}
}- Start a session on
omniroute/hyperspaceaihai/anthropic--claude-opus-latestand send a few messages so token usage accrues. - Open the Context tab from the circular context-usage indicator.
- Observe "Context Limit: —" and "Usage: —", despite
limit.context: 1000000being configured.
OpenCode version
1.18.3
Operating System
Windows 11 (10.0.26200)
Related issues
- OpenCode Desktop shows Context Limit = 0 for LM Studio providers. #35955 — Context Limit = 0 for LM Studio (auto-fetch of
/api/v0/modelsmetadata; this report is broader: explicit config override also not shown) - fix: context limit display uses stale model after model switch #35072 — context limit display uses stale model after model switch
- [FEATURE]: Feature Request / Bug: Cannot set context window limits for local models via GUI/TUI (Defaults to 0) #31433 — request to set limits via GUI/TUI (this issue is about displaying a configured limit)
- [BUG]: Custom openai-compatible provider model limit overrides ignored for context percentage display #29555 (closed) — TUI status-bar percentage ignored configured
limit.context(same class, different surface: status bar vs. Context tab) - [BUG]: Context percentage indicator doesn't reflect usable context proportion #28057 — context percentage indicator doesn't reflect usable context proportion
Filed by an AI assistant at the user's request after inspecting the config, the session-context-metrics.ts / session-context-tab.tsx / session-context-format.ts source at HEAD, and the existing issue tracker.
Activity
github-actions commentedon Jul 17, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
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:
limit.contextin config not honored for display; now closed, but worth checking if the fix addressed the Context tab as well)If you believe this was flagged incorrectly, please let a maintainer know.