name: worktree-task
description: Execute instructions in an isolated worktree, commit, fast-forward merge to parent, cleanup. Args: <instructions...>
Worktree Task
Execute a set of instructions in an isolated worktree branched from a parent branch.
Commit results, fast-forward merge back to parent, delete worktree/branch, report.
Args
/worktree-task <parent-branch> <instructions...>
$PARENT — branch to fork from and merge back to (required).
$INSTRUCTIONS — what to do in the worktree (required). Free-form text.
If either is missing, ask the user.
Setup
- Verify
$PARENT exists: git rev-parse --verify $PARENT.
- Generate branch name:
task-<short-description>-<date>-<short-id> derived from instructions.
<short-description> — 2-3 word slug from instructions.
<short-id> — 4 random hex chars; avoids collisions on same-day reruns. e.g. task-add-logging-20260322-3f2a.
- Path:
$PROJECT/.worktrees/<branch>.
- Create worktree:
git worktree add $PROJECT/.worktrees/<branch> -b <branch> $PARENT
cd to worktree. All work happens there.
- Create
.tmp/ if missing.
Execute
- Carry out
$INSTRUCTIONS in the worktree.
- Follow all standard pre-read rules (Go, shell, etc.) as applicable to the work.
- If instructions are ambiguous, ask the user before proceeding.
Commit
- Stage only files relevant to the instructions. Do NOT stage
.tmp/ content.
- Write a commit message per
~/.claude/docs/git-operations.md rules.
- Commit.
Merge
Rebase onto $PARENT so merge is fast-forward:
git fetch . $PARENT
git rebase $PARENT
Then fast-forward $PARENT. Locate where $PARENT is checked out:
If --ff-only fails → rebase again, retry once. If still fails → report error, do NOT force.
Cleanup
After successful merge:
git worktree remove $PROJECT/.worktrees/<branch>
git branch -d <branch>
If merge failed → do NOT delete. Report the worktree path so the user can inspect.
Report
Always end with:
- Commit:
<hash> (short hash on $PARENT after merge)
- Files modified: list of changed files
- Summary: 1-3 sentence description of what was done
- Worktree: cleaned up, or path if retained due to error
Rules
- ALWAYS work in the worktree, NEVER in root checkout.
- ALWAYS commit before merging — NEVER merge uncommitted work.
- ALWAYS use
--ff-only — NEVER create merge commits.
- NEVER stage
.tmp/ or unrelated files.
- NEVER force-push or use
--force.
- If instructions produce no changes → report "no changes needed", cleanup worktree, stop.