Files
architecture/skills/worktrees/scripts/cleanup-worktrees.sh
Hugo Nijhuis 03a665503c feat: add parallel issue implementation capability with worktrees
Add complete capability set for orchestrating parallel issue implementation
with automated review cycles using git worktrees.

Components:
- worktrees skill: Git worktree patterns + bundled scripts for reliable operations
- spawn-issues skill: Event-driven orchestrator (Haiku) for parallel workflow
- issue-worker agent: Implements issues autonomously (Sonnet)
- code-reviewer agent: Reviews PRs with quality checks (Haiku, read-only)
- pr-fixer agent: Addresses review feedback automatically (Haiku)

Workflow: /spawn-issues creates worktrees → spawns workers → reviews PRs →
fixes feedback → iterates until approved → cleans up worktrees

Scripts handle error-prone worktree operations. Orchestrator uses event-driven
approach with task notifications for efficient parallel execution.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-01-12 15:51:10 +01:00

57 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Clean up git worktrees
#
# Usage:
# ./cleanup-worktrees.sh <path> # Remove specific worktree
# ./cleanup-worktrees.sh <directory> # Remove all worktrees in directory
# ./cleanup-worktrees.sh --force <path> # Force remove even if dirty
FORCE=false
if [ "$1" = "--force" ]; then
FORCE=true
shift
fi
TARGET="$1"
REPO_PATH=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
cd "$REPO_PATH"
remove_worktree() {
local worktree_path="$1"
if [ ! -d "$worktree_path" ]; then
return 0
fi
if [ "$FORCE" = true ]; then
git worktree remove "$worktree_path" --force 2>/dev/null || true
else
git worktree remove "$worktree_path" 2>/dev/null || true
fi
}
# Check if target is a directory containing multiple worktrees
if [ -d "$TARGET" ]; then
# Check if it's a worktree itself or a directory of worktrees
if git worktree list | grep -q "$TARGET\$"; then
# It's a single worktree
remove_worktree "$TARGET"
else
# It's a directory, remove all worktrees inside
for worktree in "$TARGET"/*; do
if [ -d "$worktree" ]; then
remove_worktree "$worktree"
fi
done
# Try to remove the directory if empty
rmdir "$TARGET" 2>/dev/null || true
fi
else
echo "Error: Path does not exist: $TARGET" >&2
exit 1
fi