opencode context window: the size comes from the model, and compaction keeps 15 percent free
- opencode
- coding-agents
- context-engineering
The opencode context window is the limit.context value of the model you picked. opencode takes it from the Models.dev catalog, or from your config for a custom model. Near that limit opencode compacts the session by itself. /compact does it on demand. This post is for people who come from Claude Code or Codex and want the numbers. I do not run opencode. It is not installed on my machine. Everything here comes from the docs and the source at tags v1.19.5 and v2.2.5, read on 6 November 2026.
{
"$schema": "https://opencode.ai/config.json",
"compaction": {
"auto": true,
"keep": { "tokens": 15000 },
"buffer": "20%"
}
}
- Size. Each model's
limit.context. Standard providers get it from Models.dev. opencode 2 assumes 200,000 tokens for a custom model without one. - Usage. The TUI sidebar shows tokens, percent used and cost. The docs do not describe it. The source does.
- Threshold. opencode 2 keeps 15 percent of the window free, at least 16,000 tokens. It compacts when the rest is full.
- Command.
/compactin the TUI, keybindctrl+x c. opencode 2 adds an API route. - Settings. The
compactionblock inopencode.json. opencode 1 hasauto,pruneandreserved. opencode 2 hasauto,keep.tokensandbuffer.
How Claude Code handles the same budget, with the 33 edits I wasted after compaction, is in my Claude Code context window post. The Codex numbers are in Codex context window. This one is opencode.
What is the opencode context window size?
opencode has no fixed window. The size is the limit.context field of the selected model. The opencode 1 providers page says the limit fields "allow OpenCode to understand how much context you have left". It adds that "standard providers pull these from models.dev automatically".
In the source the catalog is downloaded from models.opencode.ai and cached on disk. opencode 2 also bundles a snapshot of it.
For a model the catalog does not know, set the limit yourself. The opencode 2 models page shows it per model:
"providers": {
"openai": {
"models": {
"coding-default": {
"modelID": "gpt-6.1-sol",
"limit": { "context": 200000, "output": 32000 }
}
}
}
}
In opencode 1 the top key is provider, not providers. Without a limit, opencode 2 assumes "a 200,000-token context limit and 32,000-token output limit". The docs call these "fallback assumptions, not detected capabilities". Per the docs, opencode 2 reads the context size from Ollama and LM Studio. For vLLM it takes the reported max_model_len.
How do I see context usage in opencode?
Open the session sidebar. In both versions a built-in sidebar plugin draws a Context block. It shows the token count, the percent used and the money spent. The docs do not describe this block. I read it in sidebar/context.tsx at both tags. I have not seen it on screen.
The percent is the last assistant reply's tokens divided by limit.context. opencode adds input, output, reasoning, cache read and cache write. Claude Code's percent leaves output tokens out. My opencode statusline post covers that gap and the footer.
In opencode 2, ctrl+x b toggles the sidebar per the keybind defaults in the source. In cli.json, debug.turn_tokens adds per-turn token usage.
When does opencode compact the context automatically?
opencode 2 compacts when the conversation fills the window minus a buffer. The default buffer is 15 percent of the window, at least 16,000 tokens. A 200,000-token window compacts near 170,000. A 128,000-token window compacts near 108,800. In the source the 16,000 floor applies only to windows of 32,000 tokens or more.
opencode 1 works differently. In overflow.ts the trigger is the window minus the model's output limit, capped at 32,000 tokens. A 200,000 model with an output limit of 32,000 or more lands at 168,000. The reserved key only counts when the model also has a separate input limit. The docs do not mention that condition.
What compaction does in opencode 2 is a summary. The docs say opencode "summarizes the entire current conversation". It keeps the most recent part, "about 15,000 tokens by default", beside the summary. If a provider rejects a request as too long, opencode compacts and retries once. The docs call compaction "lossy".
What are the opencode compaction settings?
The settings sit under compaction in opencode.json. The keys differ by version. opencode 1 documents auto, prune and reserved. opencode 2 has auto, keep.tokens and buffer. In both versions auto defaults to true. The opencode 2 buffer sets the threshold, as a percent such as "20%" or as a token count.
In opencode 1, auto compacts "when context is full". prune removes "old tool outputs to save tokens", default false. reserved is a token buffer. The v1.19.5 schema also has tail_turns and preserve_recent_tokens. With prune on, the source clears tool output older than the newest 40,000 tokens, if more than 20,000 would go.
In opencode 2, keep.tokens defaults to 15,000. The docs say "20%" compacts at 80 percent full. agents.compaction.model writes summaries with another model. experimental.background_compaction prepares the summary ahead of time. The docs mark it experimental. The migration page maps reserved to buffer and drops prune with a warning.
How do I run /compact in opencode?
Type /compact in the TUI. The opencode 1 TUI page lists it as "Compact the current session", alias /summarize, keybind ctrl+x c. In opencode 2.2.5 the source registers the same slash command and the same <leader>c keybind. Manual compaction works with auto off.
opencode 2 adds an API route. The compaction page shows this call:
opencode api post /api/session/ses_example/compact --data '{}'
The response only confirms the request. It does not wait for the summary. I found no opencode compact subcommand in the CLI pages of either version.
How does opencode compare with Claude Code and Codex?
opencode takes the window from the model catalog and compacts with a percent buffer. Codex compacts at 90 percent of its window. Claude Code compacts at the model limit unless you move the trigger with autoCompactWindow. All three have /compact.
| opencode 2.2.5 | Codex CLI 0.166.0 | Claude Code | |
|---|---|---|---|
| Window source | Model limit.context, Models.dev or config | Model catalog, model_context_window | 200K, 1M on models that support it |
| Live view | Sidebar Context block | /status, footer | /context, status line |
| Auto compaction | Window minus 15%, at least 16K | 90% of the window | Model limit or autoCompactWindow |
| Manual | /compact, API route | /compact | /compact with a focus |
| Tuning | buffer, keep.tokens, auto | model_auto_compact_token_limit | /autocompact, autoCompactWindow |
Continuing a long opencode session later is covered in opencode resume.
Frequently asked questions
Did you test this?
No. opencode is not installed on my machine. This post reads the opencode 1 and opencode 2 docs and the source at tags v1.19.5 and v2.2.5 on 6 November 2026. The Claude Code and Codex rows come from my two earlier posts.
What is the default opencode compaction threshold?
In opencode 2, the window minus 15 percent, with at least 16,000 tokens kept free. That is about 170,000 on a 200K model. In opencode 1 the source subtracts the model's output limit, capped at 32,000.
How do I turn off auto compaction in opencode?
Set "auto": false under compaction. opencode 1 also reads the OPENCODE_DISABLE_AUTOCOMPACT environment variable. /compact still works.
Why does opencode show the wrong context size for my model?
The catalog does not know the model, or the provider entry has no limit. Set limit.context on the model. opencode 2 otherwise assumes 200,000 tokens.
The verdict
I use Claude Code and Codex every day. opencode I only read. If I moved, I would check limit.context for my model first. Then I would set buffer as a percent, so one setting fits every model.
Sources, read on 6 November 2026: the opencode config, TUI, CLI and providers pages, the opencode 2 compaction, config, models, CLI config and migration pages, and anomalyco/opencode at tags v1.19.5 and v2.2.5.