Skip to content

openclaw sessions

列出已存储的对话 Session。

bash
openclaw sessions
openclaw sessions --agent work
openclaw sessions --all-agents
openclaw sessions --active 120
openclaw sessions --json

范围选择:

  • 默认:已配置的默认 Agent 存储
  • --agent <id>:单个已配置的 Agent 存储
  • --all-agents:聚合所有已配置的 Agent 存储
  • --store <path>:显式指定存储路径(不能与 --agent--all-agents 组合使用)

openclaw sessions --all-agents 读取已配置的 Agent 存储。Gateway 和 ACP Session 发现范围更广:它们还包括在默认 agents/ 根目录或模板化 session.store 根目录下发现的纯磁盘存储。这些发现的存储必须解析到 Agent 根目录内的常规 sessions.json 文件;符号链接和根目录外的路径会被跳过。

JSON 示例:

openclaw sessions --all-agents --json

json
{
  "path": null,
  "stores": [
    { "agentId": "main", "path": "/home/user/.openclaw/agents/main/sessions/sessions.json" },
    { "agentId": "work", "path": "/home/user/.openclaw/agents/work/sessions/sessions.json" }
  ],
  "allAgents": true,
  "count": 2,
  "activeMinutes": null,
  "sessions": [
    { "agentId": "main", "key": "agent:main:main", "model": "gpt-5" },
    { "agentId": "work", "key": "agent:work:main", "model": "claude-opus-4-6" }
  ]
}

清理维护

立即运行维护(而不是等待下一个写入周期):

bash
openclaw sessions cleanup --dry-run
openclaw sessions cleanup --agent work --dry-run
openclaw sessions cleanup --all-agents --dry-run
openclaw sessions cleanup --enforce
openclaw sessions cleanup --enforce --active-key "agent:main:telegram:direct:123"
openclaw sessions cleanup --json

openclaw sessions cleanup 使用配置中的 session.maintenance 设置:

  • 范围说明:openclaw sessions cleanup 仅维护 Session 存储/记录文件,不清理 Cron 运行日志(cron/runs/<jobId>.jsonl)——这些由 Cron 配置中的 cron.runLog.maxBytescron.runLog.keepLines 管理,详见 Cron 维护

  • --dry-run:预览将被剪切/截断的条目数,但不写入。文本模式下,干运行会打印每个 Session 的操作表(ActionKeyAgeModelFlags),让你看到哪些会被保留、哪些会被删除。

  • --enforce:即使 session.maintenance.modewarn,也强制应用维护。

  • --active-key <key>:保护特定活跃键不被磁盘预算驱逐。

  • --agent <id>:对单个已配置的 Agent 存储运行清理。

  • --all-agents:对所有已配置的 Agent 存储运行清理。

  • --store <path>:针对指定的 sessions.json 文件运行。

  • --json:打印 JSON 摘要。使用 --all-agents 时,输出中每个存储包含一个摘要。

openclaw sessions cleanup --all-agents --dry-run --json

json
{
  "allAgents": true,
  "mode": "warn",
  "dryRun": true,
  "stores": [
    {
      "agentId": "main",
      "storePath": "/home/user/.openclaw/agents/main/sessions/sessions.json",
      "beforeCount": 120,
      "afterCount": 80,
      "pruned": 40,
      "capped": 0
    },
    {
      "agentId": "work",
      "storePath": "/home/user/.openclaw/agents/work/sessions/sessions.json",
      "beforeCount": 18,
      "afterCount": 18,
      "pruned": 0,
      "capped": 0
    }
  ]
}

相关文档: