Install
openclaw skills install @chaobs/super-session-cleanupSession cleanup skill for Claw-family agents (OpenClaw, WorkBuddy, QClaw, etc.). This skill should be used when the user wants to track and clean up temporary files, scripts, installed skills, libraries, and software generated during a conversation session. Trigger phrases include: "开启清理追踪", "session cleanup", "会话清理", "清理垃圾文件", "清理对话文件", "清理临时文件", "结束清理", "列出临时文件", "清理 Skill", "卸载多余库", "clean up session", "cleanup now", "帮我清理".
openclaw skills install @chaobs/super-session-cleanupTrack and clean up all artifacts produced during a Claw-family agent session:
~/.workbuddy/skills/ or .workbuddy/skills/Trigger words (start tracking):
开启清理追踪 | 启动会话清理 | session cleanup start | track session files |
开始记录临时文件 | enable cleanup tracking
On activation:
<workspace>/.workbuddy/session-track.json with the following structure. If the file already exists from a previous interrupted session, load it and announce: "✅ 发现上一次会话的追踪记录,已恢复。"
{
"started_at": "ISO-8601 timestamp",
"workspace": "path/to/workspace",
"items": {
"temp_files": [],
"pip_packages": [],
"npm_packages": [],
"system_software": [],
"skills": [],
"other": []
},
"skip_list": []
}
session-track.json using replace_in_file or write_to_file. This ensures the tracking log survives token overflow, session resets, or unexpected interruptions. Do NOT announce each individual append.What to track — detection rules:
| Category | Detection signal |
|---|---|
| Temp files | write_to_file / execute_command that creates a file in a temp path (%TEMP%, /tmp, session scratch dirs, generated-images/), OR any file where the explanation contains keywords: "temporary", "demo", "test", "example", "scratch", "临时", "演示", "测试" |
| Pip packages | pip install, pip3 install, uv pip install |
| npm packages | npm install, npx ... --save |
| System software | winget install, choco install, apt install, brew install, scoop install |
| Skills | init_skill.py, use_skill, manually writing a new SKILL.md to a skills folder |
| Other | Any item the user explicitly asks to track |
Auto-tracking enforcement (critical — prevents missed items):
After EVERY tool call while tracking is active, perform a quick post-check on the tool call result. This is mandatory and must not be skipped:
write_to_file — Check if the filePath is in a temp/scratch/generated path OR if the explanation contains keywords: "temporary", "demo", "test", "example", "scratch", "临时", "演示", "测试". If yes → append to temp_files in session-track.json.
execute_command — Scan the command string for:
pip install / pip3 install / uv pip install → extract package name, append to pip_packagesnpm install / npm i → extract package name, append to npm_packageswinget install / choco install / apt install / brew install / scoop install → extract package name, append to system_software%TEMP%, /tmp, etc.) → append to temp_filesuse_skill or init_skill.py** — If a new skill is being installed or initialized, append the skill path to skills.
User's explicit instruction — If the user says "track this" / "记录这个" / "add to cleanup", append to other.
This post-check should be a silent, automatic step — do NOT announce it to the user. Simply update session-track.json in the background.
Trigger words (run cleanup):
清理垃圾文件 | 结束清理 | 清理对话文件 | cleanup now | clean session |
清理临时文件 | 会话清理 | 帮我清理 | 删除临时文件 | clean up
Cleanup workflow — follow these steps in order:
Read session-track.json from <workspace>/.workbuddy/. Print the full tracked list as a Markdown checklist grouped by category. Format each category array as a checklist. Example output:
## 本次会话产生的资源清单
### 🗂 临时文件
- [ ] C:\Users\<user>\AppData\Local\Temp\demo_script.py
- [x] C:\Users\<user>\AppData\Local\Temp\keep_this.py (保留)
- [ ] /path/to/workspace/generated-images/test.png
### 📦 安装的 Python 包
- [ ] requests==2.31.0
### 🧩 安装的 Skills
- [ ] ~/.workbuddy/skills/my-test-skill/
If the tracked list is empty (excluding skip_list items), say: "📭 本次会话未检测到可清理的资源。" and stop.
When classifying, check skip_list in session-track.json — any item in skip_list should be excluded from cleanup and shown as "保留" in the summary.
For each tracked item, classify it as either:
delete_file (workspace files) or execute_command (non-workspace files). This gives step-by-step visibility and is token-efficient for small lists.cleanup.py in two phases:
python "<skill_dir>/scripts/cleanup.py" --track-file "<workspace>/.workbuddy/session-track.json" --dry-runpython "<skill_dir>/scripts/cleanup.py" --track-file "<workspace>/.workbuddy/session-track.json"
This leverages the script's built-in safety checks, trash-first logic, and batch efficiency.cleanup.py regardless of item count.delete_file tool directly.%TEMP%, /tmp, home directory) → use execute_command with a trash-first strategy:
# Try Recycle Bin first (safe, reversible)
$shell = New-Object -ComObject Shell.Application
$item = $shell.NameSpace(0).ParseName('<file_path>')
$item.InvokeVerb('delete')
Remove-Item "<file_path>" -Forceosascript -e 'tell app "Finder" to delete POSIX file "<file_path>"'
Fallback: rm "<file_path>"gio trash "<file_path>" or trash-put "<file_path>"
Fallback: rm "<file_path>"%TEMP%, /tmp), hard-delete is acceptable since these are OS-managed scratch spaces. For all other paths, always prefer trash.For each Class B item, present a grouped confirmation prompt:
以下资源涉及依赖关系,需要您确认是否删除/卸载:
📦 Python 包:
• requests==2.31.0 → pip uninstall requests
🧩 Skills:
• ~/.workbuddy/skills/my-test-skill/ → 将永久删除
请回复:
全部删除 / 全部保留 / 逐一确认
For package uninstalls:
pip uninstall -y <package> via execute_commandnpm uninstall -g <package> via execute_commandwinget uninstall --id <id> via execute_commandchoco uninstall <package> -y via execute_commandbrew uninstall <formula> via execute_commandsudo apt remove -y <package> via execute_commandscoop uninstall <app> via execute_commandFor Skills uninstall:
execute_command:
Remove-Item -Path "<skill_dir>" -Recurse -Forcerm -rf "<skill_dir>"delete_file for skill directories as they are typically outside the workspace.For system_software uninstall:
winget, try winget list <name> first to find the exact ID before uninstalling.After cleanup is complete, print a summary:
✅ 会话清理完成
已删除临时文件: N 项
已卸载 Python 包: N 项
已删除 Skills: N 项
跳过/保留: N 项
Reset the in-memory session log and delete <workspace>/.workbuddy/session-track.json.
| Command | Action |
|---|---|
列出临时文件 / show session log | Print current tracked list from session-track.json without deleting |
清除记录 / clear log | Delete <workspace>/.workbuddy/session-track.json via delete_file and reset tracking state. Does NOT delete any actual files. Note: The safety rule "never delete .workbuddy/ folder" protects the directory itself, not transient session files within it — session-track.json is explicitly designed to be deleted by this command. |
手动添加 <path> / add to cleanup <path> | Append a path to the relevant array in session-track.json |
跳过 <path_or_name> / skip <path_or_name> | Add an item to skip_list in session-track.json, excluding it from future cleanup. Accepts partial matches (e.g. 跳过 demo_script.py matches the full path). Confirm to user: "✅ 已标记保留: " |
跳过 command detail:
When the user says 跳过 <X>:
session-track.json > items for entries containing <X> as a substring.skip_list, confirm to user.列出临时文件 to review.Items in skip_list are displayed with (保留) tag in the cleanup list and excluded from actual deletion/uninstall.
.workbuddy/ directory itself. Exception: session-track.json inside .workbuddy/ is a transient session file and may be deleted by the 清除记录 command or Step E cleanup.rm -rf or del /S /Q on home, desktop, downloads, or project roots.scripts/cleanup.py — Command-line cleanup utility; can be run directly to remove a list of paths.references/cleanup-guide.md — Full reference of uninstall commands by package manager and OS.track_init() shallow copy bug — nested items dict now uses copy.deepcopy() to prevent cross-session reference sharing (P2-6)uninstall_pip() / uninstall_npm() now pre-check whether the package is actually installed before attempting uninstall (P2-9)Path("/") resolving to \ on Windows, incorrectly flagging all paths as unsafeskip_list partial matching — added _is_skipped() helper for substring-based matchingsend_to_trash() silent hard-delete fallback — now requires allow_hard_delete=True (only set for temp paths)--workspace CLI argument for --manifest modeALLOWED_SUBDIRS list for workspace-aware safety checks (generated-images, node_modules)session-track.json(保留) skip marker in Step A example output--init, --add, --skip-add, --show, --dry-run