Compaction
Context window + compaction: how OpenClaw keeps sessions within model limits.
Every model has a context window (the maximum tokens it can see). Long-running chats accumulate messages and tool results; once the window gets tight, OpenClaw compacts older history to keep it within limits.
What is compaction
Compaction summarizes older conversation into a compact summary entry while keeping recent messages intact. The summary is stored in the session history, so future requests use:
- The compacted summary
- The latest messages after the compaction point'
''
'Compaction ''persists'' in the session's JSONL history.
Configuration
See ''compaction configuration and modes'' for ''agents.defaults.compaction'' settings.
Auto-compaction (enabled by default)
When a session approaches or exceeds the model's context window, OpenClaw triggers auto-compaction and may retry the original request with compacted context.
You'll see:
- ''🧹 Auto-compaction complete'' in verbose mode'
'- ''/status'' shows ''🧹 Compactions: <count>''
Before compaction, OpenClaw can run a ''silent memory flush'' to store persistent records to disk. See ''Memory'' for details and configuration.
Manual compaction
Use ''/compact'' (optionally with a directive) to force a compaction pass:
/compact Focus on decisions and open questions
Context window source
Context windows are model-specific. OpenClaw uses model definitions from the configured provider directory to determine limits.
Compaction vs. pruning
- Compaction: Summarizes and persists in JSONL.
- Session pruning: Trims old tool results only, on-demand, in-memory.
See ''/concepts/session-pruning'' for details on pruning.
Tips
- Use ''/compact'' when a session feels stale or context-bloated.
- Large tool outputs are truncated; pruning can further reduce tool result buildup.
- If you need a fresh session, ''/new'' or ''/reset'' starts a new session ID.