worktree-manager
Create, inspect, release, or remove Git worktrees with separate authorization and safety gates.
SKILL.mdskills/worktree-manager/SKILL.md
GitHubPurpose
Manage Git worktree lifecycle operations safely without silently destroying state.
Trigger / When to use
Use this skill when:
- the user asks to
create,get-worktree,release worktree, orremove worktree - the agent must create a managed task worktree at the canonical external path
- the operator needs a structured inspect result before deciding whether to keep, release, remove, or manually review a worktree
Do not use this skill when:
- the task is implementation work inside an already selected worktree
- the request is merge, push, branch deletion, release-tag, or environment setup work
- the user expects
release worktreeto imply deletion - the user wants repository-internal worktree placement under the repo root
Inputs
- requested operation:
create,get-worktree,release worktree, orremove worktree - repository root context for the target repo
- worktree selector when inspecting, releasing, or removing
- branch name or worktree name for create
- optional managed-path prefix override from the human; otherwise use
agent - explicit human destructive approval before any remove path
- explicit human choice when branch-name collision requires reuse or rename
Process
- Confirm the current directory belongs to the intended Git repository.
- If repo-root validation fails, return
BLOCKED, tell the operator to switch to the correct repository, and make no worktree mutation.
- If repo-root validation fails, return
- Resolve the requested lifecycle operation exactly as one of
create,get-worktree,release worktree, orremove worktree.- If the intent is ambiguous (for example, "clean up this worktree"), stop and ask whether the user means
release worktreeorremove worktree.
- If the intent is ambiguous (for example, "clean up this worktree"), stop and ask whether the user means
- Resolve the target worktree or branch selector.
- Determine managed status from path policy first.
- Surface a planner / observer coordination warning whenever shared planning, governance, or other cross-worktree files may be touched.
- For
create:- Build the managed path as
../<repo-name>.worktrees/<prefix>-YYYYMMDD-<worktree-name>. - Keep the managed worktree outside the repository root.
- If the target path already exists and is not the intended worktree, stop for human review instead of improvising.
- If the preferred branch name already exists, stop for an explicit reuse-or-rename decision; do not silently reuse the lineage.
- Create the branch and worktree only after the path and branch decisions are unambiguous.
- Return at least this contract:
create_result: path: "../<repo-name>.worktrees/<prefix>-YYYYMMDD-<worktree-name>" branch: "<branch-name>" next_step: "cd <path> && continue work inside this worktree"
- Build the managed path as
- For
get-worktree:- Inspect the requested worktree or the relevant known worktrees.
- For every reported worktree, return
path,branch,status,dirty state,recommendation,reason, andnext safe action. - Route dirty, untracked, unpushed, detached, locked, unmanaged, or otherwise ambiguous states to
needs-human-decision. - Route a missing path that Git still records as a worktree to
prune-candidatewith a reason and a safe follow-up action. - Do not auto-prune stale registrations.
- For
release worktree:- Treat release as non-destructive offboarding from the active working set.
- Fill the fixed
release_evidenceschema before deciding whether release is safe. - Keep
destructive_action_allowed: falseby default. - Require a clean worktree, no untracked files, and merged or explicitly abandoned lineage before recommending release.
- Never use release as a synonym for remove.
- For
remove worktree:- Require explicit human destructive approval.
- Re-check safety signals before removal: clean state, no untracked files, no unresolved branch ambiguity, and no lock or unknown state.
- Do not remove by default when state is dirty, untracked, unpushed, detached, locked, unmanaged without explicit authorization, or otherwise unclear.
- If safety signals fail, return
needs-human-decisioninstead of forcing deletion.
- For unmanaged worktrees:
- Allow inspect and status reporting.
- Do not automatically release, remove, delete, prune, rename a branch, or assume the task is done.
- If the human explicitly authorizes a destructive path, restate that the worktree is unmanaged and require the full remove safety gate before proceeding.
Examples
- Positive: Create a managed task worktree, return the managed path, attached branch, and the immediate next step to continue work inside that worktree.
- Negative: Treat "release worktree" as permission to delete the directory, silently reuse an existing branch, or clean up an unmanaged worktree without an explicit destructive gate.
Outputs
create_result: managedpath, attachedbranch, and immediatenext_stepget_worktree_result: entries withpath,branch,status,dirty state,recommendation,reason, andnext safe actionrelease_evidence: recorded evidence plus the release recommendation that keeps destructive action separaterouting_result:BLOCKED,needs-human-decision, orprune-candidaterouting when safety rules require escalation- a shared-file coordination warning when multiple worktrees may touch the same planning or governance files
Validation
Required Checks
- repo-root validation passes before any create, get-worktree, release, or remove action
createuses the canonical managed path family and keeps the worktree outside the repository rootcreate_resultincludespath,branch, andnext_stepget-worktreeoutput includespath,branch,status,dirty state,recommendation,reason, andnext safe actionfor every reported worktreerelease worktreerecords the fullrelease_evidenceschema and keepsdestructive_action_allowed: falseunless a separate remove path is explicitly authorizedrelease worktreeandremove worktreeremain distinct operations- risky states route to
needs-human-decisioninstead of destructive automation - missing-path-but-registered worktrees route to
prune-candidateand are not auto-pruned - unmanaged worktrees stay inspect-only by default
- branch collisions stop for an explicit reuse-or-rename decision
Quality Checks (best effort)
- selector resolution is explicit enough that another agent could inspect the same target without guessing
reasonexplains why the recommendation was chosen instead of only naming the statusnext safe actionis concrete and non-destructive when the state is ambiguous- the shared-file coordination warning names the planner / observer responsibility when shared files are present or likely
On Soft Fail
- mark the result as
INCOMPLETE - continue with the safest best-effort inspection or guidance that does not mutate state
- list the missing information, blocked checks, or execution limits explicitly
Failure Handling
Missing Context
- mark the result as
INCOMPLETE - state which selector, branch name, release evidence field, or destructive approval is missing
- do not guess missing branch lineage or destructive intent
Ambiguous Requirement
- if the ambiguity changes whether the path is
create,release worktree, orremove worktree, returnBLOCKEDand ask for clarification - if the ambiguity is non-destructive, proceed with inspection-only guidance and list the assumption explicitly
Execution Limitation
- state the limitation explicitly in the result
- do not fabricate Git state, branch status, or release evidence
- prefer
get-worktreestyle inspection guidance over risky mutation when commands or selectors cannot be verified
Verification
- After
create, verify the worktree path exists, the branch is attached as intended, and the returnednext_steppoints into that worktree. - After
get-worktree, verify each reported worktree includes the full fixed field set. - Before
release worktreeorremove worktree, verify that the evidence and safety gates still match the latest observed state.
Red Flags
- the user says "clean up" without specifying
release worktreeorremove worktree - the preferred branch name already exists
- the worktree path sits outside the canonical managed family but the request assumes the skill owns it
- Git still records a worktree whose path is missing
- multiple active worktrees may edit the same planning or governance files
Common Rationalizations
- "Release and remove are basically the same."
- "The branch already exists, so just reuse it."
- "This unmanaged path looks close enough to the managed convention."
- "A stale registration can be auto-pruned without asking."
Boundaries
- Do not perform feature implementation, merge, push, branch deletion, PR management, or release-tag handling.
- Do not place managed worktrees inside the repository root.
- Do not silently convert
release worktreeintoremove worktree. - Do not auto-prune stale registrations during
get-worktree. - Do not assume unmanaged worktrees are safe to modify or delete.
- Do not bypass the reuse-or-rename gate when a branch name collides.
Local references
reference.md: stable terminology, selector rules, managed-path policy, recommendation matrix detail, and release evidence schemaexamples.md: detailed positive, negative, and edge-case scenarios for create, get-worktree, release, and removechecklist.md: repeatable pre-create, pre-release, pre-remove, unmanaged-worktree, and non-repo safety checks