openclaw sessions
列出存储的对话会话。
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 的会话发现范围更广:它们还会包含在默认 agents/ 根目录下或模板化 session.store 根目录下找到的仅存在于磁盘的存储。这些被发现的存储必须解析为 agent 根目录内的常规 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-5" }
]
}
清理维护
立即执行维护(不等下一次写入周期):
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 配置 中的cron.runLog.maxBytes和cron.runLog.keepLines管理,详情参见 Cron 维护。 -
--dry-run:预览有多少条目会被清理 / 截断,不实际写入。- 文本模式下,dry-run 会打印每个会话的操作表格(
Action、Key、Age、Model、Flags),让你看到哪些会保留、哪些会被移除。
- 文本模式下,dry-run 会打印每个会话的操作表格(
-
--enforce:即使session.maintenance.mode是warn也强制执行维护。 -
--active-key <key>:保护指定的活跃 key 不被磁盘预算驱逐。 -
--agent <id>:对指定的已配置 agent 存储执行清理。 -
--all-agents:对所有已配置的 agent 存储执行清理。 -
--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
}
]
}
相关内容: