skills/using-git-worktrees/SKILL.md
Use when starting feature work that needs isolation from current workspace, or setting up parallel development tracks. Triggers: 'worktree', 'separate branch', 'isolate this work', 'don't mess up current work', 'work on two things at once', 'parallel workstreams', 'new branch for this', 'keep my current work safe'.
npx skillsauth add axiomantic/spellbook 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.
Announce: "Using git-worktrees skill for isolated workspace."
| Input | Required | Description |
|-------|----------|-------------|
| feature_name | Yes | Name for the worktree branch (e.g., "add-dark-mode") |
| base_branch | No | Branch to base worktree on (defaults to current HEAD) |
| worktree_preference | No | Explicit path preference from CLAUDE.md or user |
| Output | Type | Description |
|--------|------|-------------|
| worktree_path | Path | Absolute path to created worktree directory |
| branch_name | String | Name of the created branch |
| baseline_status | Report | Test results confirming clean starting state |
Follow this priority order:
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # Alternative
If found: Use that directory. If both exist, .worktrees wins.
grep -i "worktree.*director" CLAUDE.md 2>/dev/null
If preference specified: Use it without asking.
If no directory exists and no CLAUDE.md preference:
No worktree directory found. Where should I create worktrees?
1. .worktrees/ (project-local, hidden)
2. ~/.local/spellbook/worktrees/<project-name>/ (global location)
Which would you prefer?
MUST verify directory is ignored before creating worktree:
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
<analysis>
Before creating worktree:
- Does target directory already exist?
- Is directory preference established (existing > CLAUDE.md > ask)?
- Is project-local path gitignored?
If NOT ignored: add to .gitignore + commit immediately. Worktree contents must never be tracked.
</analysis>
If NOT ignored:
No .gitignore verification needed — outside project entirely.
project=$(basename "$(git rev-parse --show-toplevel)")
# Determine full path
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$BRANCH_NAME"
;;
~/.local/spellbook/worktrees/*)
path="~/.local/spellbook/worktrees/$project/$BRANCH_NAME"
;;
esac
# Check if branch/worktree already exists
git worktree list | grep -q "$BRANCH_NAME" && echo "ERROR: Worktree exists"
# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
Auto-detect and run appropriate 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 || uv sync; fi
if [ -f go.mod ]; then go mod download; fi
If setup fails: Report specific failure. Ask whether to proceed or troubleshoot.
Run tests to ensure worktree starts clean:
# Use project-appropriate command: npm test / cargo test / pytest / go test ./...
<reflection>
After worktree creation:
- Did `git worktree add` succeed?
- Are dependencies installed?
- Do tests pass in new worktree?
IF NO to any: Report failure, do NOT proceed with implementation.
</reflection>
If tests fail: Report failures, ask whether to proceed or investigate.
If tests pass: Report ready.
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
Check context for autonomous mode indicators:
worktree preference specified (e.g., "single", "per_parallel_track", "none")When autonomous mode is active:
| Situation | Action |
|-----------|--------|
| .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 |
| Worktree already exists | Report error, ask for new name |
| Setup command fails | Report failure, ask how to proceed |
| No package.json/Cargo.toml | Skip dependency install |
| Mistake | Problem | Fix |
|---------|---------|-----|
| Skip ignore verification | Worktree contents get tracked, pollute git status | Always git check-ignore before creating project-local worktree |
| Assume directory location | Creates inconsistency, violates project conventions | Follow priority: existing > CLAUDE.md > ask |
| Proceed with failing tests | Can't distinguish new bugs from pre-existing issues | Report failures, get explicit permission to proceed |
| Hardcode setup commands | Breaks on projects using different tools | Auto-detect from manifest files |
[Check .worktrees/ - exists]
[Verify ignored - git check-ignore confirms .worktrees/ is ignored]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]
Worktree ready at /Users/jesse/myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth feature
<FORBIDDEN>
- Creating worktrees in unignored project-local directories
- Proceeding with implementation when baseline tests fail
- Assuming worktree location without checking precedence
- Modifying files in main workspace while in worktree context
- Leaving orphaned worktrees after feature completion
- Skipping safety verification for speed
</FORBIDDEN>
<CRITICAL>
## Self-Check
Before reporting worktree ready — if ANY unchecked, STOP and resolve:
git worktree add completed successfullyCalled by:
Pairs with:
<FINAL_EMPHASIS> Worktree isolation protects the main workspace from experimental damage. Skipping safety verification causes repository pollution requiring manual cleanup. Proceeding without baseline tests makes it impossible to distinguish new bugs from pre-existing failures. Take the time to do it right. </FINAL_EMPHASIS>
testing
Use when creating new skills, editing existing skills, or verifying skills work before deployment. Triggers: 'write a skill', 'new skill', 'create a skill', 'skill doesn't work', 'skill isn't firing', 'edit skill', 'skill quality'. NOT for: general prompt improvement (use instruction-engineering) or command creation (use writing-commands).
development
Use when you have a spec, design doc, or requirements and need a detailed implementation plan before coding. Triggers: 'write a plan', 'create implementation plan', 'plan this out', 'break this down into steps', 'convert design to tasks', 'implementation order'. Also invoked by develop during planning. NOT for: reviewing existing plans (use reviewing-impl-plans).
testing
Use when creating new commands, editing existing commands, or reviewing command quality. Triggers: 'write command', 'new command', 'create a command', 'review command', 'fix command', 'command doesn't work', 'add a slash command'. NOT for: skill creation (use writing-skills).
development
Use when about to claim discovery during debugging. Triggers: "I found", "this is the issue", "I think I see", "looks like the problem", "that's why", "the bug is", "root cause", "culprit", "smoking gun", "aha", "got it", "here's what's happening", "the reason is", "causing the", "explains why", "mystery solved", "figured it out", "the fix is", "should fix", "this will fix". Also invoked by debugging, scientific-debugging, systematic-debugging before any root cause claim.