Clean Worktree (Interactive)
Description
Interactive cleanup of worktrees: lists merged/stale branches and asks confirmation before deleting. **Difference with `/clean-worktrees`**: - `/clean-worktree`: Interactive, asks confirmation - `/cle
Installation
claude install-skill https://github.com/rtk-ai/rtk README
model: haiku description: Interactive cleanup of stale worktrees (merged branches, orphaned refs)
Clean Worktree (Interactive)
Interactive cleanup of worktrees: lists merged/stale branches and asks confirmation before deleting.
**Difference with `/clean-worktrees`**:
- undefined
Usage
/clean-worktree # Interactive audit + cleanup
Implementation
Execute this script:
#!/bin/bash
set -euo pipefail
echo "=== Worktrees Status ==="
git worktree list
echo ""
echo "=== Pruning stale references ==="
git worktree prune
echo ""
echo "=== Merged branches (safe to delete) ==="
MERGED_FOUND=false
CURRENT_DIR="$(pwd)"
while IFS= read -r line; do
path=$(echo "$line" | awk '{print $1}')
branch=$(echo "$line" | grep -oE '\[.*\]' | tr -d '[]' || true)
[ -z "$branch" ] && continue
[ "$branch" = "master" ] && continue
[ "$branch" = "main" ] && continue
[ "$path" = "$CURRENT_DIR" ] && continue
if git branch --merged master | grep -q "^[* ] ${branch}$" 2>/dev/null; then
echo " - $branch (at $path) - MERGED"
MERGED_FOUND=true
fi
done < <(git worktree list)
if [ "$MERGED_FOUND" = false ]; then
echo " (none found)"
echo ""
echo "=== Disk usage ==="
du -sh .worktrees/ 2>/dev/null || echo "No .worktrees directory"
exit 0
fi
echo ""
echo "=== Clean merged worktrees? [y/N] ==="
read -r confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
while IFS= read -r line; do
path=$(echo "$line" | awk '{print $1}')
branch=$(echo "$line" | grep -oE '\[.*\]' | tr -d '[]' || true)
[ -z "$branch" ] && continue
[ "$branch" = "master" ] && continue
[ "$branch" = "main" ] && continue
[ "$path" = "$CURRENT_DIR" ] && continue
if git branch --merged master | grep -q "^[* ] ${branch}$" 2>/dev/null; then
echo " Removing $branch..."
git worktree remove "$path" 2>/dev/null || rm -rf "$path"
git branch -d "$branch" 2>/dev/null || echo " (branch already deleted)"
echo " Done: $branch"
fi
done < <(git worktree list)
echo ""
echo "Cleanup complete."
else
echo "Aborted."
fi
echo ""
echo "=== Disk usage ==="
du -sh .worktrees/ 2>/dev/null || echo "No .worktrees directory"
Safety
- undefined
Manual Force Remove (unmerged branch)
git worktree remove --force .worktrees/feature-name
git branch -D feature/name
git worktree prune
Related Skills
next.js
| The React Framework | 138360 | 1503 | 1 |
Development community sharing-skills
skill for guidance.
Development community root-cause-tracing
Use when errors occur deep in execution and you need to trace back to find the original trigger.
Development community Template Skill
Minimal skeleton for a new skill project structure.
Development community Third-party Notices
THE FOLLOWING SETS FORTH ATTRIBUTION NOTICES FOR THIRD PARTY SOFTWARE THAT MAY BE CONTAINED IN PORTIONS OF THIS PRODUCT. ---
Development official Claude API
When code imports anthropic/@anthropic-ai/sdk/claude_agent_sdk, or user asks to use Claude APIBuild apps with the Claude API or Anthropic SDK
Development official Related Agents
Openai Codex CLI
(55.8k ⭐) - Lightweight coding agent that runs in your terminal.
Contributing to nanobot
Thank you for being here. nanobot is built with a simple belief: good tools should feel calm, clear, and humane. We care deeply about useful features, but we also believe in achieving more with less:
Key exports from each phase
for summary in .planning/phases/*/*-SUMMARY.md; do echo "=== $summary ===" grep -A 10 "Key Files\|Exports\|Provides" "$summary" 2>/dev/null done