清理OpenClaw中积累的子代理和cron:run子会话,以修复子代理启动缓慢的问题。使用时机:子代理启动缓慢,sessions.json文件过大。
keywords:
Every subagent call and cron job execution leaves an entry in sessions.json. After a few days of use, hundreds of entries accumulate, causing the gateway to slow down when starting new subagents.
Symptom: Subagent startup goes from a few seconds to 10+ seconds.
Root cause: Completed child session entries piling up in sessions.json.
Fix: Remove subagent and cron:run child session records, keep main and channel sessions.
每次 subagent 调用和 cron job 执行都会在 sessions.json 中留下记录。积累几百条后,gateway 启动 subagent 时明显变慢。
症状: subagent 启动时间从几秒变成十几秒甚至更长。 根因: sessions.json 中积累了大量已完成的 child session 索引。 解法: 删除 subagent 和 cron:run 类型的 child session 记录,保留主 session 和 channel session。
powershell
openclaw gateway stop
powershell
.\cleanup.ps1 # 清理 sessions.json 索引(默认保留 .jsonl 文件)
.\cleanup.ps1 -DryRun # 预览模式,不实际修改
.\cleanup.ps1 -KeepJsonl # 保留 .jsonl history 文件(明确指定,不删)
.\cleanup.ps1 -CleanJsonl # 危险!同时删除 .jsonl 文件(对话历史会丢失)
powershell
openclaw gateway
Session typeExample keyActionMain sessionagent:main:main✅ KeepWhatsAppagent:main:whatsapp:direct:+1xxx✅ KeepTelegramagent:main:telegram:direct:xxx✅ KeepSignalagent:main:signal:direct:+1xxx✅ KeepGoogle Chatagent:main:google chat:direct:xxx✅ KeepLineagent:main:line:direct:xxx✅ KeepWeChatagent:main:wechat:direct:xxx✅ KeepiMessage / SMSagent:main:imessage:direct:xxx✅ KeepBlueBubbles (iOS)agent:main:bluebubbles:direct:xxx✅ Keep其他 channel sessionagent:main:<channel>:...✅ KeepCron definitionagent:main:cron:uuid✅ KeepCron run recordagent:main:cron:uuid:run:uuid❌ DeleteSubagent sessionagent:main:subagent:uuid❌ Delete其他 child sessionagent:main:<type>:...❌ Delete
默认不删除 .jsonl 文件。 .jsonl 包含完整的对话历史,删除后无法恢复。
如需清理 .jsonl,必须加 -CleanJsonl 参数:
powershell
.\cleanup.ps1 -CleanJsonl # 清理 sessions.json 索引 + 删除 .jsonl 文件