Use when starting feature work that needs isolation from the current branch, or before executing a plan or fanning out parallel stations - sets up an isolated workspace using the harness's native worktree tool, falling back to a git worktree. Triggers on "worktree", "isolate this work", "don't touch my branch", "work on a copy".
--- name: worktree version: 0.1.0 license: MIT description: Use when starting feature work that needs isolation from the current branch, or before executing a plan or fanning out parallel stations - sets up an isolated workspace using the harness's native worktree tool, falling back to a git worktree. Triggers on "worktree", "isolate this work", "don't touch my branch", "work on a copy". --- # worktree A cook does not prep on the same board the plates are leaving from. A clean station is the first move of service, not an afterthought: it keeps the work in front of you from contaminating what is already plated. This skill sets up that clean station for code, an isolated workspace where a feature or a risky change can be built without touching the branch the user is standing on. **Core principle:** detect existing isolation first, then prefer the harness's native worktree tool, then fall back to git. Never fight the harness by stacking a manual worktree on top of one it already gave you. ## Step 0: are you already isolated? Before creating anything, check. Stacking a worktree inside a worktree is the most common mistake. ```bash 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) git rev-parse --show-superproject-working-tree 2>/dev/null # non-empty = submodule, not a worktree ``` If `GIT_DIR != GIT_COMMON` and you are not in a submodule, you are already in a linked worktree. Report the path and branch, skip to Step 2. If they are equal (or you are in a submodule), you are in a normal checkout: continue. ## Step 1: get consent, then create If the user's instructions already declare a worktree preference, honor it without asking. Otherwise ask once: "Want me to set up an isolated worktree so your current branch stays untouched?" If they decline, work in place and skip to Step 2. **1a. Native tool first (preferred).** If the harness gives you a worktree mechanism, a tool named something like `EnterWorktree` or `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag, use it and skip to Step 2. Native tools own directory placement, branch creation, and cleanup; a hand-rolled `git worktree add` on top of them leaves phantom state the harness cannot see. **1b. Git fallback (only when no native tool exists).** Pick the directory by priority: explicit user preference, then an existing `.worktrees/` (wins) or `worktrees/`, else default to `.worktrees/` at the repo root. For a project-local directory, verify it is ignored before creating anything (`git check-ignore -q .worktrees`); if not, add it to `.gitignore` and commit that first, or the worktree contents get tracked. Then: ```bash git worktree add ".worktrees/$BRANCH" -b "$BRANCH" cd ".worktrees/$BRANCH" ``` If creation fails on a permission or sandbox denial, say so plainly, work in the current directory, and run setup in place. ## Step 2: setup and a clean baseline Install dependencies for whatever the repo is (`npm install`, `cargo build`, `pip install -r requirements.txt` / `poetry install`, `go mod download`), then run the suite once so you start from a known-green floor ([check](../check/SKILL.md)). If the baseline is already red, report it and ask before building on top: you cannot tell your new bug from a pre-existing one otherwise. Report: the worktree path, the branch, and the baseline result. ## Pairs with - [stations](../stations/SKILL.md): concurrent stations that write to the same files each get their own worktree so they do not collide in one tree. - [fire](../fire/SKILL.md): execute a plan inside the isolated workspace, not on the user's working branch. ## Common mistakes - Creating a worktree when Step 0 already found one. Detect before you build. - Reaching for `git worktree add` when the harness has a native tool. If you have it, use it; the git path is the fallback, not the default. - Skipping the ignore check, so the worktree's files land in `git status` and eventually in a commit. - Building on a red baseline, then being unable to separate your change's failures from the ones that were already there. - Guessing the directory instead of following the priority order; the inconsistency bites the next session that looks for the worktree.
don't have the plugin yet? install it then click "run inline in claude" again.
added explicit inputs with setup guidance, broke procedure into discrete steps with input-output pairs, extracted decision logic into a dedicated section, documented edge cases (permission failures, red baseline, ignore checks), clarified harness vs git priority, added output contract with example json, and defined outcome signal for user validation.
set up a clean, isolated workspace for feature work or parallel execution without contaminating the branch you're standing on. use this before starting risky changes, running a plan in isolation, or fanning out concurrent work stations. triggers on "worktree", "isolate this work", "don't touch my branch", "work on a copy". the core principle: detect existing isolation first, prefer the harness's native worktree tool, fall back to git worktree, never stack isolation on top of isolation.
.git directoryEnterWorktree, WorktreeCreate, /worktree command, or --worktree flag. if present, takes priority over git worktree.worktrees/ or worktrees/ if they exist, else default to .worktrees/ at repo root.gitignore if setting up a new worktree directoryStep 0: detect existing isolation
before creating anything, check if you are already in a linked worktree or submodule.
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)
SUPERPROJECT=$(git rev-parse --show-superproject-working-tree 2>/dev/null)
inputs: git state (GIT_DIR, GIT_COMMON, superproject marker)
output: isolation status (already isolated, in submodule, or clean checkout)
if GIT_DIR != GIT_COMMON and SUPERPROJECT is empty, you are already in a linked worktree. report the path and current branch, then skip to Step 2. if GIT_DIR == GIT_COMMON or SUPERPROJECT is non-empty (submodule), you are in a normal checkout. continue to Step 1.
Step 1: consent and workspace creation
1a. check for existing worktree preference in task instructions.
input: user task context
output: preference string or null
if found (e.g., "use .worktrees/feature-x" or "use native worktree"), honor it without asking. if not found, ask once: "want me to set up an isolated worktree so your current branch stays untouched?" capture the response.
output: consent (yes/no/already-stated)
if the user declines, set a flag WORK_IN_PLACE=true and skip to Step 2.
1b. prefer native harness tool.
input: harness capabilities (check for EnterWorktree, WorktreeCreate, /worktree command, or --worktree flag)
output: worktree path and branch name
if a native tool exists, invoke it (e.g., EnterWorktree feature-branch or harness-specific command). let the harness own directory placement, branch creation, and cleanup. skip to Step 2.
output: working directory path, branch name, creation status (success/failure)
1c. git fallback (only if no native tool).
input: user directory preference (if any), existing .worktrees/ or worktrees/ dirs, repo root
output: resolved worktree directory path
resolve directory by priority:
.worktrees/ directory, orworktrees/ directory, or.worktrees/ at repo rootverify the resolved directory is git-ignored:
git check-ignore -q "$WORKTREE_DIR"
input: git ignore rules
output: ignore status (ignored or not-ignored)
if not ignored, add it to .gitignore, commit that change first, then proceed. if the commit fails, report it and ask before continuing.
create the worktree:
git worktree add "$WORKTREE_DIR/$BRANCH" -b "$BRANCH"
cd "$WORKTREE_DIR/$BRANCH"
input: branch name, worktree directory
output: worktree path, branch name, creation status (success/failure/permission-denied)
if creation fails on permission or sandbox denial, report the error plainly. set WORK_IN_PLACE=true and run setup in the current directory instead.
Step 2: setup and baseline
install dependencies for the repo. run the appropriate command based on language detection:
npm installcargo buildpip install -r requirements.txtpoetry installgo mod downloadinput: package manager presence, dependency files
output: install status (success/failure), dependency tree
run the test suite once to establish a known-green baseline:
# invoke via check skill
input: test suite, worktree state
output: baseline test results (pass/fail), test report
if the baseline is red, report it and ask: "baseline is failing. build on top of this anyway?" do not proceed without consent. you cannot separate your new bugs from pre-existing ones.
input: baseline status, user consent
output: permission to proceed or stop
report to the user:
WORK_IN_PLACE=true)WORK_IN_PLACE=true, skip worktree creation, run setup in current directory..gitignore and commit before creating worktree.WORK_IN_PLACE=true, run setup in place.on success, the skill outputs:
WORK_IN_PLACE=trueexample output:
{
"worktree_path": "/repo/.worktrees/feature-xyz",
"branch": "feature-xyz",
"baseline_status": "pass",
"baseline_count": { "passed": 142, "failed": 0, "skipped": 3 },
"ignored": true,
"creation_method": "git-worktree"
}
all paths are absolute and verified to exist. all test counts are integers. if creation_method is "in-place", worktree_path equals the current working directory at invocation time.
the user knows this worked when:
git status of the parent repo (it is properly ignored or isolated by the harness)git worktree list (if using git fallback) or harness status shows the new workspace