CtrlK
BlogDocsLog inGet started
Tessl Logo
SkillPublic

git-worktree

Create, switch to, or delete a git worktree under ~/.worktrees/<path-key>/<branch>, then rebase the agent session onto that directory. Use when asked to make, enter, or remove a worktree for a branch, when work needs an isolated checkout, or when invoked as /git:worktree.

Quality

100%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

SKILL.md
Quality
Evals
Security

Git Worktree

Announce at start: "Using git-worktree skill to the worktree for ."

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

InvocationEffect
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 listone <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 the bash tool's cwd parameter (omp resolves an absolute cwd outside the session directory fine; verified)
  • every file tool call (read/grep/glob/edit) uses absolute paths under $wt_path
  • every task subagent prompt states $wt_path and requires absolute paths under it. Subagents inherit the parent's cwd and the task tool has no cwd field, so a subagent given relative paths silently works in the wrong tree
  • the final report restates $wt_path verbatim, 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:

HarnessLine to printTruth 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
otheromp --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 /move out (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=v1 and 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/tr pipeline — call wt path.
  • Never treat a wt shell session as proof that live terminals picked up .config/zsh/** or .config/nushell/** (see using-git-worktrees).
  • Never git worktree add a 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).

Repository

phatblat/dotfiles

Path

.agents/skills/git-worktree/SKILL.md

Last updated
First committed

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.