Git worktrees
Isolate each task in its own worktree so the main checkout stays on the default branch and parallel work never collides.
First: find the repo and defer to a local doc
Run these before anything else — they resolve the repo you're actually in (never hardcode a path):
ROOT="$(git rev-parse --show-toplevel)" || { echo "not a git repo"; exit 1; }
DEFAULT_BRANCH="$(git -C "$ROOT" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@' || echo main)"
If $ROOT/WORKTREES.md exists, read it and follow it instead — the repo's own doc is the source of truth and may override the conventions below. Only fall back to this skill's defaults when the repo has no WORKTREES.md.
Naming (default convention)
| Item | Pattern | Example |
|---|---|---|
| Directory | .claude/worktrees/<slug>/ |
.claude/worktrees/add-start-timestamp |
| Branch | worktree-<slug> |
worktree-add-start-timestamp |
<slug> = kebab-case task title (lowercase, hyphens).
Create
From an up-to-date default branch:
git -C "$ROOT" fetch origin
SLUG="my-feature-name"
git -C "$ROOT" worktree add -b "worktree-${SLUG}" ".claude/worktrees/${SLUG}" "origin/${DEFAULT_BRANCH}"
cd "$ROOT/.claude/worktrees/${SLUG}"
If the branch already exists, drop -b and point at it:
git -C "$ROOT" worktree add ".claude/worktrees/${SLUG}" "worktree-${SLUG}"
Ship
git add -A && git commit -m "…"
git push -u origin HEAD
gh pr create --title "…" --body "…"
Base branch is usually the repo default. Match existing PR titles/bodies in the repo.
List / remove
git -C "$ROOT" worktree list
git -C "$ROOT" worktree remove ".claude/worktrees/${SLUG}" # after the branch is merged
git -C "$ROOT" branch -d "worktree-${SLUG}" # if not auto-deleted
git -C "$ROOT" worktree prune
Notes
- To tear a worktree down by PR state once the task ships, see the companion
worktree-cleanupskill. - Always run
git worktreeagainst$ROOT; paths are relative to it. - Worktrees get their own
.gitfile pointing at the shared object store; tracked files like.claude/settings.jsonand.vscode/settings.jsonare checked out normally. - Sandboxed environments may block worktree creation under
.claude/— retry with full filesystem/git access if checkout fails.