Remote OpenClaw Blog
OpenClaw Memory Keeps Resetting: The Permanent Fix
7 min read ·
Remote OpenClaw Blog
7 min read ·
You configured your OpenClaw agent with detailed instructions, user preferences, and operational context. It worked perfectly for the first few hours. Then it forgot everything — your name, your preferences, the project it was working on, all of it.
This is the most common complaint in the OpenClaw community, and the root cause is almost always the same: context compaction. According to the official OpenClaw memory documentation, compaction is an automatic process that summarizes older conversation history to stay within the model's token window.
The problem is that compaction does not distinguish between throwaway messages and critical operational context. Your agent's core instructions, your communication preferences, and your business rules are all treated as expendable conversation history.
Every LLM has a maximum context window — the total number of tokens it can process at once. Claude 3.5 Sonnet supports 200K tokens. GPT-4o supports 128K. When the conversation history approaches this limit, OpenClaw triggers compaction.
During compaction, OpenClaw takes the oldest messages in the conversation, generates a summary, and replaces the original messages with the summary. This process is lossy. Specific details, exact instructions, and nuanced preferences get compressed into generic summaries.
The default maxContextTokens setting is 60% of the model's limit. For Claude 3.5 Sonnet, that means compaction triggers at around 120K tokens — which a busy agent can hit within a single working day. According to community benchmarks shared in the GitHub discussions, agents processing more than 50 messages per day will trigger compaction within 8-12 hours on default settings.
The first step is to increase maxContextTokens to 80% of your model's context window. This gives the agent more room before compaction triggers, extending the time between memory resets.
# For Claude 3.5 Sonnet (200K window)
openclaw config set memory.maxContextTokens 160000
# For GPT-4o (128K window)
openclaw config set memory.maxContextTokens 102400
# For Claude 3 Opus (200K window)
openclaw config set memory.maxContextTokens 160000
Setting this above 80% is not recommended. The remaining 20% is needed for the agent's system prompt, current tool outputs, and response generation. Going higher risks hitting the hard token limit, which causes the agent to crash rather than gracefully compact.
This fix alone extends memory retention from 8-12 hours to roughly 18-24 hours for a typical agent workload. It is not a permanent solution, but it buys time while you implement the deeper fixes below.
OpenClaw supports a [PINNED] tag that marks specific messages as immune to compaction. Pinned content is never summarized or discarded, regardless of how full the context window gets.
Add the [PINNED] tag to the beginning of any message you want to persist permanently:
[PINNED] My name is Zac. I am the founder of Remote OpenClaw.
Always address me by name. Never use generic greetings.
[PINNED] Communication preferences:
- Respond in short paragraphs, 2-3 sentences max
- Use bullet points for lists
- Never use emojis
- Default to Telegram for notifications, email for reports
[PINNED] Business rules:
- Never commit to deliverables without my approval
- Always check the project board before starting new work
- Escalate anything involving money or contracts
Limit pinned content to under 2,000 tokens. Every pinned message permanently occupies space in the context window. Too many pinned messages reduce the available space for actual conversation, which triggers compaction more frequently — defeating the purpose.
If your agent handles a low volume of messages (under 20 per day), you can disable automatic compaction entirely and manage context manually:
openclaw config set memory.autoCompaction false
With auto-compaction disabled, you are responsible for clearing the conversation history when the context window fills up. The agent will warn you when it reaches 90% capacity. At that point, you can manually trigger a selective compaction:
# Compact only messages older than 24 hours
openclaw memory compact --older-than 24h
# Compact everything except pinned messages
openclaw memory compact --preserve-pinned
This approach gives you full control over what gets kept and what gets discarded. The trade-off is that you need to monitor context usage and intervene manually. For high-volume agents, this is not practical.
The permanent fix for memory loss is to move critical context out of the conversation history and into persistent files on disk. OpenClaw reads these files at the start of every session, so they survive any amount of compaction.
The recommended structure uses five files, as documented in the OpenClaw Memory Configuration Guide:
This file defines who the agent is, how it behaves, and what rules it follows. It is loaded first on every session start.
# SOUL.md
You are Atlas, an AI chief of staff for Zac Frulloni.
Your role is founder operations: calendar, email, tasks, and communications.
## Core Rules
- Never commit to deliverables without explicit approval
- Respond in short, direct paragraphs
- Escalate anything involving money or legal matters
- Default communication channel: Telegram
This file stores everything the agent has learned about the user: preferences, patterns, contacts, and context.
Marketplace
Free skills and AI personas for OpenClaw — browse the marketplace.
Browse the Marketplace →# USER.md
## Zac Frulloni
- Timezone: America/Los_Angeles
- Preferred name: Zac
- Communication style: direct, no fluff
- Morning availability: after 9am PT
- Key contacts: [list of frequent contacts and their roles]
This file acts as a table of contents for all memory files. The agent reads it to know what other files exist and when they were last updated.
# MEMORY.md — Memory Index
- SOUL.md — agent identity and core rules (updated 2026-04-06)
- USER.md — user preferences and patterns (updated 2026-04-06)
- AGENTS.md — multi-agent coordination (updated 2026-04-05)
- daily-logs/2026-04-06.md — today's operational log
If you run multiple OpenClaw agents, this file defines how they coordinate: which agent handles which tasks, handoff protocols, and shared context.
A directory of daily log files where the agent records key decisions, actions taken, and context that should persist beyond the current session. Old logs can be archived or summarized weekly.
# daily-logs/2026-04-06.md
## Actions
- 09:15 — Sent daily briefing via Telegram
- 10:30 — Rescheduled meeting with Gordon to Thursday
- 14:00 — Drafted proposal for Kanesh, awaiting review
## Decisions
- Zac approved the $2,500 budget for Fyndaro project
- Connor engagement paused until May
For the full memory setup walkthrough, see OpenClaw Memory Not Working: The Fix Guide.
File-based memory handles identity, preferences, and logs well. But it struggles with relational knowledge — connections between entities, cause-and-effect relationships, and contextual associations that span multiple domains.
Cognee is an open-source knowledge graph engine that integrates with OpenClaw to provide structured relational memory. Instead of flat files, Cognee stores knowledge as a graph of interconnected nodes.
Install Cognee and connect it to your OpenClaw instance:
# Install Cognee
pip install cognee
# Configure OpenClaw to use Cognee for knowledge storage
openclaw config set memory.knowledgeEngine cognee
openclaw config set memory.cogneeEndpoint http://localhost:8000
With Cognee enabled, your agent can store and retrieve relational knowledge like "Client X prefers email over Slack," "Project Y depends on API Z," and "The last time this error occurred, the fix was to restart the gateway." This context persists across sessions and is queryable by the agent when relevant.
Cognee does not replace the file-based memory system. Use SOUL.md and USER.md for identity and preferences. Use Cognee for relational knowledge that does not fit neatly into static files.
The complete memory stack combines all five fixes into a layered architecture:
Operators using this full stack report zero memory loss over 30+ day continuous operation periods, according to feedback shared in the Remote OpenClaw community. The agent remembers user preferences, project context, and operational history indefinitely.
For the detailed configuration walkthrough, start with the OpenClaw Memory Configuration Guide and then read OpenClaw Persistent Memory Methods for advanced techniques.
OpenClaw uses context compaction to stay within the model's token limit. When a conversation exceeds maxContextTokens (default 60% of model limit), the system summarizes older messages and discards the originals. Critical instructions, user preferences, and operational context get lost in this process unless they are pinned or stored in persistent memory files.
The recommended 5-file architecture uses SOUL.md for agent identity, USER.md for user preferences, MEMORY.md as the index, AGENTS.md for multi-agent coordination, and a daily-logs directory for timestamped records. This structure survives compaction because files are read from disk on each session start.
No. Cognee provides a knowledge graph layer that complements the file-based memory system. SOUL.md and USER.md handle identity and preferences. Cognee handles relational knowledge like "Client X prefers email over Slack" or "Project Y depends on API Z." Use both together for the most reliable memory architecture.