← ClaudeAtlas

git-worktreelisted

Lists linked worktrees with PR state and cleans up merged ones. Use when asked to "list worktrees", "clean up worktrees", or after shipping a PR to reclaim slots. Do NOT use to enter a worktree from scratch (use `claude-worktree`).
erclx/toolkit · ★ 1 · Code & Development · score 74
Install: claude install-skill erclx/toolkit
# Git worktree See `wiki/claude-worktrees.md` for worktree semantics and the "Shipping from worktrees" workflow. For entry, use `claude-worktree`. ## Mode selection Pick exactly one mode from the user's request: - `list`: show every worktree with its branch, PR state, and dirtiness ("list worktrees", "what worktrees do I have") - `cleanup`: remove worktrees whose branches are merged, then prune local branches ("clean up worktrees", "reclaim worktree slots") ## Context Run in parallel: - `git rev-parse --git-dir 2>/dev/null || echo "NO_REPO"` - `git rev-parse --git-common-dir 2>/dev/null || echo "NO_REPO"` - `git worktree list --porcelain 2>/dev/null || echo "NO_REPO"` - `git fetch --prune origin 2>/dev/null || echo "NO_REMOTE"` Resolve `MAIN_ROOT` from the first `worktree` line of `git worktree list --porcelain`. ## Guards - If either `git-dir` command returned `NO_REPO`, stop: `❌ Not a git repository.` ## Enumeration (list and cleanup) Parse `git worktree list --porcelain` into rows. Each row has `path`, `branch`, `head`. Skip the `bare` row if present. For each row, determine merge state of its branch: 1. Skip the main-root row. Mark it `main` with no PR lookup. 2. Try `gh pr view <branch> --json state,number,url 2>/dev/null`: - `MERGED`: state is `merged`, record PR number and URL. - `OPEN`: state is `open`, record PR number and URL. - `CLOSED`: state is `closed` (not merged), record PR number. - Command fails or returns no PR: fall through. 3. Fa