Appearance
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 --jsonopenclaw sessions cleanup 使用配置中的 session.maintenance 设置:
范围说明:
openclaw sessions cleanup仅维护 Session 存储/记录文件,不清理 Cron 运行日志(cron/runs/<jobId>.jsonl)——这些由 Cron 配置中的cron.runLog.maxBytes和cron.runLog.keepLines管理,详见 Cron 维护。--dry-run:预览将被剪切/截断的条目数,但不写入。文本模式下,干运行会打印每个 Session 的操作表(Action、Key、Age、Model、Flags),让你看到哪些会被保留、哪些会被删除。--enforce:即使session.maintenance.mode为warn,也强制应用维护。--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
}
]
}常见问题
Q: OpenClaw 怎么删除旧 Session?
A: 先运行 openclaw sessions cleanup --dry-run 看会删哪些记录,确认无误后再运行 openclaw sessions cleanup --enforce。如果你有多个 Agent,用 --all-agents 统一检查,或用 --agent <id> 只清理某个 Agent。
Q: cleanup 会不会删掉正在用的会话?
A: 可以用 --active-key <key> 保护当前活跃 Session。先用 openclaw sessions --json 查 key,再把它传给 cleanup。
Q: 为什么清理 Session 后 Cron 日志还在?
A: sessions cleanup 只维护 Session 存储,不清理 cron/runs/<jobId>.jsonl。Cron 运行日志要通过 Cron 配置里的 cron.runLog.maxBytes 和 cron.runLog.keepLines 控制。
相关文档:
- Session 配置:配置参考