Context Window Management¶
Type: OpenClaw memory constraint and mitigation strategy
Definition¶
The context window is the finite amount of text (measured in tokens) that an AI model can process at once. When it fills up, older content is automatically compacted (summarized and compressed) to make room. OpenClaw's session history lives in the context window — when it compacts, some earlier details are lost. The critical rule: don't rely on conversation history for important state; write it to files.
How It Works¶
Current AI models handle 100K+ tokens, but context still has hard limits. When the context window fills, older messages are automatically summarized and compressed by the system. The agent still works, but some details from earlier in the session are gone. This happens silently — the agent doesn't always know what was compacted.
Signs of context overflow: forgotten earlier instructions, repeated questions, and [compacted: tool output removed] messages. When overflow happens, recovery involves: (1) immediately write current state to a file, (2) start a fresh session with context restoration instructions ("Continue project X. Read context.md for background").
The solution to overflow is proactive chunking. Don't ask for "everything about X" in one task — break large tasks into smaller chunks that fit within the context window. Design every project with a context.md file that can be read to restore state after a session gap. Sub-agents with long-running tasks are particularly vulnerable to context exhaustion.
Memory layer discipline helps: if important facts are in MEMORY.md or project context files, they're preserved regardless of what happens in the conversation window. The 5-layer memory system is designed to ensure important context survives compaction events.
Key Properties¶
- Automatic compaction — older content summarized when window fills; agent may not notice what was lost
- Token limits apply — 100K+ tokens sounds large but long conversations, code, and data fill it fast
- Overflow signs — forgotten instructions, repeated questions,
[compacted: tool output removed] - Recovery via files — write current state to file, start fresh session with file as context
- Chunking strategy — break large tasks into smaller pieces to avoid single-task context exhaustion
- 5-layer memory as buffer — important facts in files (MEMORY.md, context.md) survive compaction
Related Concepts¶
- five-layer-memory — the 5-layer system provides files-based persistence as overflow mitigation
- daily-logs — daily log files preserve operational context across session gaps
- subagent-spawning — sub-agents are particularly vulnerable to context exhaustion on long tasks
Source Chapters¶
- kelly-handbook-ch8-memory — context window mechanics and compaction behavior detailed
- kelly-handbook-ch7-multi-agent — sub-agent context exhaustion as failure mode