Loading...
Loading...
Manage Claude Code resources - terminate orphaned processes and clean up ~/.opencode/ directory
npx skill4agent add benbrastmckie/nvim skill-refresh--dry-run--force# Parse from command input
dry_run=false
force=false
if [[ "$*" == *"--dry-run"* ]]; then
dry_run=true
fi
if [[ "$*" == *"--force"* ]]; then
force=true
fi.opencode/scripts/claude-refresh.sh $( [ "$force" = true ] && echo "--force" )echo ""
echo "=== Cleaning Orphaned Postflight Markers ==="
echo ""
# 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)
# 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."
fi
else
echo "No orphaned postflight markers found."
fi.opencode/scripts/claude-cleanup.sh--dry-runecho ""
echo "=== DRY RUN MODE ==="
echo "Showing 8-hour cleanup preview..."
echo ""
.opencode/scripts/claude-cleanup.sh --dry-run --age 8--forceecho ""
echo "=== EXECUTING CLEANUP (8-hour default) ==="
echo ""
.opencode/scripts/claude-cleanup.sh --force --age 8No cleanup candidates found within default thresholds.
All files are either protected or recently modified.{
"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)"
}
]
}--age 8--age 48--age 0case "$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# User runs: /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
# Prompt appears:
[Age Threshold]
Select cleanup age threshold:
1. 8 hours (default) - Remove files older than 8 hours
2. 2 days - Remove files older than 2 days
3. Clean slate - Remove everything except safety margin
# User selects option 1
# Cleanup executes:
Cleanup Complete
================
Deleted: 5577 files
Failed: 0 files
Space reclaimed: 6.7 GB
New total size: 600.0 MB# User runs: /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.# User runs: /refresh --force
# Shows survey, then immediately:
=== EXECUTING CLEANUP (8-hour default) ===
Cleanup Complete
================
Deleted: 5577 files
Space reclaimed: 6.7 GBsessions-index.jsonsettings.json.credentials.jsonhistory.jsonlError: Cleanup scripts not found at .opencode/scripts/
Please ensure claude-refresh.sh and claude-cleanup.sh are installed.Warning: Some operations failed due to insufficient permissions.
Failed files: 5
Successfully deleted: 5572 filesError: ~/.opencode/ directory not found.
Nothing to clean up.