跳转到内容

sessions

列出存储的对话会话。

Terminal window
openclaw sessions
openclaw sessions --agent work
openclaw sessions --all-agents
openclaw sessions --active 120
openclaw sessions --json

范围选择:

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

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

JSON 示例:

openclaw sessions --all-agents --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" }
]
}

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

Terminal window
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 仅维护会话存储/记录。它不会清理 cron 运行日志 (cron/runs/<jobId>.jsonl),这些日志由 Cron configuration 中的 cron.runLog.maxBytescron.runLog.keepLines 管理,并在 Cron maintenance 中进行解释。

  • --dry-run:预览将修剪/封顶的条目数量而不进行写入。

    • 在文本模式下,dry-run 会打印一个按会话列出的操作表 (Action, Key, Age, Model, Flags),以便您查看哪些内容会被保留,哪些会被移除。
  • --enforce:即使 session.maintenance.modewarn 时也应用维护。

  • --active-key <key>:保护特定的活动密钥不被磁盘预算驱逐。

  • --agent <id>: 为一个已配置的代理存储运行清理。

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

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

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

openclaw sessions cleanup --all-agents --dry-run --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
}
]
}

相关: