Sessions
Sessions provide conversation context isolation for each sender. Every DM, group chat, or thread gets its own session with persistent message history, model settings, and conversation state.What is a Session?
A session is a conversation context that includes:- Message History: Full conversation transcript
- Agent State: Current model, settings, and configuration
- Metadata: Sender info, channel, timestamps
- Delivery Context: Last known route for replies
- Usage Tracking: Token counts and model information
Session Keys
Session Key Format
Each session has a unique key that identifies the conversation:Session Key Components
Location: src/routing/session-key.ts:90
DM Session Scoping
Direct messages can share or separate sessions:main: All DMs share one session (default)per-peer: Separate session per senderper-channel-peer: Separate per sender+channelper-account-channel-peer: Separate per account+channel+sender
main (shared):
per-peer:
per-channel-peer:
Identity Links
Link identities across platforms to share sessions:Session Storage
Storage Location
Sessions are stored as JSONL files:Session Transcript Format
Each.jsonl file contains one message per line:
Session Metadata
Session metadata is stored insessions.json:
sessionId: Unique UUID for this sessionupdatedAt: Last message timestamp (ms)label: Display name for UIchannel: Originating channelchatType:direct,group,channel, orthreadmodel: Current AI modelcompactionCount: Number of compactions performedlastChannel,lastTo: Delivery context for replies
Session Lifecycle
Session Creation
Sessions are created automatically on first message:- User sends first message
- Router generates session key based on agent, channel, and sender
- Gateway creates session with empty history
- Agent processes message and generates response
- Session saved to disk with metadata
Session Reset
Sessions can be reset manually or automatically: Manual Reset:daily: Reset at specific hour each dayidle: Reset after N minutes of inactivity
Session Compaction
When a session grows too large, OpenClaw compacts it:- Trigger: Session exceeds token limit (e.g., 100k tokens)
- Compaction LLM: Summarizes conversation history
- Summary Injected: Replaces old messages with summary
- Recent Messages Kept: Last N messages preserved
- Transcript Updated: Compaction event logged
Compaction preserves conversation continuity while reducing token usage and cost.
Session Configuration
Basic Settings
Reset Configuration
Maintenance Configuration
mode:warn(log only) orenforce(apply limits)pruneAfter: Remove sessions older than duration (e.g.,30d,12h)maxEntries: Maximum session count insessions.jsonrotateBytes: Rotatesessions.jsonwhen size exceeds limit
Session Pruning
Automatic Pruning
Old sessions are pruned automatically: Default Behavior:- Sessions older than 30 days are warned
- Mode defaults to
warn(no automatic deletion)
Manual Pruning
Archival
Before pruning, sessions are archived:Session Management
List Sessions
Inspect Session
Reset Session
Session Persistence
Write Lock
Session writes are protected by a lock to prevent corruption:Atomic Writes
Session updates use atomic write-then-rename:- Write to
.tmpfile - Verify write succeeded
- Rename to final path
Cache Management
Session metadata is cached in memory:- TTL: 45 seconds (default)
- Invalidation: On write
- Size Limit: 5000 entries
Advanced Features
Thread Sessions
Threaded conversations create sub-sessions:Group History Keys
Group chats use a shared history key:Session Send Policy
Control which sessions can send outbound messages:Troubleshooting
Session Not Loading
Session Corruption
High Token Usage
Next Steps
Message Routing
Configure multi-agent routing rules
Agent Configuration
Customize agent behavior and models
Channel Setup
Connect messaging platforms
Session Commands
CLI reference for session management

