← Back to Skills Marketplace
Cleanup Sessions
by
phenixMiao
· GitHub ↗
· v1.0.2
· MIT-0
144
Downloads
0
Stars
1
Active Installs
3
Versions
Install in OpenClaw
/install cleanup-sessions
Description
清理已中止且48小时未更新的子 agent 会话及过期备份文件,释放磁盘空间并同步更新索引文件。
README (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)
Usage Guidance
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.
Capability Analysis
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.
Capability Assessment
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.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install cleanup-sessions - After installation, invoke the skill by name or use
/cleanup-sessions - Provide required inputs per the skill's parameter spec and get structured output
Version History
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 天备份保留策略,避免误删
- 优化交互流程,删除前展示详细预览和统计信息
Metadata
Frequently Asked Questions
What is Cleanup Sessions?
清理已中止且48小时未更新的子 agent 会话及过期备份文件,释放磁盘空间并同步更新索引文件。 It is an AI Agent Skill for Claude Code / OpenClaw, with 144 downloads so far.
How do I install Cleanup Sessions?
Run "/install cleanup-sessions" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Cleanup Sessions free?
Yes, Cleanup Sessions is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Cleanup Sessions support?
Cleanup Sessions is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Cleanup Sessions?
It is built and maintained by phenixMiao (@phenixmiao); the current version is v1.0.2.
More Skills