plugins/superpowers-bd/skills/using-git-worktrees/SKILL.md
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
npx skillsauth add schlenks/superpowers-bd using-git-worktreesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Before creating anything, check if you are already in an isolated workspace.
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)
Submodule guard: GIT_DIR != GIT_COMMON is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
# If this returns a path, you're in a submodule, not a worktree — treat as normal repo
git rev-parse --show-superproject-working-tree 2>/dev/null
If GIT_DIR != GIT_COMMON (and not a submodule): You are already in a linked worktree. Skip to Step 3 (Project Setup) below. Do NOT create another worktree.
Report with branch state:
<path> on branch <name>."<path> (detached HEAD, externally managed). Branch creation needed at finish time."If GIT_DIR == GIT_COMMON (or in a submodule): You are in a normal repo checkout.
Has the user already indicated their worktree preference (CLAUDE.md, brainstorming spec, prior instructions)? If yes, honor it without asking. If no, ask for consent before creating a worktree:
"Would you like me to set up an isolated worktree? It protects your current branch from changes."
If the user declines consent, work in place and skip to Step 3 (Project Setup).
The user has consented to an isolated workspace (Step 0). Do you already have a way to create one? It might be a tool with a name like EnterWorktree, WorktreeCreate, a /worktree command, or a --worktree flag. If you do, use it and skip directly to Step 3 (Project Setup).
Native tools manage directory placement, branch creation, and harness lifecycle hooks (WorktreeCreate/WorktreeRemove). Using git worktree add when you have a native tool creates phantom state your harness can't see or manage.
Only proceed to Step 1b if you have no native worktree tool available.
Only use this if Step 1a does not apply — you have no native worktree tool. Create a worktree manually using git via the task-tracked flow below.
Follow this priority order to select the directory:
.worktrees/ or worktrees/ if present (.worktrees/ wins if both exist).worktrees/ (project-local) or ~/.config/superpowers/worktrees/<project>/ (global)See references/directory-selection.md for full bash commands and ask-user flow.
Safety verification (project-local only):
git check-ignore -q .worktrees to verify directory is ignored.gitignore if not ignored.gitignore change before proceedingSee references/safety-verification.md for full verification protocol.
Creation Steps (Task-Tracked): Create 4 native tasks, each blocked by the previous (non-skippable sequence):
git check-ignore, add to .gitignore if neededgit worktree add <path> -b <branch>See references/creation-steps.md for full TaskCreate blocks, bash commands, and setup detection.
After workspace is established (whether via native tool or git fallback), auto-detect and run setup:
if [ -f package.json ]; then npm install; fi
if [ -f Cargo.toml ]; then cargo build; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi
if [ -f go.mod ]; then go mod download; fi
Run the project test suite. Report pass/fail. If failing, ask before proceeding.
| Situation | Action |
|-----------|--------|
| Already in linked worktree (Step 0) | Skip creation, go to Step 3 |
| In a submodule | Treat as normal repo (Step 0 guard) |
| Native worktree tool available | Use it (Step 1a), skip fallback |
| No native tool | Git worktree fallback (Step 1b) |
| .worktrees/ exists | Use it (verify ignored) |
| worktrees/ exists | Use it (verify ignored) |
| Both exist | Use .worktrees/ |
| Neither exists | Check CLAUDE.md -> Ask user |
| Directory not ignored | Add to .gitignore + commit |
| Tests fail during baseline | Report failures + ask |
| No package.json/Cargo.toml | Skip dependency install |
| Done with worktree | Use ExitWorktree tool (2.1.72+) |
git check-ignore first.Called by: brainstorming (after design), any skill needing isolated workspace
Pairs with: finishing-a-development-branch (cleanup), executing-plans / subagent-driven-development (work happens here)
Cleanup: ExitWorktree tool (2.1.72+) — see Quick Reference and references/creation-steps.md section 6.
references/directory-selection.md: full priority order with bash commands and ask-user flowreferences/safety-verification.md: full gitignore verification protocol with commandsreferences/creation-steps.md: full TaskCreate blocks, bash commands, and setup detectionreferences/example-workflow.md: annotated example of complete worktree setup workflowreferences/red-flags.md: Never/Always lists for quick self-checktools
Use when converting a Superpowers-BD implementation plan or Shortcut story into a beads epic with dependency-aware child tasks
development
Use when the user asks for /cr-style review of local changes, commits, a branch diff, or a GitHub PR outside subagent-driven development
development
Use when you have a spec or requirements for a multi-step task, before touching code
tools
Use when starting any conversation - establishes how to find and use skills, requiring Skill tool invocation before ANY response including clarifying questions