skills/using-worktrees/SKILL.md
Use when starting an isolated feature branch, when working on multiple features simultaneously, when experimenting without affecting the main workspace, or when a clean workspace is needed before beginning implementation. User phrases like "start a new branch", "set up a worktree", "isolated workspace", "work on feature X separately".
npx skillsauth add joshsymonds/gambit using-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. No switching branches, no stashing, no conflicts with in-progress work.
Core principle: Discover location → verify safety → create → setup environment → verify baseline → report.
Iron Law: NO skipping baseline verification. Tests must pass in the new worktree BEFORE reporting ready. No exceptions.
Announce at start: "I'm using gambit:using-worktrees to set up an isolated workspace."
LOW FREEDOM - Follow the 8-step process exactly. No skipping steps. STOP points halt execution until resolved.
| Step | Action | STOP If | |------|--------|---------| | 1 | Check existing directories | - | | 2 | Check CLAUDE.md preference | - | | 3 | Ask user for preference | No answer received | | 4 | Verify directory is gitignored | Cannot add to .gitignore | | 5 | Create worktree | Git command fails | | 6 | Run environment setup | Setup fails | | 7 | Verify clean baseline | Tests fail AND user says investigate | | 8 | Report ready | - |
Directory priority: Existing dir > CLAUDE.md preference > Ask user
Don't use for: quick fixes, single-file changes, when user explicitly wants current directory
ls -d .worktrees 2>/dev/null # Check first (preferred, hidden)
ls -d worktrees 2>/dev/null # Check second (alternative)
.worktrees/ exists → Use it, skip to Step 4worktrees/ exists (no .worktrees) → Use it, skip to Step 4.worktrees/, skip to Step 4grep -i "worktree" CLAUDE.md 2>/dev/null
REQUIRED: Use AskUserQuestion tool.
AskUserQuestion
questions:
- question: "No worktree directory found. Where should I create worktrees?"
header: "Location"
options:
- label: ".worktrees/ (Recommended)"
description: "Project-local, hidden directory"
- label: "worktrees/"
description: "Project-local, visible directory"
- label: "~/.worktrees/<project>/"
description: "Global location outside project"
multiSelect: false
STOP: Wait for user response before proceeding.
Project-local directories only (.worktrees or worktrees). Skip for global (~/.worktrees/).
git check-ignore -q .worktrees 2>/dev/null # or worktrees
echo ".worktrees/" >> .gitignore
git add .gitignore && git commit -m "chore: add worktree directory to gitignore"
STOP if commit fails. Do not create worktree with unignored directory.
Determine branch name from user request (e.g., "auth feature" → feature/auth).
# Set path based on location choice
path=".worktrees/$BRANCH_NAME" # project-local
path="$HOME/.worktrees/$project/$BRANCH_NAME" # global
git worktree add "$path" -b "$BRANCH_NAME"
STOP if git command fails. Report error and ask user.
Verify:
cd "$path" && git status # Clean working tree on new branch
Detect project type and run FIRST match:
| Priority | Detection | Setup Command |
|----------|-----------|---------------|
| 1 | devenv.nix or .envrc | See devenv workflow below |
| 2 | package.json | npm install / yarn install / pnpm install (match lockfile) |
| 3 | Cargo.toml | cargo build |
| 4 | pyproject.toml with tool.poetry | poetry install |
| 5 | requirements.txt | pip install -r requirements.txt |
| 6 | go.mod | go mod download |
| None | No match | Report "No recognized project type. Skipping setup." |
If devenv detected, check for database usage:
grep -l "DATABASE_URL\|postgres\|mysql" devenv.nix .envrc 2>/dev/null
If database found, REQUIRED: Ask about strategy:
AskUserQuestion
questions:
- question: "This project uses devenv with a database. How should the worktree handle it?"
header: "Database"
options:
- label: "Share database (Recommended)"
description: "Use same $DATABASE_URL as main. Faster setup, shared data."
- label: "Isolated database"
description: "Create new database. Clean slate, but requires migration."
multiSelect: false
STOP: Wait for response.
direnv allow 2>/dev/null || devenv shell.env.local, allow direnv, run migrationsREQUIRED: Run tests to establish baseline.
| Project Type | Test Command |
|--------------|--------------|
| Node.js | npm test |
| Rust | cargo test |
| Python | pytest |
| Go | go test ./... |
| Devenv | Check Makefile for test target |
Tests failing (N failures) in fresh worktree.
[Show first 3-5 failures]
These failures exist in the base branch. Options:
1. Proceed anyway (failures are known/expected)
2. Investigate before proceeding
3. Cancel worktree creation
git worktree remove "$path", STOPWorktree ready at <full-absolute-path>
Branch: <branch-name>
Tests: <N> passing, <M> failures (if any)
Environment: <devenv/npm/cargo/pip/go/none>
Always use full absolute path. User needs it for navigation.
Then chain to the next skill automatically. If tasks exist (invoked from a brainstorming handoff), invoke executing-plans directly:
Skill skill="gambit:executing-plans"
If no tasks exist yet (invoked standalone), ask the user:
AskUserQuestion
questions:
- question: "Worktree ready. What's next?"
header: "Next step"
options:
- label: "Plan the work"
description: "Design and create tasks with gambit:brainstorming"
- label: "Start executing"
description: "Execute existing tasks with gambit:executing-plans"
multiSelect: false
Then invoke the chosen skill directly using the Skill tool.
All mean: STOP. Follow the process.
| Excuse | Reality | |--------|---------| | "Directory is probably ignored" | RUN git check-ignore to verify | | "Tests probably pass" | RUN tests to verify | | "Same as last time, don't need to ask" | ASK — user preferences can change | | "Small feature, don't need isolation" | User requested worktree — create it | | "Can fix gitignore later" | FIX NOW — prevents accidents |
Before reporting ready:
See REFERENCE.md for detailed good/bad examples including:
Called by:
gambit:brainstorming (optional, user chooses at handoff)/gambit:using-worktreesCalls:
gambit:executing-plans (invoked directly after worktree setup, if tasks exist)gambit:brainstorming (if invoked standalone with no tasks)Pairs with:
gambit:finishing-branch — handles worktree cleanup after work completeWorkflow:
gambit:brainstorming → gambit:using-worktrees → gambit:executing-plans
↓
gambit:review
↓
gambit:finishing-branch
testing
Use when creating a new skill, modifying an existing skill, writing or rewriting a SKILL.md file, auditing a skill's description for discoverability, or when user mentions "create a skill", "write a skill", "new skill", "modify skill", "improve skill", "edit the skill".
development
Use before any completion claim, success statement, or marking a task done. Triggers when about to say "Great!", "Perfect!", "Done", "All set", "Ready to commit", before creating a PR, before moving to the next task, or when code has changed since the last test run.
development
Use at the start of every session before any response or action. Also invoke whenever uncertain which gambit skill applies, when about to implement / debug / refactor / test / plan / brainstorm, or when a user request could match any gambit skill even at 1% probability.
development
Use when bugs keep slipping through despite high test coverage, when suspecting tests are giving false confidence, before a major refactor that will depend on the existing test suite, or when coverage metrics don't match incident rates. User phrases like "do these tests actually catch bugs?", "is this suite any good?", "why didn't the tests catch this?".