worktree
Create, list, and tear down per-branch git worktrees, each with an isolated Neon database branch and a portless dev URL, so multiple branches can be worked in parallel without DB or dev-server collisi
SKILL.md.claude/skills/worktree/SKILL.md
GitHubWorktree
Manage the lifecycle of per-issue git worktrees. All state-changing logic lives
in the bundled worktree.sh; this skill only routes the subcommand, opens the
editor, and summarizes the result. Do not improvise around the script — it is
the deterministic, idempotent contract.
Quick start
/worktree create drag-and-drop-categories # provision + open a worktree for this branch
/worktree create drag-and-drop-categories 142 # …tagged with issue #142 → branch 142-drag-and-drop-categories
/worktree list # show all worktrees
/worktree cleanup 142 # tear down by issue# (guards against unsaved work)
/worktree cleanup drag-and-drop-categories # …or by branch name
/worktree cleanup --merged # sweep all merged/closed worktrees
How it works
A worktree lives at .worktrees/<branch>, where <branch> is a DNS-safe slug of
the given name, optionally prefixed with an issue number (<issue#>-<slug>). The
directory name doubles as the portless hostname prefix
(<branch>.personal-finance.localhost) and the Neon branch name
(local/<branch>). The Neon branch is provisioned by the post-checkout hook on
create and reaped by teardown.yml on branch delete — this skill never touches
the Neon API itself.
Workflow
- Parse the argument string into
<subcommand> <args>. If empty or unknown, runbash .claude/skills/worktree/worktree.sh --helpand stop. - Run the script, streaming its output:
bash .claude/skills/worktree/worktree.sh <subcommand> <args> - On
createsuccess only: open the editor window withcode <WORKTREE_DIR>(readWORKTREE_DIR=from the script's output). - Summarize for the user: branch, worktree path,
DEV_URL, Neon branch (local/<branch>), and the next step:cd <WORKTREE_DIR> && claude(thenmake startfor the dev server). - On any failure, surface the script's error verbatim and stop. No auto-retry, no calling the Neon API by hand, no force-removing on your own initiative.
No handoff doc or issue primer is written — the developer pulls issue context
themselves once claude is running in the worktree.
Guardrails
createrequires.envin the main worktree (make env_pullif missing) and must run from the repo root, not a linked worktree. The script enforces both.cleanuprefuses to remove a worktree with uncommitted changes or unpushed commits. Only pass--forceif the user explicitly confirms the work is disposable.- A never-pushed branch never triggers
teardown.yml, so its Neon branch can orphan. If that matters, push the branch first or runscripts/neon-branch.sh delete --allperiodically. - Per CLAUDE.md, never run
make/yarnverification here — that flows through@agent-codebase-verification.
Verifying changes to this skill
The mutating paths touch real Neon branches (never mocked). To verify:
- Automated:
worktree.sh create <name> --dry-runmust print the resolved branch (<slug>, or<issue#>-<slug>when an issue number is passed), worktree dir, Neon branch, and dev URL with no mutation. Runshellcheck worktree.shif available. - Manual smoke:
createa throwaway branch → confirm worktree,.env, Neon branch, dev URL, andcodewindow →listshows it →cleanupblocks on a dirty file →cleanup --forceremoves it →teardown.ymlreaps the Neon branch on delete. - Idempotency: run
create <name>twice; the second run must reuse, not duplicate or error.