Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How OpenClaw Works  ›  Lesson

The Context Window and Memory

Context Window 13 minThe context window is everything the model sees at once and is kept in check by compaction, while memory files in the workspace carry facts from one conversation to the next.

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:

  • /compact summarises now, and you can add a note on what to keep.
  • /new starts a fresh session. Before it resets, the session-memory hook saves what was discussed.
  • /context list or /context detail shows 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.

A trip, and a week laterStep 1 of 4
  1. 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.

quick drill

What is the context window?

quick drill

What does compaction do?

quick drill

What happens when you type /new?

quick drill

You want the agent to know your shoe size six months from now. Where should that live?

quick drill

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 /new for a new topic and /compact when a chat runs long.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy did it forget?

A user complains: 'I told my agent my wife's birthday last month and now it doesn't know it.' Explain the difference between the context window and the memory system, and what the user should do.