yun-spawn-worktree
Spawn an ephemeral worktree — a second working tree of a synced repo, on its own branch,
so parallel agents each get an isolated tree and branch instead of editing or scanning each
other's. It only creates the worktree; removing it is the caller's job once the work lands
(git worktree remove, or a future yun-clean-worktree). This is the light isolation rung —
pure git, local, no sandbox — the seam a heavier execution substrate plugs in above.
Preconditions
- You MUST be at the workspace root (the dir with
AGENTS.mdandskills/). Stay there — operate withgit -C, nevercdinto the repo or the worktree (AGENTS.md rule 1). repos/<repo>/exists and is a FULL clone — worktrees need full history, so a shallow clone won't do (yun-sync-repoclones full by default).
Inputs
<repo>— the synced repo underrepos/<repo>/.<task>— a kebab-case slug for the work; names both the worktree dir and its branch. It may carry slash-separated segments (<prefix>/<ticket>-<nonce>) so a caller spawning a whole set can group them under one branch namespace it can list and prune later; git takes the slashes in a branch name, and the worktree simply nests to match.<base>— the ref to branch from (optional; defaults to the repo's currentHEAD).
Steps
Resolve and check for collision. Confirm
repos/<repo>/is a repo. If.worktrees/<repo>/<task>/already exists, or a branch named<task>already exists in the repo, STOP and ask — never clobber another agent's worktree or branch. Done when the target path and branch name are both free.Spawn the worktree on a new branch. Add it at an ABSOLUTE path — a path passed to
git -Cis read against the repo dir, not the workspace root, so an absolute path is what keeps the worktree under.worktrees/(outside the repo's own tree, per rule 3):git -C repos/<repo> worktree add -b <task> "$(pwd)/.worktrees/<repo>/<task>" <base>Done when the command succeeds.
Verify isolation.
git -C repos/<repo> worktree listshows the new worktree on branch<task>.git statusat the workspace root does NOT list it —.worktrees/is gitignored; if it appears, the workspace.gitignoreis broken, so fix it before continuing. Done when both hold.Report. Give the ready path
.worktrees/<repo>/<task>/and its branch. Work runs there viagit -C .worktrees/<repo>/<task>, from the workspace root. Done when the caller has the path and branch.
Cleanup
The caller's job once the work lands, not this skill's: git -C repos/<repo> worktree remove .worktrees/<repo>/<task>. Run git worktree prune BEFORE deleting a source repo, and
git worktree repair if the workspace moves (AGENTS.md rule 4).