name: "worktree-management"
description: "Use to isolate Git tasks in separate worktrees and avoid overwriting unrelated user work."
maturity-level: "L4"
risk-scope: "R0-R4"
version: "1.0.0"
Worktree Management
Core Question
Should this task use the current working tree or a separate Git worktree, and how can that worktree be created or removed safely?
When To Use
Use this skill when:
- the current working tree has unrelated work and a new task is requested
- the user wants to work on multiple branches concurrently
- the agent needs an isolated workspace for a risky or long-running task
- the user asks to list, create, prune, or remove worktrees
When Not To Use
Do not use this skill when:
- normal branch switching in a clean tree
- destructive recovery of lost commits
- conflict resolution inside a worktree
- commit planning inside a worktree
Route to:
- simple branch work routes to
branch-workflow - recovery or destructive cleanup routes to
undo-recover - conflicts inside a worktree route to
resolve-conflicts - commit work inside the selected worktree routes to
atomic-commits
Required Evidence
Before action, inspect or establish:
git worktree list --porcelain- current branch and path
- target branch or task name
- dirty state in current and target worktree
- path existence and ownership
- remote branch relationship if creating from remote
No-evidence rule:
- Do not make strong claims without observed evidence.
- State assumptions when proceeding under incomplete evidence.
- Stop when missing evidence affects safety, correctness, user work, remote state, or irreversible action.
Operating Contract
You MAY:
- inspect relevant repository state and project files.
- generate a plan, report, or local artifact within the declared risk scope.
- route to another skill when the requested action is outside this skill's owner boundary.
You MUST:
- inspect before acting.
- keep the task within the declared owner boundary.
- classify state and risk before any meaningful action.
- preserve unrelated user work.
- verify outcomes proportional to risk.
- report evidence, assumptions, actions, verification, and residual risk.
You MUST NOT:
- invent project policy.
- expose secrets or sensitive values.
- mutate unrelated files or refs.
- perform destructive, remote, shared, history-rewriting, or irreversible actions without explicit action-specific confirmation.
- continue after unexpected destructive output.
State / Risk Table
| State | Evidence | Risk | Default Action | Confirmation | Verification |
|---|
| Dirty current tree and unrelated new task | status plus user task | R1/R2 | Recommend separate worktree | no | worktree plan |
| Create new worktree | target path and branch evidence | R2/R4 | Create only with explicit path/branch/source | yes for remote branch creation | worktree list and status |
| Existing worktree for branch | worktree list | R1 | Reuse or report current mapping | no | path and branch shown |
| Remove clean worktree | worktree list and status | R3 | Remove only exact clean path after confirmation | yes | worktree list after removal |
| Remove dirty worktree | worktree status | R5 | Stop; route recovery or preserve work first | yes + recovery | status preserved |
Workflow
- Identify the user goal and current owner boundary.
- Inspect required evidence.
- Classify repository/task state.
- Classify risk using the declared scope.
- Choose the minimal sufficient action or route.
- Execute only allowed actions, if any.
- Verify outcome or self-check the artifact.
- Report result, evidence, verification, assumptions, and residual risk.
Decision Rules
- Prefer worktree isolation when the current tree contains unrelated human work.
- Do not remove a worktree until its status has been inspected.
- Do not reuse a dirty worktree for an unrelated task.
- Name worktrees by task or branch to improve auditability.
- May inspect and list worktrees.
- May create a worktree after explicit branch/path intent.
- Must not remove dirty worktrees.
- Must not delete branches or remote refs from this skill.
Verification
Minimum verification:
- Verify worktree path, branch, and status after creation or removal.
- Report residual dirty state.
- Confirm no unrelated worktree was modified.
Risk-based floor:
- R0-R1: evidence inspected and output self-checked.
- R2: inspect resulting diff or local state.
- R3: verify local state and report recovery limits.
- R4-R5: require explicit confirmation, preflight evidence, and post-action verification where this skill owns the action.
Output Contract
Final response must include:
## Result
- Decision, action, or artifact produced.
## Evidence
- Files, commands, diffs, refs, or assumptions used.
## Verification
- Checks performed and their result.
## Risks / Limitations
- Remaining uncertainty, blocked actions, or routed next steps.
Stop / Confirmation Rules
Stop when the repository state is dirty, conflicted, diverged, missing required evidence, or ambiguous in a way that could overwrite user work, invalidate the requested scope, or require a gated action.
Require explicit action-specific confirmation for:
- destructive local mutation.
- remote/shared mutation.
- history rewriting.
- security/secret/data impact.
- irreversible or hard-to-recover operation.
Broad approval such as "do whatever" is not enough for R4-R5 actions.
Lazy-load References
Load references/worktree-lifecycle.md when:
- the task needs the detailed guidance described by the file name.
- the state/risk table identifies an ambiguous or high-risk path.
Load references/isolation-patterns.md when:
- the task needs the detailed guidance described by the file name.
- the state/risk table identifies an ambiguous or high-risk path.
Load references/cleanup.md when:
- the task needs the detailed guidance described by the file name.
- the state/risk table identifies an ambiguous or high-risk path.