| name | using-git-worktrees |
| description | 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 |
Using Git Worktrees
Overview
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: Systematic directory selection + safety verification = reliable isolation.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Directory Selection Process
Follow this priority order:
1. Check Existing Directories
ls -d .claude/worktrees 2>/dev/null
ls -d .worktrees 2>/dev/null
ls -d worktrees 2>/dev/null
If found: Use that directory. Priority: .claude/worktrees > .worktrees > worktrees.
2. Default: .claude/worktrees/
This project uses .claude/worktrees/ as the worktree directory (already gitignored). Create it if it doesn't exist.
Safety Verification
For Project-Local Directories (.claude/worktrees, .worktrees, or worktrees)
MUST verify directory is ignored before creating worktree:
git check-ignore -q .claude/worktrees 2>/dev/null || git check-ignore -q .worktrees 2>/dev/null
If NOT ignored:
- Add appropriate line to .gitignore
- Commit the change
- Proceed with worktree creation
For Global Directory (~/.config/superpowers/worktrees)
No .gitignore verification needed - outside project entirely.
Creation Steps
1. Detect Project Name
project=$(basename "$(git rev-parse --show-toplevel)")
2. Create Worktree
path=".claude/worktrees/$BRANCH_NAME"
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
3. Copy Environment Files
.env files are gitignored and exist at the repo root and inside individual apps. Copy all of them into the worktree so services can run:
repo_root=$(git rev-parse --show-toplevel)
find "$repo_root" -name ".env" \
-not -path "*/node_modules/*" \
-not -path "*/.venv/*" \
-not -path "*/.claude/worktrees/*" \
| while read -r envfile; do
relative="${envfile#$repo_root/}"
cp "$envfile" "$path/$relative"
done
4. Run Project Setup
Auto-detect and run appropriate setup:
if [ -f package.json ]; then bun install; fi
if [ -f pyproject.toml ]; then uv sync; fi
5. Verify Clean Baseline
Run tests to ensure worktree starts clean:
bun run lint
uv run pytest
If tests fail: Report failures, ask whether to proceed or investigate.
If tests pass: Report ready.
6. Report Location
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
Quick Reference
| Situation | Action |
|---|
.claude/worktrees/ exists | Use it (already gitignored) |
.worktrees/ exists | Use it (verify ignored) |
| Neither exists | Create .claude/worktrees/ |
| Directory not ignored | Add to .gitignore + commit |
| Tests fail during baseline | Report failures + ask |
Red Flags
Never:
- Create worktree without verifying it's ignored (project-local)
- Skip baseline test verification
- Proceed with failing tests without asking
- Assume directory location when ambiguous
Always:
- Follow directory priority: existing > CLAUDE.md > ask
- Verify directory is ignored for project-local
- Auto-detect and run project setup
- Verify clean test baseline