worktree

Installation
SKILL.md

worktree

A git worktree is a second checkout of the same repo on its own branch. Edits there never touch the main checkout, so it is the safe place for experiments, risky refactors, and parallel work.

Preconditions (check first)

  1. git rev-parse --show-toplevel — must be inside a git repo. If not, stop and offer git init + an initial commit (worktrees need at least one commit).
  2. git log -1 — the repo needs a commit. If there is none, say so; --worktree fails with Failed to resolve base branch "HEAD".
  3. Make sure .claude/worktrees/ is in the repo's .gitignore; add it if missing (tell the user you did).
  4. Note uncommitted work in the main checkout. Default worktrees branch from the remote default branch, not the current branch, so in-progress changes will NOT be in the new worktree. If the user wants their current state, either commit first or set "worktree": {"baseRef": "head"} in settings — ask which.

A. Move this session into a worktree (most common)

  1. Load the tool if it is deferred: ToolSearch with select:EnterWorktree,ExitWorktree.
  2. Call EnterWorktree with a short kebab-case name describing the task (e.g. fix-login-redirect). It creates .claude/worktrees/<name>/ on branch worktree-<name> and moves the session's working directory there.
  3. Set up the fresh checkout: it has only tracked files. Install dependencies (npm install, pip install -r ..., etc.) and check whether gitignored files like .env are needed. If they are, suggest a .worktreeinclude file at the repo root (gitignore syntax, e.g. .env) so future worktrees copy them automatically.
  4. Tell the user: worktree path, branch name, and that the main checkout is untouched.

To hop to another existing worktree under .claude/worktrees/, call EnterWorktree with that path.

Installs
3
First Seen
Nov 5, 2026