Skip to content

Session Management

xopc provides comprehensive session management for conversation history via CLI and Web UI.


Overview

FeatureCLIWeb UI
List sessions
Search sessions
View details
Archive/Unarchive
Pin/Unpin
Export (JSON)
Delete
Reset in place (/new)✅ (channels)
Search in session

Session Storage

PropertyValue
Database~/.xopc/xopc.db (SQLite, WAL)
Tablessessions, transcripts, transcript_entries, session_config, compaction_checkpoints, transcript_fts (FTS5)
Per-session overridesSQLite session_config (model, thinking, verbose, …)
Legacy pathagents/<agentId>/sessions/ may exist from older installs; new installs do not write transcripts there

Session metadata, transcript rows, compaction checkpoints, and full-text search are stored in SQLite. The gateway opens the database on startup (openXopcDatabase()).


Reset vs delete

ActionSession keyTranscriptOverrides (session_config, thinking on session row)
Reset (/new, POST /api/sessions/:key/reset)Same keyCurrent transcript archived in SQLite; new sessionId + empty transcriptPreserved
Delete (DELETE /api/sessions/:key)Removed from indexTranscript rows removed with sessionConfig removed with session

Channel slash /new (aliases /reset, /restart) uses reset semantics, not delete. TUI /new / /reset call the same reset API in gateway mode (POST /api/sessions/:key/reset via performSessionReset).

Automatic rollover: At turn start, xopc evaluates session.reset (daily at atHour or idle via idleMinutes) and archives + assigns a new sessionId when the session is stale—same as OpenClaw channel initSessionState. Configured session.resetTriggers (default ["/new","/reset"]) are matched on inbound body before the model runs; bare triggers ack without a turn, /new hello resets then continues with hello.

Webchat API: POST /api/agent requires sessionKey / chatId in agent:{agentId}:{rest} form (or omit for agent:main:main). Bare chat_* ids are rejected; create sessions via POST /api/sessions.


Agent session keys

Runtime session keys use the OpenClaw-aligned form agent:{agentId}:{rest}:

ShapeExampleUse
Main bucketagent:main:mainDefault TUI/CLI “home” session when session.scope is per-sender (session.mainKey defaults to main)
Global scopeglobalWhen session.scope is global and no -s is passed
Channel peeragent:main:telegram:default:direct:123456Routed inbound/outbound chats
Shorthandmytopic on CLI/TUIExpanded to agent:{currentAgentId}:mytopic

The agentId segment selects one enabled agents.list manifest, with any declared capabilityPresets applied. That effective manifest owns workspace, model roles, tool policy, and agent home (agents/<id>/). Prefer full agent:… keys in scripts; shorthand is fine for interactive TUI.


Session States

StatusDescription
activeCurrently active session (default)
pinnedPinned to top for quick access
archivedArchived and moved to archive folder

CLI Usage

List Sessions

bash
# List all sessions
xopc session list

# Filter by status
xopc session list --status active
xopc session list --status archived
xopc session list --status pinned

# Search by name or content
xopc session list --query "project"

# Sort and limit
xopc session list --sort updatedAt --order desc --limit 50

View Session Details

bash
# Show session info and recent messages
xopc session info telegram:123456

# Search within a session
xopc session grep telegram:123456 "API design"

Manage Sessions

bash
# Rename a session
xopc session rename telegram:123456 "Project Discussion"

# Add tags
xopc session tag telegram:123456 work important

# Remove tags
xopc session untag telegram:123456 important

# Archive a session
xopc session archive telegram:123456

# Unarchive a session
xopc session unarchive telegram:123456

# Pin a session
xopc session pin telegram:123456

# Unpin a session
xopc session unpin telegram:123456

# Delete a session
xopc session delete telegram:123456

# Export session to JSON
xopc session export telegram:123456 \
  --format json \
  --output backup.json

Bulk Operations

bash
# Delete multiple sessions by filter
xopc session delete-many --status archived --force

# Archive old sessions (30+ days inactive)
xopc session cleanup --days 30

Statistics

bash
xopc session stats

Sample output:

📊 Session Statistics

  Total Sessions:     42
  Active:             28
  Archived:           12
  Pinned:             2
  Total Messages:     1,847
  Total Tokens:       452.3k

  By Channel:
    telegram: 35
    gateway: 5
    cli: 2

Web UI

The Web UI provides a visual interface for session management at the gateway root (hash router; sessions live under #/sessions).

Features

  1. Session List: Grid/list view with filtering
  2. Search: Real-time search across sessions
  3. Filters: Filter by status (All/Active/Pinned/Archived)
  4. Statistics: Visual stats cards
  5. Detail Drawer: Click any session to view:
    • Full message history
    • In-session search with highlighting
    • Archive/Pin/Export/Delete actions

Accessing the UI

bash
# Install and start the gateway OS service (or run foreground: xopc gateway)
xopc gateway service install
xopc gateway service start

# Open in browser
open http://localhost:18790/#/sessions

Session Structure

typescript
interface SessionMetadata {
  key: string;              // Unique identifier
  name?: string;            // Optional custom name
  status: 'active' | 'idle' | 'archived' | 'pinned';
  tags: string[];           // User-defined tags
  createdAt: string;        // ISO timestamp
  updatedAt: string;
  lastAccessedAt: string;
  messageCount: number;
  estimatedTokens: number;
  compactedCount: number;   // Number of compressions
  sourceChannel: string;    // telegram, gateway, cli
  sourceChatId: string;
}

interface SessionDetail extends SessionMetadata {
  messages: Message[];
}

interface Message {
  role: 'system' | 'user' | 'assistant' | 'tool' | 'toolResult';
  content: string;
  timestamp?: string;
  tool_call_id?: string;
  tool_calls?: ToolCall[];
  name?: string;
}

Automatic Maintenance

Compaction

When a session exceeds the context window limit:

  1. Early messages are summarized using LLM
  2. Recent messages are preserved (default: last 10)
  3. System messages are always kept

Configure in config.json:

json
{
  "agents": {
    "defaults": {
      "compaction": {
        "enabled": true,
        "mode": "abstractive",
        "triggerThreshold": 0.8,
        "keepRecentMessages": 10
      }
    }
  }
}

Compaction Modes:

  • extractive - Summarize using key sentences
  • abstractive - LLM-based summarization
  • structured - Preserve structured data

Sliding Window

To prevent memory issues:

  • Maximum messages: 100
  • Keeps recent messages when limit exceeded
  • Preserves system context

Best Practices

  1. Use Tags: Tag sessions by project or topic
  2. Pin Important Sessions: Keep frequently accessed sessions pinned
  3. Archive Old Sessions: Archive sessions you don't need regularly
  4. Regular Cleanup: Use session cleanup for old inactive sessions
  5. Export Before Delete: Export important sessions before deletion

Troubleshooting

Sessions Not Loading in Web UI

  1. Check gateway is running: xopc gateway status
  2. In the browser devtools Network tab, confirm REST calls to /api/sessions succeed and, if the UI uses live updates, that GET /api/events (SSE) stays connected
  3. Check for errors in gateway logs

Session store issues

Run deep integrity checks:

bash
xopc doctor --deep

This validates SQLite linkage between sessions and transcripts, scans for orphan transcripts, and runs PRAGMA integrity_check.

Missing sessions

If sessions were created but do not appear in the UI:

bash
xopc session list --limit 1000

Check gateway logs and confirm ~/.xopc/xopc.db exists and is writable.


API Reference

The gateway exposes sessions under /api/sessions (authenticated JSON over HTTP). There is no WebSocket surface for the console; live UI updates use SSE on GET /api/events where applicable.

Gateway HTTP routes (summary)

OperationHTTP
List / filter / searchGET /api/sessions (status, search, channel, limit, offset, …)
StatsGET /api/sessions/stats
Get sessionGET /api/sessions/:key
Update metadata (e.g. tags)PATCH /api/sessions/:key
Create sessionPOST /api/sessions
RenamePOST /api/sessions/:key/rename
Archive / unarchivePOST /api/sessions/:key/archive · POST /api/sessions/:key/unarchive
Pin / unpinPOST /api/sessions/:key/pin · POST /api/sessions/:key/unpin
ExportGET /api/sessions/:key/export
DeleteDELETE /api/sessions/:key
Reset (archive + new transcript id)POST /api/sessions/:key/reset

Search inside transcript text from the CLI: xopc session grep <sessionKey> <pattern>.

Released under the MIT License.