← 返回 Skills 市场
Cleanup Sessions
作者
phenixMiao
· GitHub ↗
· v1.0.2
· MIT-0
144
总下载
0
收藏
1
当前安装
3
版本数
在 OpenClaw 中安装
/install cleanup-sessions
功能描述
清理已中止且48小时未更新的子 agent 会话及过期备份文件,释放磁盘空间并同步更新索引文件。
使用说明 (SKILL.md)
cleanup-sessions
清理已中止的子 agent 会话文件及备份文件,释放磁盘空间。
触发条件
用户提到:
- 清理子 agent 会话
- 删除 aborted 的会话
- 清理会话文件
- 清理 sessions 目录
- 清理备份文件
- 清理 .deleted / .reset 文件
- 清理过期会话
功能
- 预览模式:列出所有
abortedLastRun: true的会话文件,显示大小和路径 - 清理模式:删除已确认的废弃会话文件
- 同步清理:同时清理
sessions.json索引中的对应条目 - 备份清理:清理
.jsonl.deleted.*和.jsonl.reset.*备份文件
使用方式
直接清理(用户明确同意时)
// 1. 列出所有会话
const sessions = await sessions_list();
// 2. 过滤出 aborted 的子 agent 会话
const abortedSessions = sessions.sessions.filter(s =>
s.kind === 'other' &&
s.key.includes('subagent') &&
s.abortedLastRun === true
);
// 3. 提取会话 ID 并删除对应文件
for (const session of abortedSessions) {
const sessionId = session.sessionId;
const filePath = `/Users/miaofengkai115572/.openclaw/agents/main/sessions/${sessionId}.jsonl`;
// 执行删除
}
完整清理流程
A. 清理已中止的子 agent 会话
- 调用
sessions_list()获取会话列表 - 过滤出
abortedLastRun: true且key包含subagent的会话 - 保护近期会话:排除 48 小时内更新的会话(
updatedAt > Date.now() - 48*60*60*1000) - 向用户展示待删除的文件列表(路径 + 大小 + 最后更新时间)
- 用户确认后执行删除
.jsonl文件 - 同步清理
sessions.json中的对应条目
B. 清理备份文件
- 扫描
*.jsonl.deleted.*文件(删除备份) - 扫描
*.jsonl.reset.*文件(重置备份,保留 7 天内) - 展示待删除的备份文件数量和总大小
- 用户确认后执行删除
清理策略:
.deleted文件:全部删除(会话已删,备份无用).reset文件:删除 7 天前的(保留近期备份)- 保护期:48 小时内的会话不删除(即使
abortedLastRun: true)
注意事项
- 只删除子 agent 会话:
key包含subagent的会话 - 只删除已中止的:
abortedLastRun === true - 保留主会话:不要删除用户正在使用的会话
- 48 小时保护:不删除 48 小时内更新的会话(即使已中止)
- 建议先预览:删除前展示文件列表和总大小
- 同步清理 sessions.json:删除 .jsonl 后必须清理索引文件,否则数据不一致
- 备份文件说明:
.jsonl.deleted.*→ 会话删除前的备份,可安全删除.jsonl.reset.*→ 会话重置/压缩前的备份,建议保留 7 天
- 定期清理:建议每周清理一次备份文件,避免占用过多磁盘空间
相关文件
- 会话目录:
~/.openclaw/agents/main/sessions/*.jsonl - 会话元数据:通过
sessions_list()获取
示例输出
A. 子 agent 会话清理
找到 2 个可清理的已中止子 agent 会话:
| 会话 ID | 大小 | 标签 | 最后更新 |
|---------|------|------|----------|
| 46bf8f99-... | 76K | feishu-creator | 7 天前 |
| a5348a20-... | 149K | feishu-doc-creator | 7 天前 |
已保护:1 个会话(48 小时内更新)
总计可释放:225KB
确认删除?
B. 备份文件清理
扫描备份文件:
| 类型 | 文件数 | 总大小 |
|------|--------|--------|
| .deleted | 18 | 2.1 MB |
| .reset (7 天前) | 12 | 4.1 GB |
总计可释放:4.1 GB
确认删除?
技术实现
核心工具
sessions_list()- 获取会话列表和状态- Node.js
fs模块 - 删除会话文件 sessions.json同步更新 - 保持索引一致性
伪代码示例
// 获取会话列表
const sessions = await sessions_list();
// 过滤条件
const shouldDelete = sessions.filter(s =>
s.key.includes('subagent') &&
s.abortedLastRun === true &&
Date.now() - s.updatedAt > 48 * 60 * 60 * 1000 // 48 小时保护
);
// 用户确认后删除文件并更新索引
扩展建议
- 添加
--dry-run模式(预览不删除) - 添加按时间过滤(只清理 N 天前的)
- 添加按大小过滤(只清理大于 X 的)
- 定期自动清理(结合 heartbeat)
安全使用建议
This skill appears coherent for its stated purpose, but it deletes files — take these precautions before installing or running it: 1) Always run the preview/dry-run first and carefully review the listed file paths, sizes, and timestamps. 2) Back up sessions.json (and any important .jsonl files) before performing deletions. 3) Confirm the skill resolves the current user's home directory (do not use code with hard-coded usernames). 4) Prefer running as the same non-root user owning the OpenClaw files to avoid accidental system-wide deletions. 5) Ask for or inspect the actual implementation used at runtime to ensure protections against symlink/path-traversal and that deletions only target files under the intended sessions directory. 6) If you need higher assurance, request that the author provide a --dry-run script and an explicit confirmation prompt implementation, or run the cleanup commands manually after previewing the list.
功能分析
Type: OpenClaw Skill
Name: cleanup-sessions
Version: 1.0.2
The skill is designed to perform destructive file deletions to free up disk space. While it includes safety logic such as a 48-hour protection window and user confirmation steps, it contains a hardcoded absolute path to a specific user's home directory (/Users/miaofengkai115572/) in SKILL.md, which is a significant portability flaw and potential vulnerability. Furthermore, the README.md references an external shell script (cleanup.sh) that is not included in the provided bundle, making the full execution logic unverifiable.
能力评估
Purpose & Capability
The name/description match the SKILL.md and README: the skill enumerates sessions via sessions_list(), filters aborted subagent sessions, deletes .jsonl files and backup files, and updates sessions.json. There are no extraneous environment variables, binaries, or install steps requested that would be inconsistent with a local cleanup tool.
Instruction Scope
Instructions are focused on listing and deleting files under ~/.openclaw/agents/main/sessions and syncing sessions.json, which is appropriate. Notes of caution: example code contains a hard-coded user path (/Users/miaofengkai115572/...) — ensure implementations resolve the current user home dynamically. The SKILL.md relies on sessions_list() and Node fs operations; it does not instruct contacting external endpoints. The instructions assume a direct mapping from sessionId → filename and require correct filtering (key includes 'subagent' and abortedLastRun === true). Implementation-level safety checks (e.g., avoid following symlinks, validate file ownership, double-check path joins to prevent traversal) are not specified, so users should insist on a dry-run preview before deletion.
Install Mechanism
No install spec and no code files that would be executed were provided (instruction-only). This minimizes install-time risk (nothing to download or write to disk by the skill itself).
Credentials
The skill requests no environment variables, no credentials, and no config paths beyond user-local OpenClaw session directories, which is proportionate for a local cleanup utility.
Persistence & Privilege
The skill is not always-enabled and does not request persistent elevated privileges. It will run only when invoked and its scope is limited to the sessions directory and sessions.json index as documented.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install cleanup-sessions - 安装完成后,直接呼叫该 Skill 的名称或使用
/cleanup-sessions触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
- Removed the cleanup.sh file.
- Now relies on internal logic and instructions documented in SKILL.md for cleanup tasks.
v1.0.1
- Added a new "技术实现" section describing core tools and pseudocode usage.
- Improved documentation structure for better clarity and usability.
- No functional or logic changes; update is documentation only.
v1.0.0
cleanup-sessions 1.0.0 – 首个版本,支持子 agent 会话及备份文件清理。
- 新增预览模式:可列出所有已中止的子 agent 会话文件,显示路径和大小
- 新增清理模式:支持一键删除已确认的废弃会话文件及对应索引
- 支持同步清理 sessions.json 元数据及 .deleted/.reset 会话备份文件
- 提供 48 小时保护期及 7 天备份保留策略,避免误删
- 优化交互流程,删除前展示详细预览和统计信息
元数据
常见问题
Cleanup Sessions 是什么?
清理已中止且48小时未更新的子 agent 会话及过期备份文件,释放磁盘空间并同步更新索引文件。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 144 次。
如何安装 Cleanup Sessions?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install cleanup-sessions」即可一键安装,无需额外配置。
Cleanup Sessions 是免费的吗?
是的,Cleanup Sessions 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Cleanup Sessions 支持哪些平台?
Cleanup Sessions 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Cleanup Sessions?
由 phenixMiao(@phenixmiao)开发并维护,当前版本 v1.0.2。
推荐 Skills