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)
git rev-parse --show-toplevel— must be inside a git repo. If not, stop and offergit init+ an initial commit (worktrees need at least one commit).git log -1— the repo needs a commit. If there is none, say so;--worktreefails withFailed to resolve base branch "HEAD".- Make sure
.claude/worktrees/is in the repo's.gitignore; add it if missing (tell the user you did). - 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)
- Load the tool if it is deferred:
ToolSearchwithselect:EnterWorktree,ExitWorktree. - Call
EnterWorktreewith a short kebab-case name describing the task (e.g.fix-login-redirect). It creates.claude/worktrees/<name>/on branchworktree-<name>and moves the session's working directory there. - Set up the fresh checkout: it has only tracked files. Install dependencies (
npm install,pip install -r ..., etc.) and check whether gitignored files like.envare needed. If they are, suggest a.worktreeincludefile at the repo root (gitignore syntax, e.g..env) so future worktrees copy them automatically. - 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.