/clean-worktree
Interactive cleanup of stale worktrees (merged branches, orphaned refs)
$ npx -y skills add rtk-ai/rtk --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/clean-worktree
Context preview
What this command does when you run it.
Interactive cleanup of stale worktrees (merged branches, orphaned refs)
Command definition
clean-worktree.mdmodel: 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`**:
- `/clean-worktree`: Interactive, asks confirmation
- `/clean-worktrees`: Automatic, no interaction
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
- Never removes `master` or `main` worktrees
- Only removes branches merged into `master`
- Asks confirmation before any deletion
- Cleans both git reference and physical directory
Manual Force Remove (unmerged branch)
git worktree remove --force .worktrees/feature-name
git branch -D feature/name
git worktree prune
Read more
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`**:
- `/clean-worktree`: Interactive, asks confirmation
- `/clean-worktrees`: Automatic, no interaction
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
- Never removes `master` or `main` worktrees
- Only removes branches merged into `master`
- Asks confirmation before any deletion
- Cleans both git reference and physical directory
Manual Force Remove (unmerged branch)
git worktree remove --force .worktrees/feature-name git branch -D feature/name git worktree prune
CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies
Repo: rtk-ai/rtk
Other commands on rtk.
- /clean-worktrees
Clean all merged worktrees automatically (no interaction)
Open command - /diagnose
RTK environment diagnostics - Checks installation, hooks, version, command routing
Open command - /audit-codebase
RTK Codebase Health Audit β 7 catΓ©gories scorΓ©es 0-10
Open command - /codereview
RTK Code Review β Review locale pre-PR avec auto-fix
Open command - /remove-worktree
Remove a specific worktree (directory + git reference + branch)
Open command - /worktree-status
Check background cargo check status for a git worktree
Open command

