Skill flagged — review recommended

ClawHub Security found sensitive or high-impact capabilities. Review the scan results before using.

OpenClaw Subagent Session Cleanup

v1.0.1

Clean up accumulated subagent and cron:run child sessions in OpenClaw to fix slow subagent startup. Use when: subagents are slow to start, sessions.json is t...

0· 80· 1 versions· 0 current· 0 all-time· Updated 1d ago· MIT-0

Install

openclaw skills install openclaw-subagent-session-cleanup

keywords:

  • session cleanup
  • subagent slow
  • sessions.json too large
  • child session accumulation
  • session compact
  • clean sessions
  • subagent startup slow
  • gateway slow
  • session too many
  • 清理 session
  • subagent 启动慢
  • sessions.json 太大

OpenClaw Session Cleanup

Background / 背景

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。


Steps / 操作步骤

Step 1: Stop Gateway

openclaw gateway stop

Step 2: Run cleanup script

.\cleanup.ps1             # 清理 sessions.json 索引(默认保留 .jsonl 文件)
.\cleanup.ps1 -DryRun     # 预览模式,不实际修改
.\cleanup.ps1 -KeepJsonl  # 保留 .jsonl history 文件(明确指定,不删)
.\cleanup.ps1 -CleanJsonl # 危险!同时删除 .jsonl 文件(对话历史会丢失)

Step 3: Restart Gateway

openclaw gateway

What is kept / 保留规则

Session typeExample keyAction
Main sessionagent:main:main✅ Keep
WhatsAppagent:main:whatsapp:direct:+1xxx✅ Keep
Telegramagent:main:telegram:direct:xxx✅ Keep
Signalagent:main:signal:direct:+1xxx✅ Keep
Google Chatagent:main:google chat:direct:xxx✅ Keep
Lineagent:main:line:direct:xxx✅ Keep
WeChatagent:main:wechat:direct:xxx✅ Keep
iMessage / SMSagent:main:imessage:direct:xxx✅ Keep
BlueBubbles (iOS)agent:main:bluebubbles:direct:xxx✅ Keep
其他 channel sessionagent:main:<channel>:...✅ Keep
Cron definitionagent:main:cron:uuid✅ Keep
Cron run recordagent:main:cron:uuid:run:uuid❌ Delete
Subagent sessionagent:main:subagent:uuid❌ Delete
其他 child sessionagent:main:<type>:...❌ Delete

⚠️ 关于 .jsonl 文件(对话历史)

默认不删除 .jsonl 文件。 .jsonl 包含完整的对话历史,删除后无法恢复。 如需清理 .jsonl,必须加 -CleanJsonl 参数:

.\cleanup.ps1 -CleanJsonl    # 清理 sessions.json 索引 + 删除 .jsonl 文件

Version tags

latestvk9704j3wtn38r8t9ft6gdfbb3184hana