<!-- llms-explorer concept facts · https://llms-explorer.com/tree/opencode-compaction-config-for-local-providers/ · pack 2026-10-05 · ~1202 tokens -->

# OpenCode compaction config for local providers

> V2 settings: compaction.auto (default true), compaction.keep.tokens (default 15000, recent conversation kept beside the summary), compaction.buffer (default 10% of the limit, tokens kept free; larger starts compaction earlier). Both numbers are non-negative integers.

Parent: [Mac local LLMs: Agent clients, context and compaction](https://llms-explorer.com/tree/mac-local-llms-agent-clients-context-and-compaction/) · 2 facets · 25 facts · page: https://llms-explorer.com/tree/opencode-compaction-config-for-local-providers/

## Facts

- V2 settings: compaction.auto (default true), compaction.keep.tokens (default 15000, recent conversation kept beside the summary), compaction.buffer (default 10% of the limit, tokens kept free; larger starts compaction earlier). Both numbers are non-negative integers. — source: `asserted`
- auto also covers recovery: a request the provider rejects as too long is compacted and retried once; a second rejection is returned as an error. — source: `asserted`
- The summary is written by the session's own model; there is no separate compaction model. — source: `asserted`
- Compaction needs older conversation to replace and cannot make room when a request is mostly fixed instructions and tool schemas (docs example: 128k context = 120k fixed + 8k conversation). — source: `asserted`
- If the conversation to compact is itself too long, OpenCode sends a shortened text version and may omit the oldest exchanges. — source: `asserted`
- Native provider compaction (settings.compaction.type native) works only for OpenAI Responses models; local providers use summary compaction. — source: `asserted`
- After compaction, current instruction files become the session baseline. — source: `asserted`
- OpenCode estimates tokens locally when provider usage is missing, so buffer cannot guarantee no overflow. — source: `asserted`
- V1 (opencode.ai/docs/config, still cached as current there): auto, prune (default false), reserved (token buffer so compaction itself does not overflow). V2 (opencode.ai/v2/docs/compaction, bswen guide updated 2026-09-07): auto, keep.tokens, buffer; the V2 migration note says V1 used tail-turn and pruning behavior. — source: `asserted`
- Issue 8140 (2026-01-13, closed not planned) asked for compaction.threshold (0-1) and compaction.maxContext to compact earlier than the model limit; not adopted, so buffer is the V2 way to compact earlier. — source: `asserted`
- A fixed prefix of tens of thousands of tokens (skill listing, MCP tools) leaves compaction unable to help on a small window (see agent-skill-listing-injection-cost.md). — source: `asserted`
- V1 docs page versus V2 docs page describe different keys under the same name compaction; which applies depends on the installed OpenCode version. — source: `asserted`
- Which config schema OpenCode 1.18.34 (the version measured locally) accepts. — source: `asserted`
- Whether limit.context is required for buffer to take effect on a custom local provider; the bswen guide lists limit.context as the budget basis. — source: `asserted`
- OpenCode V2 compaction keys are auto (true), keep.tokens (15000) and buffer (10% of the limit by default) — [source](https://opencode.ai/v2/docs/compaction/)
- OpenCode V2 recovers once from a provider too-long rejection and returns the second rejection as an error — [source](https://opencode.ai/v2/docs/compaction/)
- OpenCode compaction uses the session's model and has no separate compaction model — [source](https://opencode.ai/v2/docs/compaction/)
- OpenCode compaction cannot create room when fixed instructions and tool schemas fill the window — [source](https://opencode.ai/v2/docs/compaction/)
- OpenCode V1 config keys are auto, prune and reserved — [source](https://opencode.ai/docs/config/)
- V2 uses compaction.keep.tokens instead of V1 pruning and tail-turn behavior — [source](https://opencode.ai/v2/docs/compaction/)
- Issue 8140 asking for compaction threshold and maxContext was closed as not planned — [source](https://github.com/anomalyco/opencode/issues/8140)
- OpenCode estimates tokens locally when provider usage is missing, so buffer cannot guarantee overflow avoidance — [source](https://docs.bswen.com/blog/2026-03-21-opencode-auto-compact-config/)
- Native provider compaction applies to OpenAI Responses models only — [source](https://opencode.ai/v2/docs/compaction/)
- For a small local window set limit.context to the server's real n_ctx and raise buffer, since there is no threshold setting — source: `asserted`

## Corrections and disagreements

- CONTRADICTS: claude-code-context-window-mismatch-against-local-servers.md lists reserved and prune as the compaction config; that is the V1 schema, and a V2 install uses keep.tokens and buffer. — source: `asserted`
