Worktree cleanup
A cleanup request starts the complete analysis, not deletion. Read applicable
AGENTS.md and the project worktree/hosting runbooks first. Resolve repository
roots, worktree locations, release and environment targets, ownership, ignored-file
policy and managed-worktree lifecycle. Never assume a branch name or directory.
Skills supply decision criteria; the runbook supplies project commands and execution
order. Missing inputs block only dependent conclusions, not independent inspection.
Analyze all worktrees before asking for approval
- Inventory all registered worktrees in scope with
git worktree list --porcelain -z, parsing paths safely. Include primary, detached, locked and missing
directories. Identify ownership, current cwd, active processes/editor use and
dependencies between directories, including node_modules links. Do not create
a checkout merely to match the number of open MRs. Read-only history/diff
analysis needs no new worktree. Delegate bounded content analysis to a subagent
when useful and available; consolidate its evidence into this chat.
- Fetch refs from verified remotes and read current open MRs/PRs. Pin relevant
release/environment SHAs and record stale or unavailable evidence. Inspect
tracked/untracked changes, ongoing Git operations and ignored-file names.
Distinguish generated caches/dependencies from valuable settings, notes and
env files; never print secrets or read secret contents for this inventory.
- Establish purpose and actual content: product task, delivery, synchronization,
baseline or release candidate. Names and MR labels are clues, not proof.
Explain what the work does and where it is retained. A completed delivery
retained in an environment branch can lose its checkout without claiming the
feature reached release; preserve the source of an open release MR or unique
unfinished work. Preserve the primary checkout even when dirty.
- Investigate uniqueness using ancestry, history, patches and resulting content
against relevant retained refs. Distinguish command errors from negative
ancestry results. For squash/rebase/cherry-pick, differing SHAs alone do not
establish unique work. Review merge resolutions and reflog-only commits for
useful changes versus reproducible temporary integration. Neither reflog
presence nor patch equivalence alone decides removal. For forgotten work,
explain the behavior missing from published refs and whether it could form a
separate MR; do not create one without authorization.
- Complete available investigation before presenting decisions. Preserve genuine
unique work and active tasks; propose removing completed task checkouts after
confirmed release integration and completed temporary checkouts once useful
work is retained or demonstrably reproducible. Current cwd alone is not a
retention reason: plan to move to a surviving checkout. An unavailable source
must be a specific evidence gap, not a generic "needs investigation" verdict.
Present the plan and wait
Return a self-contained table in the current chat; do not create a Markdown report
unless requested. Every directory must be identifiable, even when grouping similar
deliveries. Show full paths/SHAs only where needed to distinguish objects or decide.
| Worktree / task |
What it contains |
MR and where work is retained |
Unique local changes |
Keep/remove and reason |
Include the concrete removal list, preservation steps, dependency order and any
specific questions about possible data loss. Do not substitute "not in release"
or "has reflog" for explaining the actual work. Separate worktree removal, local
branch deletion and remote branch deletion; approval for one does not imply another.
Stop after this analysis and plan, including for a broad cleanup request. Wait for
user confirmation or corrections before deleting. An analysis-only request remains
read-only and does not require prompting the user to authorize execution. Incorporate corrections into
the scope; do not ask again for each already-approved directory or dependency.
Execute the agreed plan
- Recheck candidate HEADs, relevant refs, files, Git operations, locks, active use
and directory dependencies immediately before removal. Reassess changed items;
pause affected removals for newly discovered data-loss risk or expanded scope.
Continue the independent approved portion. Never kill another user's processes.
- Preserve needed files/history by the agreed method. Do not silently stash,
discard settings/env files, unlock worktrees or treat all ignored files as
disposable. Include dependent directories in the agreed ordering and verify
retained checkouts do not depend on removed dependencies.
- Move out of a checkout before removing it. For ordinary Git worktrees use
git worktree remove <exact-path> without force. For runtime-managed worktrees
use the supported archive/removal lifecycle and verify what its snapshot
preserves; needed ignored files may require separate preservation. Refusal is
not permission for force, reset, git clean or recursive directory deletion.
- Detached HEADs and reflog-only work need evidence of retention or reviewed
reproducibility, not an automatic permanent checkout. Investigate locked or
missing registrations explicitly; do not use blanket prune. Delete local or
remote branches only within separately authorized scope and fresh use checks.
- Verify registrations, directory removal and surviving dependencies. Report
removed, kept and blocked items in chat. Do not equate cleanup with feature
delivery, issue completion or a background cleanup service.
1---2name: clean-worktrees3description: Analyze all project worktrees, explain their contents and propose removals in chat, then execute after the user confirms or adjusts the plan. Use when asked to clean up worktrees; branch deletion is separate.4metadata:5 source: https://skillmd.com/skills/gertyhiler/clean-worktrees6---78# Worktree cleanup910A cleanup request starts the complete analysis, not deletion. Read applicable11AGENTS.md and the project worktree/hosting runbooks first. Resolve repository12roots, worktree locations, release and environment targets, ownership, ignored-file13policy and managed-worktree lifecycle. Never assume a branch name or directory.14Skills supply decision criteria; the runbook supplies project commands and execution15order. Missing inputs block only dependent conclusions, not independent inspection.1617## Analyze all worktrees before asking for approval18191. Inventory all registered worktrees in scope with `git worktree list --porcelain20 -z`, parsing paths safely. Include primary, detached, locked and missing21 directories. Identify ownership, current cwd, active processes/editor use and22 dependencies between directories, including node_modules links. Do not create23 a checkout merely to match the number of open MRs. Read-only history/diff24 analysis needs no new worktree. Delegate bounded content analysis to a subagent25 when useful and available; consolidate its evidence into this chat.262. Fetch refs from verified remotes and read current open MRs/PRs. Pin relevant27 release/environment SHAs and record stale or unavailable evidence. Inspect28 tracked/untracked changes, ongoing Git operations and ignored-file names.29 Distinguish generated caches/dependencies from valuable settings, notes and30 env files; never print secrets or read secret contents for this inventory.313. Establish purpose and actual content: product task, delivery, synchronization,32 baseline or release candidate. Names and MR labels are clues, not proof.33 Explain what the work does and where it is retained. A completed delivery34 retained in an environment branch can lose its checkout without claiming the35 feature reached release; preserve the source of an open release MR or unique36 unfinished work. Preserve the primary checkout even when dirty.374. Investigate uniqueness using ancestry, history, patches and resulting content38 against relevant retained refs. Distinguish command errors from negative39 ancestry results. For squash/rebase/cherry-pick, differing SHAs alone do not40 establish unique work. Review merge resolutions and reflog-only commits for41 useful changes versus reproducible temporary integration. Neither reflog42 presence nor patch equivalence alone decides removal. For forgotten work,43 explain the behavior missing from published refs and whether it could form a44 separate MR; do not create one without authorization.455. Complete available investigation before presenting decisions. Preserve genuine46 unique work and active tasks; propose removing completed task checkouts after47 confirmed release integration and completed temporary checkouts once useful48 work is retained or demonstrably reproducible. Current cwd alone is not a49 retention reason: plan to move to a surviving checkout. An unavailable source50 must be a specific evidence gap, not a generic "needs investigation" verdict.5152## Present the plan and wait5354Return a self-contained table in the current chat; do not create a Markdown report55unless requested. Every directory must be identifiable, even when grouping similar56deliveries. Show full paths/SHAs only where needed to distinguish objects or decide.5758| Worktree / task | What it contains | MR and where work is retained | Unique local changes | Keep/remove and reason |59| --- | --- | --- | --- | --- |6061Include the concrete removal list, preservation steps, dependency order and any62specific questions about possible data loss. Do not substitute "not in release"63or "has reflog" for explaining the actual work. Separate worktree removal, local64branch deletion and remote branch deletion; approval for one does not imply another.6566Stop after this analysis and plan, including for a broad cleanup request. Wait for67user confirmation or corrections before deleting. An analysis-only request remains68read-only and does not require prompting the user to authorize execution. Incorporate corrections into69the scope; do not ask again for each already-approved directory or dependency.7071## Execute the agreed plan72731. Recheck candidate HEADs, relevant refs, files, Git operations, locks, active use74 and directory dependencies immediately before removal. Reassess changed items;75 pause affected removals for newly discovered data-loss risk or expanded scope.76 Continue the independent approved portion. Never kill another user's processes.772. Preserve needed files/history by the agreed method. Do not silently stash,78 discard settings/env files, unlock worktrees or treat all ignored files as79 disposable. Include dependent directories in the agreed ordering and verify80 retained checkouts do not depend on removed dependencies.813. Move out of a checkout before removing it. For ordinary Git worktrees use82 `git worktree remove <exact-path>` without force. For runtime-managed worktrees83 use the supported archive/removal lifecycle and verify what its snapshot84 preserves; needed ignored files may require separate preservation. Refusal is85 not permission for force, reset, git clean or recursive directory deletion.864. Detached HEADs and reflog-only work need evidence of retention or reviewed87 reproducibility, not an automatic permanent checkout. Investigate locked or88 missing registrations explicitly; do not use blanket prune. Delete local or89 remote branches only within separately authorized scope and fresh use checks.905. Verify registrations, directory removal and surviving dependencies. Report91 removed, kept and blocked items in chat. Do not equate cleanup with feature92 delivery, issue completion or a background cleanup service.