Compaction
Managing context window size through compaction.
What is Compaction?
Compaction summarizes old messages to reduce context size while preserving important information.
Why Compact?
- Token limits: Models have context window limits
- Cost: Fewer tokens = lower API costs
- Performance: Smaller contexts process faster
How It Works
Messages 1-20 → Summary of 1-20
Messages 21-40 → Summary of 21-40
Messages 41-50 → Full messagesOld messages are summarized, recent messages kept in full.
Configuration
json5
{
compaction: {
enabled: true,
threshold: 50, // Messages before compaction
keepRecent: 10, // Recent messages to keep full
summaryModel: "claude-3-haiku" // Model for summaries
}
}Manual Compaction
bash
# Compact specific session
openclaw sessions compact <session-id>
# Compact all sessions
openclaw sessions compact --allCompaction Strategies
Rolling
Summarize oldest messages as new ones arrive.
Threshold
Compact when message count exceeds threshold.
Token-Based
Compact when token count approaches limit.