What each harness does when the conversation outgrows the context window: when it compacts, what it keeps, and how you can steer it.
When it happens
| Question | OpenCodechecked at 2.0.29 |
|---|---|
| Automatic compaction, and when | Yes. Before each model step OpenCode estimates the prompt and compacts when it reaches the usable input window minus a buffer. At 2.2.7 the window is the smaller positive input/context limit when both exist, otherwise the known limit. The default buffer is 15% of that window or 16,000 tokens, whichever is larger (windows under 32K keep just 15%). An explicit token or percentage buffer overrides it when it leaves room. Models with an unknown window never auto-compact; only a provider rejection triggers it. The 2.1 default is earlier than the previous 10% reserve. v2.1.1 uses floor(window × 0.15); an explicit compaction.buffer overrides the default. Since 2.3.1, background summary preparation is on by default; set compaction.background: false to disable it. experimental.background_compaction is removed. At 2.3.2 the runner calls precompute, which requires auto and background, skips native compaction, and checks measured prompt, model and cache freshness before holding a summary for the normal compaction boundary. An unused summary still costs tokens. The older 2.1.4 64K/85% preparation conditions are historical, not current. No runtime probe. |
| Change the trigger or turn it off | Set compaction.buffer to a token count or, since 2.2.5, a percentage string such as "20%" to compact at 80% of the usable input window. Larger buffers compact earlier. A buffer that leaves no room is ignored in favor of the default. Set compaction.auto to false to disable automatic and overflow compaction; manual compaction remains. Historical 2.1.4 finding (superseded by 2.3.1): 2.1.4 adds experimental.background_compaction: true. It prepares a summary before the ordinary trigger but does not apply it immediately or change the configured trigger. Unused summaries still consume tokens. V2 has no Since 2.3.1, background summary preparation is on by default; set compaction.background: false to disable it. experimental.background_compaction is removed. At 2.3.2 the runner calls precompute, which requires auto and background, skips native compaction, and checks measured prompt, model and cache freshness before holding a summary for the normal compaction boundary. An unused summary still costs tokens. The older 2.1.4 64K/85% preparation conditions are historical, not current. No runtime probe. |
| Compact by hand | Partly Type The V1 alias |
| See how full the context is | The TUI prompt footer and the sidebar's Context section show the last response's tokens and the percentage of the model's context window, for example The approximate 85% trigger is the default in 2.1, not a universal configured threshold; the 16K minimum advances it on small windows. |
What it does
| Question | OpenCodechecked at 2.0.29 |
|---|---|
| What replaces the conversation | In 2.1, summary compaction normally sends the whole conversation, including the tail that will be kept, to the summary model so it can reuse the normal prompt cache. It writes a structured checkpoint (Objective, Requirements, Decisions, Work State, Next Move, Relevant Files, Important Context), and later requests combine that summary with recent text reconstructed from metadata.keepID. If the whole request cannot fit, the implementation falls back to the history before the retained tail and then progressively shrinks it. A supported native compaction instead stores its provider replacement window in native.messages. The docs say there is no separate compaction model, but the source does honor a model set on the hidden The summary call no longer stores unused provider replay data. A compaction hook may still supply result.native; native.messages overrides text replay when present. At 2.1.4, precomputation requires >=85% of the calculated compaction ceiling and a measured prompt >=64K tokens. It is skipped for native compaction, an already-due context or an unknown ceiling; a held summary is reused only while its anchor/model/tail remain valid, otherwise ordinary summarization runs. A still-running usable summary can be awaited. 2.1.3–2.1.4 summary output uses normal model output-room calculation, with a 32K floor limited by actual remaining room; it is not an unconditional 32K cap or reservation. 2.2.0 source sizes the first unchanged summary request using the provider-reported prompt count plus estimates of later text. Overflow-triggered summaries and retries after rejection use estimation/reduction instead; plugin hooks can still enlarge a request beyond the measured count. This does not change the recorded automatic trigger formula. Since 2.3.1, background summary preparation is on by default; set compaction.background: false to disable it. experimental.background_compaction is removed. At 2.3.2 the runner calls precompute, which requires auto and background, skips native compaction, and checks measured prompt, model and cache freshness before holding a summary for the normal compaction boundary. An unused summary still costs tokens. The older 2.1.4 64K/85% preparation conditions are historical, not current. No runtime probe. |
| What survives | About Since 2.1, newly written summaries reference the first retained message with metadata.keepID instead of duplicating recent text. History reconstructs the text up to the checkpoint; forks remap this reference. Legacy recent text is decoded as metadata.recent. 2.2.0 source folds current instruction values into the new epoch on compaction completion. API-managed entries persist separately from chronological updates; no runtime preservation probe. |
| Trimming without summarising | |
| The full history afterwards | Yes. Earlier messages remain stored. In 2.1, a completed summary stores summary text and metadata.keepID referencing the first retained message; history reconstructs the kept text rather than duplicating it in the checkpoint. Legacy compactions retain their text through metadata.recent. Native checkpoints store native.messages. The TUI shows compaction as it starts, streams and ends. |
Shaping it
| Question | OpenCodechecked at 2.0.29 |
|---|---|
| Customise the summary or hook in | Plugins can register OpenCode appends its own summary prompt after the hooks run, so a hook cannot replace it except by supplying 2.1 replaces SessionCompactionResult.providerState with native. Hook metadata can override keepID; result.native.messages supplies a replacement message window. The obsolete session.compacted event is removed; use session.compaction.started/ended. |
| When a request overflows anyway | If the provider rejects a request as too long, OpenCode compacts, aiming at 70% of the rejected size, and retries once. A second rejection is returned as an error. If the summary request itself is too long, OpenCode sends a flattened text version and shrinks it to 70%, 50%, then 35%, dropping the oldest exchanges, before giving up. With The docs' Settings table says In 2.0.29, output-token-limit (finish reason length) recovery is separate from context-overflow compaction: source adds continuation guidance and fails after three consecutive length-limited assistant responses (two continuations). In 2.0.30, the summary request and its retry reduce the output-token allowance to fit the actual estimated prompt remaining in the model window. This is summary request budgeting, not a new auto-compaction threshold. 2.1.4 ignores an explicit buffer that leaves no room. Oversized summary requests progressively shorten exchanges: clip tool output, remove outputs/clip tool inputs, retain clipped user text, then omit an exchange. Precomputed summaries are not used for overflow recovery. 2.2.1 /goal: if the goal reviewer's request overflows the context window, OpenCode compacts the session once and reviews again. A second overflow in the same round pauses the goal. |
Notes and sources
OpenCode, 47 sources
- Since 2.3.1, background summary preparation is on by default; set compaction.background: false to disable it. experimental.background_compaction is removed. At 2.3.2 the runner calls precompute, which requires auto and background, skips native compaction, and checks measured prompt, model and cache freshness before holding a summary for the normal compaction boundary. An unused summary still costs tokens. The older 2.1.4 64K/85% preparation conditions are historical, not current. No runtime probe.