The Context Window and Memory
You spend an hour planning a trip with your agent. A week later you ask, "Which hotel did we pick?" Whether it knows depends on two different mechanisms, and mixing them up causes most "why did it forget?" surprises.
The rule
The window forgets; the files remember.
The context window is everything the model can see at once while it writes a reply: instructions, workspace files, skills, the conversation so far and tool results. Its size is fixed by the model. Every message and every tool result takes up some of it, so a long session keeps filling it.
OpenClaw manages the window with a context engine and compaction. When a session grows too long, older parts of the conversation are summarised automatically: the essentials stay, the space is freed. You can also steer it from the chat:
/compactsummarises now, and you can add a note on what to keep./newstarts a fresh session. Before it resets, the session-memory hook saves what was discussed./context listor/context detailshows what is taking up the window, file by file, tool by tool and skill by skill.
The memory system is the long-term part. Facts, past interactions and preferences are stored in memory files inside the agent's workspace, and the agent can write to them and look things up in them across conversations. Section 5 looks at those files one by one.
So compaction keeps this conversation going, while memory files carry things into future ones. A long window also has a price: the context is sent to the model with every reply, so a bloated session costs more tokens on a hosted provider.
The shortcut
Ask: "Does it matter for this conversation, or for every conversation?" This one: the context window will do. Every one: it has to end up in a memory file.
The hour-long planning chat
Every message and search result sits in the context window. As it fills, compaction summarises the oldest parts.
The trap is treating one endless session as memory. It fills the window, costs tokens on every reply, and compaction eventually squeezes out details. Start a new topic with /new.
Drills
Answer fast — trust the rule.
What is the context window?
What does compaction do?
What happens when you type /new?
You want the agent to know your shoe size six months from now. Where should that live?
Which command shows how much of the window each file, tool and skill is using?
Remember
- The window forgets; the files remember.
- Ask "this conversation or every conversation?" If every, it belongs in a memory file.
- Trap: one endless session. Use
/newfor a new topic and/compactwhen a chat runs long.
