Stand up one prepared sibling git worktree — cut from the latest origin default branch — and then stop. This skill is pure setup: it creates the worktree on a new branch, seeds the git-ignored .env* files the build needs, optionally copies other git-ignored working files the user picks, installs dependencies (after asking), and verifies Beads is operational inside the worktree. It never claims the bead, writes a plan, or implements anything.
The main working tree is never modified. The only interaction with it is reading git-ignored files out of it (read-only) to seed the worktree.
-
Preflight. Resolve the current repo root and STOP if this is not a git repo:
MAIN_ROOT=$(git rev-parse --show-toplevel) || { echo "not a git repo"; exit 1; }
REPO_NAME=$(basename "$MAIN_ROOT")
Paths derive from the current toplevel, so running this from inside an existing worktree is fine — but surface the resolved <MAIN_ROOT> before creating anything so the user can see where the new worktree will be cut from.
-
Detect the arg kind using the rule above → <MODE> (BRANCH or BEAD), <BRANCH_NAME>, and (bead mode) <BEAD_ID> / <IS_EPIC>. If detection hits the bare-token-not-a-bead case, STOP and ask — do not proceed.
-
Compute the worktree path (slashes → dashes, mirroring the executor convention):
WORKTREE_SUFFIX=$(printf '%s' "<BRANCH_NAME>" | tr '/' '-')
WORKTREE_PATH="../${REPO_NAME}-${WORKTREE_SUFFIX}"
Guard: if the computed parent resolves to / (e.g. <MAIN_ROOT> is a top-level dir), STOP and ask for an explicit target path rather than creating a worktree at the filesystem root.
-
Detect the default branch (reuse rebase-and-push verbatim):
DEFAULT_BRANCH=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD | sed 's@^origin/@@')
[ -z "$DEFAULT_BRANCH" ] && DEFAULT_BRANCH=$(git rev-parse --verify --quiet origin/main >/dev/null && echo main || echo master)
-
Collision guard — before any fetch or create. Never overwrite:
git show-ref --verify --quiet refs/heads/<BRANCH_NAME> # exists → STOP
[ -e <WORKTREE_PATH> ] # path exists → STOP
- If
<BRANCH_NAME> already exists locally, STOP and ask the user to reuse, rename, or delete it.
- If
<WORKTREE_PATH> already exists on disk, STOP and ask.
-
Fetch the default branch ref so the worktree starts from the latest upstream state:
git fetch origin <DEFAULT_BRANCH>
If this fails (offline / no remote configured), STOP and report — do not silently fall back to a stale local ref.
-
Create the worktree on a new branch off the freshly fetched default:
git worktree add <WORKTREE_PATH> -b <BRANCH_NAME> origin/<DEFAULT_BRANCH>
-
Seed .env* — MANDATORY. A fresh worktree checks out only tracked files, so the git-ignored local env the build needs (.env.local, .env, and the rest of the .env* family) is absent. Seed it up front and unconditionally. Reuse executor-task-worktree step 9 verbatim; run from <MAIN_ROOT> (reads the main tree, never writes to it):
git -C <MAIN_ROOT> ls-files --others --ignored --exclude-standard --directory \
| grep -E '(^|/)\.env(\.[^/]*)?$' \
| while IFS= read -r f; do
mkdir -p "<WORKTREE_PATH>/$(dirname "$f")"
cp -p "<MAIN_ROOT>/$f" "<WORKTREE_PATH>/$f"
done
--directory collapses fully-ignored directories (node_modules/, dist/, .beads/, *.db) to a single entry so the grep skips them — only .env* files are copied. cp -p preserves source permissions (env files are often 600).
- Always run the detection command; treat it as a no-op only when the actual output is empty. Never pre-judge that no
.env* exists because the worktree looks build-ready (.env.example is tracked and proves nothing).
- This seed is non-negotiable — see Hard Rules. A request to skip it does not override this step.
-
Offer additional git-ignored files (interactive). Compute the candidate list, filtering out .env* (already seeded), the workflow-managed runtime artifacts, and heavy dependency/build dirs (the package manager reinstalls those):
git -C <MAIN_ROOT> ls-files --others --ignored --exclude-standard --directory \
| grep -vE '(^|/)\.env(\.[^/]*)?$' \
| grep -vE '^(node_modules|dist|build|\.next|\.turbo|\.nuxt|\.svelte-kit|coverage|target|\.venv|venv|__pycache__|vendor|\.gradle|\.dart_tool|\.parcel-cache|\.cache|out|\.output|tmp|\.beads|\.bv|\.dolt|\.git)/$' \
| grep -vE '(^|/)(\.beads-credential-key|\.claude/scheduled_tasks\.lock|\.claude/settings\.local\.json)$' \
| grep -vE '\.db$' \
| grep -vE '(^|/)docs/plans/$'
-
Present the survivors (e.g. docs/claude-design/, .dev.vars, a local service-account JSON) as a numbered checklist. The default is to copy nothing extra — the user opts in by picking entries.
-
Copy only confirmed entries with cp -Rp (an entry may be a directory):
mkdir -p "<WORKTREE_PATH>/$(dirname "<f>")"; cp -Rp "<MAIN_ROOT>/<f>" "<WORKTREE_PATH>/<f>"
-
If the candidate list is empty, say so and don't prompt.
-
Never copy a must-exclude entry even if the user asks for it (see Hard Rules) — copying .beads/, *.db, .dolt/, etc. corrupts the worktree's beads/db state. If asked, refuse that specific entry, explain why, and copy the rest.
-
Detect the package manager, then ASK before installing. Inspect <WORKTREE_PATH> (the new worktree, which has the tracked lockfile):
bun.lock / bun.lockb → bun install
pnpm-lock.yaml → pnpm install
yarn.lock → yarn install
package-lock.json → npm install
package.json but no lockfile → ask which manager (suggest npm install)
- no
package.json → skip and report (nothing to install)
State the detected command, ask for confirmation, then run it: (cd <WORKTREE_PATH> && <PM> install). If the manager binary is missing, report it and let the user install manually — do not fail the whole flow. Never run a network install silently.
-
Verify Beads health in the worktree. This is what makes an executor-* skill "just work" after cd-ing in:
(cd <WORKTREE_PATH> && bd where)
- On failure, repair:
(cd <WORKTREE_PATH> && bd bootstrap --yes), then re-run bd where.
- Bead mode: this must end with
bd where succeeding. If bd is missing entirely, STOP and report — the executor cannot run without it.
- Branch mode with no Beads in the repo: skip this silently (a plain branch worktree doesn't require Beads).
-
Stop with a setup summary. No claim, no plan, no implementation. Report:
- worktree path, branch name, base (
origin/<DEFAULT_BRANCH>)
.env* seeded? (and how many files)
- extra git-ignored files copied (or "none")
- install command run (or skipped / not confirmed)
- Beads-health result
- the exact
cd <WORKTREE_PATH> to enter it
- which executor to run next:
- bead, non-epic → "
cd in, then run executor-task with <BEAD_ID> — plain, not -worktree. This skill already created the worktree; the -worktree variant would nest another one inside it."
- bead, epic-parented (or an epic-type bead) → "use
executor-epic-task if the PR should target the epic branch; otherwise executor-task."
- reopened bead for rework → "
executor-rework-in-place expects the current branch to already have an open PR (usually in the main checkout), so it's typically not the worktree flow."
- plain branch → "
cd in and work directly, or attach a bead and run an executor later."
- teardown → "remove with the
cleanup-worktree skill when done — this skill never auto-removes the worktree."