Agent Worktree
Create a new worktree for a subtask and launch a new agent in a tmux window split.
When to Use
- •You need to delegate a small, well-scoped subtask to a new agent.
- •You want a dedicated worktree and tmux window for that subtask.
Inputs Required
- •Current worktree root (the skill is invoked from inside a worktree).
- •Subtask identifier and short description (e.g.
ABC-124or123+localization_management_migration). - •Base branch to branch from (detect from
origin/HEADif not provided). - •Initial prompt content derived from the spec doc task list.
Instructions
- •Identify the repo root and verify the current worktree is clean. If there are uncommitted changes, stop and ask the user to clean or stash them.
- •Assume the current directory is the worktree root.
- •Build a worktree name:
- •If a Jira subtask ID or GitHub issue number exists:
<ID>_<brief_description> - •Otherwise:
<brief_description> - •Use ASCII, replace spaces with underscores, avoid special characters.
- •If a Jira subtask ID or GitHub issue number exists:
- •Determine the base branch:
- •Prefer
origin/HEAD(e.g.origin/masterororigin/main).
- •Prefer
- •Ensure the worktree does not already exist:
- •Check
git worktree listand the target directory.
- •Check
- •Create the worktree and branch as a sibling directory:
- •Use the worktree name as the branch name.
- •Open a tmux window in the new worktree, split vertically, start the agent, using the
agentCLI command (NOTcursor), and send the initial prompt.- •Name the tmux window with relevant short description (same as the worktree identifier).
- •Continue the parent conversation after the initial prompt is sent.
Example Commands
Detect base branch:
code
git symbolic-ref --short refs/remotes/origin/HEAD | sed 's@^origin/@@'
Check clean status:
code
git status --porcelain
Create worktree and branch (sibling to current worktree):
code
git worktree add -b "<worktree_name>" "../<worktree_name>" "<base_branch>"
Start tmux window and agent in plan mode:
code
tmux new-window -n "<description>" -c "../<worktree_name>" \; \ split-window -h -c "../<worktree_name>" \; \ send-keys agent Space -p Space --approve-mcps Space "<initial_prompt>" C-m
Notes
- •Do not create a worktree if it already exists.
- •Do not proceed if there are uncommitted changes.
- •The right pane is for the agent, the left pane is for review and git commands.