Worktree task
Launch agents in isolated git worktrees to execute a task end-to-end, then present per-worktree diffs for review and selective merge. Use when worktrees are referenced to execute a task resulting in file changes, when sandboxing risky edits, or when running parallel attempts on one task. Composed by the `agent-swarm` skill as the worktree primitive.From its SKILL.md
npx -y skills add yliapis/dotfiles --skill worktree-taskAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
9.9 KB, as published. Nobody here has run it
Worktree Task
Task
Launch an agent in an isolated git worktree to complete {task} end-to-end, then present the resulting diff and ask whether to merge the worktree branch back into the original branch and whether to delete the worktree. When {parallelism} is greater than 1, launch that many sibling agents in independent worktrees (optionally one model per agent from {agent_model}, and at most {concurrency} running at once) and present a per-worktree report so the user can pick at most one branch to merge.
The agent-swarm skill composes this skill as the worktree primitive; agent-swarm owns the swarm-vs-single decision, sizing, model mix, and selection.
Parameters
{task}— the task each agent must complete; required.{base_branch}— branch to fork the worktree(s) from; optional, default: current branch (git rev-parse --abbrev-ref HEAD).{worktree_name}— base name for the worktree directory and branch; optional, default: a filesystem-safe kebab-case slug derived from{task}. When{parallelism}is greater than 1, a 1-based index suffix (-1,-2, …) is appended per agent.{delete_worktree}— whether to delete a worktree after its branch is merged successfully; optional, default:true. Worktrees whose branches are not merged are left in place.{merge_mode}— merge behavior after showing the diff(s); optional, default:interactive. Allowed values:interactive,auto.{test_command}— shell command each agent runs inside its worktree before the diff is presented; optional. Exit code0counts as pass; any other exit code counts as fail.{agent_model}— model(s) to use for the worktree agent(s); optional, default: the parent agent's model. Accepts a single model identifier (broadcast to every agent) or a list of identifiers whose length MUST equal{parallelism}(mapped positionally by index).{parallelism}— total number of sibling agents to launch, each in its own worktree; optional, default:1. MUST be an integer>= 1; otherwise the workflow fails before any worktree is created.{concurrency}— maximum number of agents running simultaneously; optional, default:{parallelism}(all agents launch together). MUST be an integer in1..{parallelism}. Changes pacing only, never the total: exactly{parallelism}worktrees are created regardless.{num_partitions}— number of partitions; optional, default: same as parallelism. MUST be an integer>= 1. When set together with an iterable{agent_model}, the workflow raises an error unless{agent_model}provides a full iteration or a correctly-sized iterable slice for the partitions.{stop_condition}— explicit completion condition beyond "task implemented and verified"; optional.
Success Criteria
- Parameters are validated before any worktree is created:
{parallelism}and{num_partitions}are integers>= 1;{concurrency}is an integer in1..{parallelism}; if{agent_model}is a list its length equals{parallelism}; if{num_partitions}is set together with an iterable{agent_model}, the iterable is either a full iteration or a correctly-sized slice for the partitions. Validation failure aborts with an explanatory error and no filesystem side effects. - Exactly
{parallelism}isolated worktrees are created from{base_branch}(or the current branch when omitted), each on its own branch derived from{worktree_name}; at most{concurrency}agents run at any moment, and every slot keeps its 1-based launch index regardless of scheduling order. - Each agent completes
{task}(and{stop_condition}when provided) inside its own worktree, producing no edits, staged changes, or untracked files in the original working tree or in any sibling worktree. - If
{test_command}is provided, each agent runs it once inside its worktree and the captured exit code is reported per worktree. - The final response includes, per worktree: worktree path, branch, agent model, terminal status (
success/failed/incomplete), change summary, verification result, and thegit diff {base_branch}..<worktree_branch>output. - In
interactivemerge mode, the user is explicitly asked which worktree branch (if any) to merge back into{base_branch}and whether to delete each worktree before any merge or deletion happens. - In
automerge mode, at most one worktree branch is merged, and only when its agent reportedsuccess,{test_command}(when provided) exited0,{stop_condition}(when provided) is satisfied, andgit merge --no-ffagainst{base_branch}produces no conflicts. - When a worktree branch is merged and
{delete_worktree}istrue, that worktree is removed viagit worktree removeand its branch deleted viagit branch -dafter the merge succeeds.
Guardrails
- MUST keep each agent's task execution isolated to its assigned worktree; agents MUST NOT read, write, or run commands against the original working tree or any sibling worktree.
- MUST validate
{parallelism},{concurrency},{num_partitions}, and{agent_model}shape before creating any worktree; fail fast and create nothing on validation failure. - MUST present every worktree's diff (and verification result, when applicable) to the user before any merge in
interactivemode. - MUST NOT delete a worktree before the user has seen its diff (in
interactivemode) or before its merge has succeeded (inautomode). - MUST NOT merge a worktree branch if its agent reported failure,
{test_command}exited non-zero,{stop_condition}is unmet, or the branch has unresolved conflicts with{base_branch}. - MUST NOT merge more than one worktree branch per invocation.
- Scope: this workflow manages one
{task}, up to{parallelism}sibling worktrees forked from one{base_branch}, and at most one resulting merge into{base_branch}. Out of scope: pushing, opening PRs, creating tags, rebasing pre-existing branches, or touching unrelated branches.
Workflow
- Validate parameters; fail fast if
{parallelism}or{num_partitions}is not an integer>= 1,{concurrency}is not an integer in1..{parallelism},{agent_model}is a list whose length differs from{parallelism}, or{num_partitions}is set together with an iterable{agent_model}that is neither a full iteration nor a correctly-sized slice. Create no worktrees on validation failure. - Record the current branch as
{base_branch}unless explicitly provided. - Resolve the per-agent model assignment: broadcast a scalar
{agent_model}to every agent, or zip a list of identifiers positionally by index. - For each
iin1..{parallelism}, create a new branch off{base_branch}named after{worktree_name}(with-{i}suffix when{parallelism}> 1) and add a matching worktree viagit worktree add. - Launch one agent per worktree, each on its assigned model, with instructions to complete
{task}until done (and until{stop_condition}is satisfied, when provided). Keep at most{concurrency}agents running at once: start slots in index order and start the next pending slot as a running one finishes. Slot indexes, worktree names, and model assignments are fixed at creation time and do not depend on scheduling order. - After each agent reports completion, run
{test_command}(if provided) inside that worktree and capture the exit code. - Wait for all agents to finish, then collect per worktree: terminal status, change summary, test result, and
git diff {base_branch}..HEAD. - Present the per-worktree report to the user using the Output Format below.
- If
{merge_mode}isinteractive, ask which worktree branch (if any) to merge into{base_branch}and whether to delete each worktree. - If
{merge_mode}isauto, select the worktree (if any) that satisfies all merge Guardrails; if more than one is eligible, prefer the lowest-index branch. - Merge the selected branch (if any) into
{base_branch}withgit merge --no-ff; abort the merge on conflict and report it. - If the merge succeeds and
{delete_worktree}istrue, remove the merged worktree viagit worktree removeand delete its branch viagit branch -d. Worktrees whose branches were not merged are left in place unless the user opted in to delete them during the interactive prompt.
Output Format
Return a single response with the following named sections, in this order:
Run Summary
Base branch: resolved{base_branch}.Parallelism:{parallelism}.Concurrency: resolved{concurrency}(omit when equal to{parallelism}).Merge mode:interactiveorauto.Counts: succeeded / failed / incomplete.
Worktree Results
One block per worktree, in launch order:
Index: 1-based agent index.Worktree path: absolute path.Branch: worktree branch name.Agent model: model identifier used.Status:success,failed, orincomplete.Summary: 1–5 bullets describing the changes and why.Verification:{test_command}exit code and a brief output tail, orn/awhen{test_command}is not provided.Diff: a fenced```diffblock containinggit diff {base_branch}..<branch>, truncated above ~400 lines with... (truncated, K lines omitted)when oversized.Merge recommendation:merge,skip, orhold, with a one-line reason.
Merge Recommendation
- The recommended worktree branch to merge (or
none) and a one-line rationale.
Merge Prompt
Present this section only in interactive mode. Ask, per worktree:
- Merge
<worktree_branch>into{base_branch}? (y/n) - Delete worktree at
<worktree_path>? (y/n)