OpenCode context usage — see, limit, and reduce
To see how much context OpenCode is using, check the session sidebar in the TUI — it shows context fill as a percentage of the model window. To limit context, set limit.context on custom models, enable compaction/prune, start new sessions per task, and disable unused MCP servers that inject tool schemas every turn.
Hub: Tokenminning in OpenCode.
How do I see context usage in OpenCode?
OpenCode shows context fill in the session sidebar of the TUI — percentage of the model window consumed by configuration + transcript + tool outputs.
| Sidebar level | Action |
|---|---|
| < ~70% | Normal — keep working |
| ~70–80% | Run /compact or plan a new session |
| > ~80% | New session before Build explores further |
| Compaction runs repeatedly | Session grows faster than pruning removes — new session per task |
opencode stats measures billing over time; the sidebar is the live guardrail. See Token usage.
There is no separate “context usage dashboard” URL — the TUI sidebar is the authoritative live meter.
Context window limits
Context includes everything resent on each agent turn:
| Source | What counts |
|---|---|
AGENTS.md, rules, skills metadata | Input tokens every turn |
| MCP tool schemas | Every enabled server, every turn — even when tools are not called |
| Session transcript | All prior messages and tool outputs |
| Reasoning models | Thinking tokens add output pressure — change reasoning effort on Plan, not Build |
@ file attachments | Full file contents referenced |
Run opencode stats --tools after enabling a new MCP server to measure schema overhead.
Override catalog defaults when you want earlier compaction:
{
"provider": {
"my-provider": {
"models": {
"my-model": {
"limit": {
"context": 128000,
"output": 8192
}
}
}
}
}
}User-defined limit.context overrides catalog defaults — useful when a model advertises 1M context but you want compaction sooner. Details: Providers.
Compaction
{
"$schema": "https://opencode.ai/config.json",
"compaction": {
"auto": true,
"prune": true,
"reserved": 10000
}
}| Field | Default | Effect |
|---|---|---|
auto | true | Summarize when context nears limit (hidden compaction agent — costs tokens once) |
prune | false | Strip old tool outputs while keeping recent ones — set true to opt in |
reserved | — | Token buffer left for the compaction call itself |
Official default for prune is false. Enable it explicitly when long sessions accumulate tool output bloat.
Manual compaction in the TUI:
/compactAlias: /summarize. See TUI commands .
Disable auto-compaction if you always use new sessions per task:
export OPENCODE_DISABLE_AUTOCOMPACT=trueV2 compaction fields
Newer OpenCode releases may use keep.tokens and buffer instead of prune/reserved. See Compaction docs for your version.
Compression and pruning
Compression (/compact, auto-compaction) summarizes older transcript into a shorter block — it costs tokens once but frees window space. Pruning (prune: true) removes stale tool outputs without a full summarize pass.
| Technique | Config / command | When to use |
|---|---|---|
| Auto-compact | compaction.auto: true | Long sessions that approach the window |
| Manual compact | /compact in TUI | Sidebar at ~70–80% before Build explores |
| Prune tool outputs | compaction.prune: true | Agent-heavy sessions with large read/bash results |
Pruning
prune: true strips old tool outputs while keeping recent ones — opt in explicitly (default is false). Pair with /compact when long sessions accumulate tool output bloat.
Reducing unnecessary context
How MCP affects context
Each enabled MCP server adds tool JSON schemas to every agent turn. Five overlapping servers can exceed a modest model window before your actual prompt.
Disable MCP servers you are not using this week:
{
"mcp": {
"github": { "enabled": false },
"playwright": { "enabled": false }
}
}Full patterns (per-agent toggles, org remote defaults): MCP guide.
Cap agent steps when loops are the problem:
{
"agent": {
"build": {
"steps": 25
}
}
}Combine with permission.bash: "ask" (Agents).
Practical ways to avoid filling the context window
| Technique | Savings |
|---|---|
| New session per task | Stops transcript compounding |
Short AGENTS.md | Rules |
| Disable unused MCP | MCP |
| Haiku on Plan, not thinking models | Change reasoning effort in OpenCode |
Narrow @ mentions | One file, not whole trees |
/compact once, then new session | Compaction is not free |
New session per task
Start a new session when:
- You finish one task and begin another
- Sidebar context is above ~70%
- Compaction already ran once on the same thread
- The agent loops on a stuck problem
Switch with /sessions or command palette (ctrl+p). See TUI .
Troubleshooting
Context overflow errors — Run /compact; new session; verify limit.context for custom providers.
Compaction runs often — Prune is working but you add tokens faster than removal. New session per task.
“Context mode” queries — OpenCode does not expose a separate “context mode” toggle; behavior is compaction + limits + session boundaries above.
Related
- OpenCode hub
- MCP — disable MCP, schema overhead
- Change reasoning effort in OpenCode — thinking tokens
- Providers —
limit.contextoverrides - Token usage
- Context hygiene