OpenClaw compaction
How long conversations are summarized to stay inside the model window, the safeguard mode that audits the summary, auto-compaction and overflow recovery, manual compaction with a focus, and the model, identifier and byte-guard settings
Every model has a context window, and every long conversation eventually meets it. Compaction is the answer: older turns become a summary, recent turns stay exactly as they were, and the conversation continues. What deserves attention is everything around that simple idea, because the guardrails decide whether a summary is trustworthy and whether a failed compaction can cost you history.
The mechanism
- Older turns are summarized into a compact entry, the summary is saved in the session transcript, and recent messages are kept intact; when the split point would land inside a tool block, OpenClaw moves the boundary so an assistant tool call and its matching result stay together and the current unsummarized tail is preserved.
- The built-in summarizer accounts for Chinese, Japanese and Korean characters in both message text and tool arguments when estimating chunk sizes, and those budgets are approximate, so a tool call and its results stay together even when the group exceeds a chunk target.
- Summarization receives text, not image pixels: omitted images and other non-text input get explicit markers rather than a claim that a model processed them, the first eight affected messages receive at most two markers each and further omissions get one aggregate statement, and the whole addition is capped at 847 bytes per request.
- New configurations default the compaction mode to safeguard, which applies the final summary budget before validation, requires the headings to survive in the retained body and pending asks and exact identifiers to survive in the stored text, allows only the configured number of corrective attempts, and stops before writing a transcript entry when nothing passes, keeping the original history.
The full conversation history stays on disk. Compaction only changes what the model sees on the next turn.
Automatic, overflow and manual
Auto-compaction is on by default and runs when the session nears the limit or when the provider returns a context-overflow error, in which case OpenClaw compacts and retries; it recognises dozens of provider-specific overflow strings across the major vendors. Overflow recovery trims tool results inside the current window rather than copying older messages into new entries. Stopping a run stops its recovery too, and cancellation is explicitly not a rollback: a compaction that already completed stays in the transcript and is still counted. In persistent sessions, required checkpointing and compaction happen before inference while optional memory flushing and compaction wait until the reply has settled, using a separate session owner and the turn's remaining time. A manual command forces compaction and accepts a focus, which the host caps at 800 code points and escapes as prompt data, and client-side manual compaction keeps a recent tail sized by a token budget that defaults to 20,000.
The settings worth knowing
- A model override selects a different summarization model, accepting a provider and model string or a configured alias, and when unset compaction starts with the active session model; a fallback-eligible provider error retries that attempt through the session's fallback chain, but an explicit override stays exact and does not inherit it.
- Identifier preservation is strict by default so opaque identifiers survive the summary, an active transcript byte guard can trigger normal compaction once persisted history reaches a size such as twenty megabytes, and a notice setting turns the silent default into brief start and finish messages plus a degraded notice when a pre-compaction memory flush is exhausted.
- Before compacting, OpenClaw reminds the agent to save durable notes to memory files, and that flush is optional maintenance: a failure, including exhausted retries, does not reset the session or discard history, while a failed required compaction is reported with the conversation left intact rather than started over.
OpenClaw context explained is what compaction is defending and OpenClaw session pruning the lighter complement that trims tool output instead of summarizing.
Providers, successors and plugins
When an embedded provider returns a compacted window, OpenClaw keeps the complete returned context beside the checkpoint, limited to 16 mebibytes, and falls back to ordinary client-side compaction rather than truncating oversized output. If a redaction removes the window needed for replay, the manual command rebuilds context from the saved conversation instead of guessing. A context engine may return a compacted successor session inside the same agent and store, which OpenClaw publishes before maintenance or retries use it, while the built-in compactor keeps the current identity and never creates a second transcript. Plugins can register a compaction provider, which forces safeguard mode, receives the same instructions and identifier policy, and falls back through the built-in summarizer when it fails or returns nothing. OpenClaw context engines covers that pluggable layer and OpenClaw memory search the search this all keeps affordable.
On Diali
On Diali the assistant keeps its session state on a persistent volume, so the transcript that compaction writes into is durable rather than a cache; daily snapshots and one-click restore are available through the Backups add-on (included on Max). Hosted OpenClaw on Diali describes the hosted assistant and Diali pricing the plans it ships in.
- Summaries are written to the transcript; raw history stays on disk.
- Safeguard mode fails closed rather than writing a bad summary.
- A tool call and its result are never split by the boundary.
Stop reading about it, build one
Set up an agent, pick a channel, and have it working inside the app you already keep open.
