worktree
Creates a git worktree under .claude/worktrees/<branch> for a parallel session, and removes it once its branch is merged. Use when starting a session that must not disturb an already checked out branc
Files1
View on GitHubSKILL.mdskills/repo/worktree/SKILL.md
GitHubWorktree
One checkout, one session, without disturbing a branch another session already has open.
When to use
- Starting a session that needs its own checkout alongside an existing one.
- A branch merged and its worktree is no longer needed.
- The worktree list has grown and needs pruning.
- An investigation or a reproduction needs a checkout to build or run in, with no branch and no pull request of its own.
Steps
- Check
.gitignorefor a.claude/worktrees/entry. Add it when missing. - Branch off the base from config
pr.base, else the repository default branch:git worktree add --no-track .claude/worktrees/<branch> -b <branch> <base>. Without--no-trackthe upstream write to.git/configcan fail in a sandbox, after the branch exists and before the worktree does. Clear that state withgit worktree prune, thengit branch -D <branch>, then add again. - Install dependencies inside the new worktree when a lock file exists there.
- Run every command for that session from inside
.claude/worktrees/<branch>, never from the original checkout. - Once the branch's pull request merges:
git worktree remove .claude/worktrees/<branch>, thengit branch -d <branch>, thengit worktree prune. A worktree lives as long as its pull request. Acould not lock config file .git/configmessage on the remove is harmless oncegit worktree listno longer shows the path. Prune afterwards. - List existing worktrees with
git worktree listand prune one left behind by a merged or abandoned branch. A session that ends checks for its own stale worktrees first.
Investigation worktrees
- A reproduction or an investigation with no branch and no pull request gets a detached
worktree instead:
git worktree add --detach <path> <base>, outside every repository under the session's scratch directory, never under.claude/worktrees/. - It carries no branch and is never pushed. Nothing written there is committed from the parent checkout.
- Remove it with
git worktree remove <path>in the same task that created it.
Guardrails
- One branch, one worktree, one session. Never point two sessions at the same worktree.
- Before dispatching an agent into an existing worktree, check the agent list or the task list for another running agent on it.
- No status update proves an agent has stopped, a completion notice for one turn included. The same agent can be resumed and keep working in the same worktree. It holds the worktree until its termination is confirmed.
- Never remove a worktree whose branch still has unmerged work without checking first.
- A commit, amend, rebase or cherry-pick in a worktree follows the same identity rule: no
GIT_CONFIG_GLOBAL=/dev/nullwithoutGIT_COMMITTER_EMAILin the same command. Seegit-conventions. .claude/worktrees/stays in.gitignore. Never commit a worktree's contents from the parent checkout.- A detached investigation worktree lives outside the repository and outside
.claude/worktrees/, carries no branch, and is removed before the task ends.
Config
pr.base: base branch for the new worktree. Default: the repository default branch.
References
git-conventionsfor the branch naming and history rules a worktree's branch still follows.