Sessions
Every conversation in OpenClaw runs inside a session — a fully isolated container with its own context window, tool permissions, and transcript file. Sessions outlive Gateway restarts and can be resumed by key from any device or channel.
How Agents Use Context Engineering — context windows, sessions, and memory in AI agents
Description
A session is OpenClaw's unit of conversation isolation. When a message arrives on any connected channel, the Gateway routes it to a session — creating a new one if none exists, or resuming an existing one if the channel already has an active session assigned.
Each session maintains its own context window — a rolling transcript of the conversation up to the model's token limit. This means two users on two different channels cannot see each other's messages, and tool calls in one session do not affect another.
Sessions are persisted to disk as transcript files (JSON). If the Gateway restarts, the session file is intact and the next message automatically resumes from where it left off. You can also resume sessions manually by session key, or hand a session key to a different channel to continue the conversation from another platform.
Sessions support sub-agents: a session can spawn child sessions to handle parallel subtasks (for example, researching two things at once), then merge results back into the parent. Child sessions are visible in openclaw session list with a parent reference.
Each session loads workspace files on start — SOUL.md, USER.md, MEMORY.md, and AGENTS.md — giving the agent its identity, persona, and user context before the first message is processed.
Key concepts
Session keyA unique identifier for a session (e.g. site:slack:channel:C0ABC123). Used to resume or reference a specific session.
Transcript fileJSON file on disk that stores the full message history. Location: ~/.openclaw/sessions/<key>.json.
Context windowThe slice of the transcript that fits within the model's token limit. Older messages are summarised or dropped as the window fills.
Sub-agentA child session spawned by a parent session. Inherits workspace files but has its own context window and tool scope.
Session routingThe Gateway logic that decides which session a message belongs to, based on channel, chat ID, and conversation type.
CLI commands
List all active sessions
openclaw session listResume a session by key
openclaw session resume <session-key>Show a session's full transcript
openclaw session history <session-key>Kill (terminate) a session
openclaw session kill <session-key>Show info about a specific session
openclaw session info <session-key>Tips
Cross-device continuity
Copy a session key and use openclaw session resume <key> from any machine with the Gateway running and the same workspace. Context is in the transcript file.
Long sessions get expensive
As context grows, token usage per turn increases. Use /compact in the session or kill and restart for long-running tasks that changed direction.
Sub-agents for parallel work
For tasks that can be split (e.g. "research X and Y simultaneously"), instruct the agent to spawn sub-agents. They run concurrently and merge back.