ask
無料Route a codebase question to the right tool — structural graph, semantic search, or risk analysis. Use when you need to find or understand code without knowing exact file names.
日本語の概要は準備中です。原文の説明を表示しています。
Remove all git worktrees for merged branches. Accepts --dry-run to preview. Use after merging PRs or for weekly maintenance.
日本語の概要は準備中です。原文の説明を表示しています。
実行スコア 未検証
インストール方法を見るインストールする前に、エージェントに与えられる指示の中身を確認できます。
Automatically remove all worktrees for branches merged into the default branch (main or master). No interaction required.
/clean-worktrees # Remove all merged worktrees
/clean-worktrees --dry-run # Preview what would be deleted
Execute this script:
#!/bin/bash
set -euo pipefail
DRY_RUN=false
if [[ "${ARGUMENTS:-}" == *"--dry-run"* ]]; then
DRY_RUN=true
fi
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|.*/||' || \
git branch --list main master 2>/dev/null | head -1 | xargs || \
echo "main")
echo "Cleaning Worktrees"
echo "=================="
echo "Default branch: $DEFAULT_BRANCH"
echo ""
echo "1. Pruning stale git references..."
PRUNED=$(git worktree prune -v 2>&1)
[ -n "$PRUNED" ] && echo "$PRUNED" || echo "No stale references found"
echo ""
echo "2. Finding merged worktrees..."
MERGED_COUNT=0
MERGED_BRANCHES=()
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 "$DEFAULT_BRANCH" 2>/dev/null | grep -q "^[* ] ${branch}$"; then
MERGED_COUNT=$((MERGED_COUNT + 1))
MERGED_BRANCHES+=("$branch|$path")
echo " - $branch (merged)"
fi
done < <(git worktree list)
if [ $MERGED_COUNT -eq 0 ]; then
echo "No merged worktrees found"
git worktree list
exit 0
fi
echo "Found $MERGED_COUNT merged worktree(s)"
if [ "$DRY_RUN" = true ]; then
echo "DRY RUN — Would delete:"
for item in "${MERGED_BRANCHES[@]}"; do
branch=$(echo "$item" | cut -d'|' -f1)
path=$(echo "$item" | cut -d'|' -f2)
echo " - $branch ($path)"
done
echo "Run without --dry-run to actually delete"
exit 0
fi
echo "3. Removing merged worktrees..."
REMOVED_COUNT=0
for item in "${MERGED_BRANCHES[@]}"; do
branch=$(echo "$item" | cut -d'|' -f1)
path=$(echo "$item" | cut -d'|' -f2)
echo "Removing: $branch"
git worktree remove "$path" 2>/dev/null || { rm -rf "$path" 2>/dev/null; git worktree prune 2>/dev/null; }
git branch -d "$branch" 2>/dev/null || true
REMOVED_COUNT=$((REMOVED_COUNT + 1))
done
echo ""
echo "Removed: $REMOVED_COUNT worktree(s)"
git worktree list
main/mastergit symbolic-refmain or master/clean-worktrees --dry-run firstまだレビューはありません。使ってみた感想をお寄せください。
ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。
まだコメントはありません。最初のコメントを書いてみませんか。
Route a codebase question to the right tool — structural graph, semantic search, or risk analysis. Use when you need to find or understand code without knowing exact file names.
日本語の概要は準備中です。原文の説明を表示しています。
Auto-configure CLAUDE.md and claude/ knowledge docs for a new project. Use when setting up Brain Bootstrap in a new repository. Discovers the codebase, fills in templates, and writes project-specific configuration.
日本語の概要は準備中です。原文の説明を表示しています。
Use before any new feature, component, or behavioral change — when you need to explore requirements and design before writing code
日本語の概要は準備中です。原文の説明を表示しています。
Activate safety guards for the session. Use /careful before critical operations — blocks rm -rf, DROP TABLE, git push --force, kubectl delete namespace, docker system prune via PreToolUse hook.
日本語の概要は準備中です。原文の説明を表示しています。
Generate a user-facing changelog from git commits — categorize, filter noise, translate to user language. Runs in isolated fork context.
日本語の概要は準備中です。原文の説明を表示しています。
Save session state before context gets full or before ending. Writes current task state, branch, and loaded docs to claude/tasks/todo.md so the next session can resume cleanly.
日本語の概要は準備中です。原文の説明を表示しています。