skill-refresh
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRefresh Skill (Direct Execution)
刷新Skill(直接执行)
Direct execution skill for managing Claude Code resources. Performs two operations:
- Process cleanup: Identify and terminate orphaned Claude Code processes
- Directory cleanup: Clean up accumulated files in ~/.opencode/
This skill executes inline without spawning a subagent.
用于管理Claude Code资源的直接执行Skill。执行两项操作:
- 进程清理:识别并终止孤立的Claude Code进程
- 目录清理:清理~/.opencode/中累积的文件
该Skill直接内联执行,不会生成子Agent。
Execution
执行步骤
Step 1: Parse Arguments
步骤1:解析参数
Extract flags from command input:
- : Preview mode
--dry-run - : Skip confirmation, use 8-hour default
--force
bash
undefined从命令输入中提取标志:
- :预览模式
--dry-run - :跳过确认,使用8小时默认值
--force
bash
undefinedParse from command input
Parse from command input
dry_run=false
force=false
if [[ "$" == "--dry-run" ]]; then
dry_run=true
fi
if [[ "$" == "--force" ]]; then
force=true
fi
undefineddry_run=false
force=false
if [[ "$" == "--dry-run" ]]; then
dry_run=true
fi
if [[ "$" == "--force" ]]; then
force=true
fi
undefinedStep 2: Run Process Cleanup
步骤2:执行进程清理
Execute process cleanup script:
bash
.opencode/scripts/claude-refresh.sh $( [ "$force" = true ] && echo "--force" )Store process cleanup output for display.
执行进程清理脚本:
bash
.opencode/scripts/claude-refresh.sh $( [ "$force" = true ] && echo "--force" )保存进程清理输出以便展示。
Step 3: Clean Orphaned Postflight Markers
步骤3:清理孤立的Postflight标记
Clean any orphaned postflight coordination files from the specs directory. These files should normally be cleaned up by skills after postflight completes, but may be left behind if a process is interrupted.
bash
echo ""
echo "=== Cleaning Orphaned Postflight Markers ==="
echo ""清理specs目录中任何孤立的Postflight协调文件。这些文件通常会在Postflight完成后由Skill清理,但如果进程被中断可能会残留。
bash
echo ""
echo "=== Cleaning Orphaned Postflight Markers ==="
echo ""Find orphaned postflight markers (older than 1 hour)
Find orphaned postflight markers (older than 1 hour)
orphaned_pending=$(find specs -maxdepth 3 -name ".postflight-pending" -mmin +60 -type f 2>/dev/null)
orphaned_guard=$(find specs -maxdepth 3 -name ".postflight-loop-guard" -mmin +60 -type f 2>/dev/null)
orphaned_pending=$(find specs -maxdepth 3 -name ".postflight-pending" -mmin +60 -type f 2>/dev/null)
orphaned_guard=$(find specs -maxdepth 3 -name ".postflight-loop-guard" -mmin +60 -type f 2>/dev/null)
Also check for legacy global markers
Also check for legacy global markers
legacy_pending=""
legacy_guard=""
if [ -f "specs/.postflight-pending" ]; then
legacy_pending="specs/.postflight-pending"
fi
if [ -f "specs/.postflight-loop-guard" ]; then
legacy_guard="specs/.postflight-loop-guard"
fi
if [ -n "$orphaned_pending" ] || [ -n "$orphaned_guard" ] || [ -n "$legacy_pending" ] || [ -n "$legacy_guard" ]; then
if [ "$dry_run" = true ]; then
echo "Would delete the following orphaned markers:"
[ -n "$orphaned_pending" ] && echo "$orphaned_pending"
[ -n "$orphaned_guard" ] && echo "$orphaned_guard"
[ -n "$legacy_pending" ] && echo "$legacy_pending"
[ -n "$legacy_guard" ] && echo "$legacy_guard"
else
# Delete orphaned task-scoped markers
find specs -maxdepth 3 -name ".postflight-pending" -mmin +60 -delete 2>/dev/null
find specs -maxdepth 3 -name ".postflight-loop-guard" -mmin +60 -delete 2>/dev/null
# Delete legacy global markers
rm -f specs/.postflight-pending 2>/dev/null
rm -f specs/.postflight-loop-guard 2>/dev/null
echo "Cleaned orphaned postflight markers."
fielse
echo "No orphaned postflight markers found."
fi
undefinedlegacy_pending=""
legacy_guard=""
if [ -f "specs/.postflight-pending" ]; then
legacy_pending="specs/.postflight-pending"
fi
if [ -f "specs/.postflight-loop-guard" ]; then
legacy_guard="specs/.postflight-loop-guard"
fi
if [ -n "$orphaned_pending" ] || [ -n "$orphaned_guard" ] || [ -n "$legacy_pending" ] || [ -n "$legacy_guard" ]; then
if [ "$dry_run" = true ]; then
echo "Would delete the following orphaned markers:"
[ -n "$orphaned_pending" ] && echo "$orphaned_pending"
[ -n "$orphaned_guard" ] && echo "$orphaned_guard"
[ -n "$legacy_pending" ] && echo "$legacy_pending"
[ -n "$legacy_guard" ] && echo "$legacy_guard"
else
# Delete orphaned task-scoped markers
find specs -maxdepth 3 -name ".postflight-pending" -mmin +60 -delete 2>/dev/null
find specs -maxdepth 3 -name ".postflight-loop-guard" -mmin +60 -delete 2>/dev/null
# Delete legacy global markers
rm -f specs/.postflight-pending 2>/dev/null
rm -f specs/.postflight-loop-guard 2>/dev/null
echo "Cleaned orphaned postflight markers."
fielse
echo "No orphaned postflight markers found."
fi
undefinedStep 4: Run Directory Survey
步骤4:运行目录调查
Show current directory status without cleaning yet:
bash
.opencode/scripts/claude-cleanup.shThis displays:
- Current ~/.opencode/ directory size
- Breakdown by directory
- Space that can be reclaimed
先显示当前目录状态,暂不清理:
bash
.opencode/scripts/claude-cleanup.sh该命令会显示:
- 当前~/.opencode/目录大小
- 按目录细分的占用情况
- 可回收的空间
Step 5: Execute Based on Mode
步骤5:根据模式执行
Dry-Run Mode
预览模式(Dry-Run)
If is set:
--dry-runbash
echo ""
echo "=== DRY RUN MODE ==="
echo "Showing 8-hour cleanup preview..."
echo ""
.opencode/scripts/claude-cleanup.sh --dry-run --age 8Exit after showing preview.
如果设置了:
--dry-runbash
echo ""
echo "=== DRY RUN MODE ==="
echo "Showing 8-hour cleanup preview..."
echo ""
.opencode/scripts/claude-cleanup.sh --dry-run --age 8显示预览后退出。
Force Mode
强制模式(Force)
If is set:
--forcebash
echo ""
echo "=== EXECUTING CLEANUP (8-hour default) ==="
echo ""
.opencode/scripts/claude-cleanup.sh --force --age 8Show results and exit.
如果设置了:
--forcebash
echo ""
echo "=== EXECUTING CLEANUP (8-hour default) ==="
echo ""
.opencode/scripts/claude-cleanup.sh --force --age 8显示结果后退出。
Interactive Mode (Default)
交互式模式(默认)
If neither flag is set:
-
Check if cleanup candidates exist (claude-cleanup.sh exits with code 1 if candidates found)
-
If no candidates, display message and exit:
No cleanup candidates found within default thresholds.
All files are either protected or recently modified.- If candidates exist, prompt user for age selection:
json
{
"question": "Select cleanup age threshold:",
"header": "Age Threshold",
"multiSelect": false,
"options": [
{
"label": "8 hours (default)",
"description": "Remove files older than 8 hours - aggressive cleanup"
},
{
"label": "2 days",
"description": "Remove files older than 2 days - conservative cleanup"
},
{
"label": "Clean slate",
"description": "Remove everything except safety margin (1 hour)"
}
]
}-
Map user selection to age parameter:
- "8 hours (default)" →
--age 8 - "2 days" →
--age 48 - "Clean slate" →
--age 0
- "8 hours (default)" →
-
Execute cleanup with selected age:
bash
case "$selection" in
"8 hours (default)")
.opencode/scripts/claude-cleanup.sh --force --age 8
;;
"2 days")
.opencode/scripts/claude-cleanup.sh --force --age 48
;;
"Clean slate")
.opencode/scripts/claude-cleanup.sh --force --age 0
;;
esac- Display cleanup results
如果未设置任何标志:
-
检查是否存在清理候选文件(如果找到候选文件,claude-cleanup.sh会以代码1退出)
-
如果没有候选文件,显示消息并退出:
在默认阈值内未找到清理候选文件。
所有文件要么受保护,要么是最近修改的。- 如果存在候选文件,提示用户选择年龄阈值:
json
{
"question": "选择清理年龄阈值:",
"header": "年龄阈值",
"multiSelect": false,
"options": [
{
"label": "8小时(默认)",
"description": "删除超过8小时的文件 - 激进清理"
},
{
"label": "2天",
"description": "删除超过2天的文件 - 保守清理"
},
{
"label": "完全清理",
"description": "除安全余量(1小时)外全部删除"
}
]
}-
将用户选择映射到年龄参数:
- "8小时(默认)" →
--age 8 - "2天" →
--age 48 - "完全清理" →
--age 0
- "8小时(默认)" →
-
使用选定的年龄执行清理:
bash
case "$selection" in
"8小时(默认)")
.opencode/scripts/claude-cleanup.sh --force --age 8
;;
"2天")
.opencode/scripts/claude-cleanup.sh --force --age 48
;;
"完全清理")
.opencode/scripts/claude-cleanup.sh --force --age 0
;;
esac- 显示清理结果
Example Execution Flows
示例执行流程
Interactive Flow
交互式流程
bash
undefinedbash
undefinedUser runs: /refresh
用户运行:/refresh
Output:
输出:
Claude Code Refresh
No orphaned processes found.
All 3 Claude processes are active sessions.
Claude Code Directory Cleanup
Target: ~/.opencode/
Current total size: 7.3 GB
Scanning directories...
Directory Total Cleanable Files
projects/ 7.0 GB 6.5 GB 980
debug/ 151.0 MB 140.0 MB 650
...
TOTAL 7.3 GB 6.7 GB 5577
Space that can be reclaimed: 6.7 GB
Claude Code 刷新
未找到孤立进程。
所有3个Claude进程均为活跃会话。
Claude Code 目录清理
目标:~/.opencode/
当前总大小:7.3 GB
正在扫描目录...
目录 总量 可清理量 文件数
projects/ 7.0 GB 6.5 GB 980
debug/ 151.0 MB 140.0 MB 650
...
总计 7.3 GB 6.7 GB 5577
可回收空间:6.7 GB
Prompt appears:
提示出现:
[Age Threshold]
Select cleanup age threshold:
- 8 hours (default) - Remove files older than 8 hours
- 2 days - Remove files older than 2 days
- Clean slate - Remove everything except safety margin
[年龄阈值]
选择清理年龄阈值:
- 8小时(默认) - 删除超过8小时的文件
- 2天 - 删除超过2天的文件
- 完全清理 - 除安全余量外全部删除
User selects option 1
用户选择选项1
Cleanup executes:
清理执行:
Cleanup Complete
Deleted: 5577 files
Failed: 0 files
Space reclaimed: 6.7 GB
New total size: 600.0 MB
undefined清理完成
已删除:5577个文件
失败: 0个文件
回收空间:6.7 GB
新总大小:600.0 MB
undefinedDry-Run Flow
预览流程
bash
undefinedbash
undefinedUser runs: /refresh --dry-run
用户运行:/refresh --dry-run
Shows survey, then:
显示调查结果,然后:
=== DRY RUN MODE ===
Showing 8-hour cleanup preview...
Would delete: 5577 files
Would reclaim: 6.7 GB
Dry Run Summary
No changes made.
undefined=== 预览模式 ===
显示8小时清理预览...
将删除:5577个文件
将回收:6.7 GB
预览总结
未进行任何更改。
undefinedForce Flow
强制流程
bash
undefinedbash
undefinedUser runs: /refresh --force
用户运行:/refresh --force
Shows survey, then immediately:
显示调查结果,然后立即执行:
=== EXECUTING CLEANUP (8-hour default) ===
Cleanup Complete
Deleted: 5577 files
Space reclaimed: 6.7 GB
---=== 执行清理(默认8小时) ===
清理完成
已删除:5577个文件
回收空间:6.7 GB
---Safety Measures
安全措施
Protected Files (Never Deleted)
受保护文件(永不删除)
- (in each project directory)
sessions-index.json settings.json.credentials.jsonhistory.jsonl
- (每个项目目录中)
sessions-index.json settings.json.credentials.jsonhistory.jsonl
Safety Margin
安全余量
Files modified within the last hour are never deleted, regardless of age threshold.
最近1小时内修改的文件永不删除,无论年龄阈值如何。
Process Safety
进程安全
- Only targets orphaned processes (TTY = "?")
- Never kills active sessions
- Excludes current process tree
- 仅针对孤立进程(TTY = "?")
- 绝不终止活跃会话
- 排除当前进程树
Error Handling
错误处理
Scripts Not Found
未找到脚本
If scripts don't exist:
Error: Cleanup scripts not found at .opencode/scripts/
Please ensure claude-refresh.sh and claude-cleanup.sh are installed.如果脚本不存在:
错误:未在.opencode/scripts/找到清理脚本
请确保已安装claude-refresh.sh和claude-cleanup.sh。Permission Denied
权限拒绝
If kill/delete fails due to permissions:
Warning: Some operations failed due to insufficient permissions.
Failed files: 5
Successfully deleted: 5572 files如果因权限不足导致终止/删除失败:
警告:部分操作因权限不足失败。
失败文件数:5
成功删除:5572个文件No ~/.opencode/ Directory
未找到~/.opencode/目录
If directory doesn't exist:
Error: ~/.opencode/ directory not found.
Nothing to clean up.如果目录不存在:
错误:未找到~/.opencode/目录。
无内容可清理。