Git worktree

From phatblat/dotfiles · View interactive version

Git worktree is an AI agent skill from the GitHub repository phatblat/dotfiles. Use when asked to create, enter, or remove a git worktree for a branch, when work needs an isolated checkout, or when invoked as /git:worktree. Worktrees live under ~/.worktrees.

How to use this skill

Skill file

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:

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:

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

Integration

Pairs with: using-git-worktrees (layout/constraints), branch-finish (post-merge cleanup), git-stack (already creates worktrees under the same convention).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.