Git Worktree
Announce at start: "Using git-worktree skill to <action> the worktree for <branch>."
Contract
This skill never re-derives worktree paths in prose. wt on PATH is the single agent-side implementation. Layout and constraint questions belong to the using-git-worktrees skill.
Actions
| Invocation | Effect |
| --- | --- |
| wt path <branch> [--allow-home] | prints the path that would be used; mutates nothing |
| wt resolve <branch> [--allow-home] | prints the registered worktree path, or exits 3 |
| wt switch <branch> [--allow-home] | resolve, else create; prints the path |
| wt create <branch> [--allow-home] | create only; exits 4 if already registered |
| wt remove <branch> [--allow-home] [--force] | git worktree remove + prune; never touches the branch |
| wt list | one <path>\t<branch> line per worktree (agents cannot use wt's fzf picker) |
| wt verify <branch> | just check with HOME remapped (implies --allow-home) |
Session Rebase Protocol
The load-bearing part. Three parts, in this order:
A. Bind the worktree (always, immediately, no waiting)
Capture the path:
wt_path=$(wt switch "$branch" ${allow_home:+--allow-home})
From this point in the session:
- every shell call passes the worktree as the working directory —
git -C "$wt_path" …, or thebashtool'scwdparameter (omp resolves an absolutecwdoutside the session directory fine; verified) - every file tool call (
read/grep/glob/edit) uses absolute paths under$wt_path - every
tasksubagent prompt states$wt_pathand requires absolute paths under it. Subagents inherit the parent's cwd and thetasktool has nocwdfield, so a subagent given relative paths silently works in the wrong tree - the final report restates
$wt_pathverbatim, so the binding survives context compaction
B. Move the harness's own root (one line, user-run)
Detect the harness — order matters, omp sets both OMPCODE=1 and CLAUDECODE=1:
if [ -n "${OMPCODE:-}" ]; then harness=omp
elif [ -n "${CLAUDECODE:-}" ]; then harness=claude
else harness=other; fi
Then print exactly one line for the user to run:
| Harness | Line to print | Truth to state alongside it |
| --- | --- | --- |
| omp | /move <wt_path> | a real cwd change that keeps this conversation, and reloads project-scoped settings/plugins/commands for the worktree. The agent cannot self-invoke slash commands, so the user runs it. Offer /add-dir <wt_path> instead when they want both roots live, and /dirs to inspect. |
| claude | /add-dir <wt_path> | Claude Code has no cwd-change command; this only grants access, so pwd stays put and part A remains the working mechanism |
| other | omp --cwd <wt_path> | starts a fresh session rooted at the worktree; loses this conversation. --cwd also bypasses omp's ~→temp-dir auto-switch |
Never suggest omp worktree/omp wt here: that CLI manages omp's own agent worktrees under ~/.omp/wt and has nothing to do with ~/.worktrees/.
C. Never block on B
Continue the task under part A whether or not the user runs the line. Do not use AskUserQuestion to wait for it.
Deleting
wt remove refuses in three cases; the skill explains each rather than reaching for --force:
- the current session directory (or
$PWD) is inside the target worktree → tell the user to/moveout (omp) or work from another root first - the target is the repo's main worktree → never removable
- the worktree has uncommitted changes → report
git -C <path> status --porcelain=v1and ask before re-running with--force
Branch deletion is out of scope and stays with git-cleanup / branch-finish. After a successful remove, print git -C <repo_root> branch -d <branch> as the follow-up the user may want, and do not run it.
Never
- Never re-derive the worktree path in prose or with an ad-hoc
sed/trpipeline — callwt path. - Never treat a
wt shellsession as proof that live terminals picked up.config/zsh/**or.config/nushell/**(seeusing-git-worktrees). - Never
git worktree adda path whose leaf differs from the branch name. - Never remove a worktree to "fix" a dirty tree.
- Never invoke
omp worktree/omp wt, and never describe them as related: they manage omp's own agent worktrees under~/.omp/wt, not~/.worktrees/. - Never hand a subagent a relative path and assume it lands in the worktree — subagents inherit the parent cwd.
Integration
Pairs with: using-git-worktrees (layout/constraints), branch-finish (post-merge cleanup), git-stack (already creates worktrees under the same convention).