/howtoai-builder:git-worktreesfrom How to AI — Builder
Creates, manages, and cleans up isolated git worktrees for working on multiple branches simultaneously without context switching.
Ships in How to AI — Builder. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A worktree is a second (third, tenth) checkout of the same repository, each on its
own branch, all sharing one .git. That is the whole point: several branches
open at once, with no stashing and no context switch. A hotfix on main while a
half-finished feature sits untouched in another directory. Two agents editing two
branches without stepping on each other (see the parallel-agents skill — worktrees
are what make that safe).
The cost is that each worktree is a real directory with its own uninstalled
dependencies, its own missing .env, and its own claim on your dev server's port.
Budget for setup, and remove it deliberately when the branch lands.
| Goal | Command |
|---|---|
| Create on a new branch | git worktree add .worktrees/<branch> -b <branch> |
| Create from an existing branch | git worktree add .worktrees/<branch> <branch> |
| Track a remote branch | git worktree add .worktrees/<b> --track origin/<b> |
| List them all (with paths + branches) | git worktree list |
Run a command in one without cd | git -C .worktrees/<branch> <cmd> |
| Check one is clean before touching it | git -C <path> status --porcelain (empty = clean) |
| Remove one | git worktree remove <path> |
| Clear stale registrations | git worktree prune |
| Delete the branch after it merged | git branch -d <branch> |
| Delete it on the remote | git push origin --delete <branch> |
git rev-parse --git-dir differing from
git rev-parse --git-common-dir means this is already a linked worktree — work
here, don't nest another. (Submodules also differ; git rev-parse --show-superproject-working-tree returning a path means submodule, not worktree.)worktree
command or flag your harness provides). Hand-rolling git worktree add next to a
native tool creates state the harness can't see or clean up..worktrees/<branch> in the repo root, and make sure that path is
gitignored — git check-ignore -q .worktrees must succeed before you create
anything, or you will commit an entire second checkout into the repo. Escape
hatch: put worktrees in a sibling directory outside the repo
(../<repo>-worktrees/<branch>) when tooling insists on scanning the whole tree
— IDE indexers, test globs, Docker build contexts.npm install, uv sync, cargo build, go mod download), copy the gitignored
config the app needs (.env and friends) from the main checkout, and
git submodule update --init --recursive if the repo uses submodules.Then work normally. Give this worktree its own port when you run the app — the other checkout is probably already holding the default one.
Work through this before integrating anything. Each line is checkable.
git diff <target>...<branch> read end to end: no debug prints, no
commented-out code, no leftover scratch files, no dependency bumps you didn't
mean to make..env, credential-shaped strings in fixtures. git log -p -- <suspect paths>.
A file deleted in a later commit is still in the history.main.Default: rebase the feature branch onto the target (git fetch && git rebase origin/<target>), then integrate. History stays linear and each commit is
reviewable in isolation. Escape hatch: the moment anyone else may have pulled the
branch, stop rebasing and merge the target into it instead — a merge commit is
cheaper than everyone else's history breaking underneath them.
# from the main checkout, not the worktree
git checkout <target> && git pull
git merge <branch>
<test command> # green on the merged result before anything else
git push
git worktree remove .worktrees/<branch> # worktree first: a branch checked out
git branch -d <branch> # in a worktree cannot be deleted
git push origin --delete <branch> # if it was ever pushed
git worktree prune # the step everyone forgets
If the merged result is red, stop: nothing is pushed yet, so leave the branch and worktree exactly where they are and investigate.
Not merging locally? Push and open a PR instead — and keep the worktree, because review feedback gets fixed there. Clean up after the PR lands.
--force-with-lease, never --force. A
rejected push means the remote moved — read it, don't overpower it.git branch -d refuses unmerged
branches; that refusal is the safety check, so never reach for -D to get past
it. Confirm with git log <target>..<branch> returning nothing.git -C <path> status --porcelain must be empty. git worktree remove --force deletes uncommitted
edits and untracked files with nothing in the reflog to recover them..worktrees/
convention belongs to the host environment or the human — leave it alone.Stuck state — "already checked out at", a hand-deleted worktree directory, a branch
deleted too soon, a rebase gone wrong, a committed secret? Read
references/recovery.md.
node_modules and build artifacts are not shared between worktrees. Each one
needs its own install; this is the surprise that catches everyone first. Symlinking
node_modules across worktrees looks clever and breaks on native modules and
lockfile drift..env, no local
config, no seeded SQLite file — so the app dies on startup in a way that looks like
a code bug. Copy them in; never "fix" it by committing them.git checkout <branch> elsewhere fails with "already checked out at ", which reads like
corruption and is just the safety net working.git stash in one worktree is
visible — and poppable — from all of them, so a stash pop can apply someone else's
changes into the wrong tree.git worktree prune..git/hooks are
shared across all worktrees — so a hook that assumes it runs at the repo root will
misbehave in a linked one..worktrees/ doubles CPU and fills search results with duplicate hits until you
exclude it in the editor as well as in .gitignore.What SKILL.md sets; muted values are Claude Code's defaults
7 skills in this plugin
/code-reviewReviews someone's code, and handles feedback on yours — intent first, issues ranked by consequence, blocking vs non-blocking labeled. Use for "review this code", "review my PR", "look at this diff", or "how should I respond to this review comment"./debug-systematicallyFinds the root cause of a bug instead of patching symptoms — reproduce, hypothesize, bisect, explain the mechanism. Use for "debug this", "why is this failing", "this test is flaky", "works locally but not in prod", or "I can't figure out why"./mcp-builderBuilds MCP servers an agent can actually use: tool design, results that fit the context budget, actionable errors, transport, auth. Use for "build an MCP server", "add an MCP tool", "expose my API to an AI assistant", or when tools get picked wrong./parallel-agentsSplits work across subagents running at once — what genuinely parallelizes, briefing each one cold, verifying what comes back. Use for "run these in parallel", "use subagents", "fan this out", "split this work up", or "delegate these tasks"./test-driven-developmentDrives implementation with the test written before the code — red, green, refactor — and knows when test-first is wrong. Use for "TDD", "write tests first", "test-driven", "add tests for this", "red green refactor", or adding a regression test./webapp-testingDrives a running web app in a browser to prove it works — real user flows, console and network evidence, failure paths, saved proof. Use for "test my app in the browser", "does this actually work", "check the page loads", or "verify the signup flow".npx claudepluginhub rubenhassid1/howtoai-skills --plugin howtoai-builderOther plugins' skills for the same job