clean-up-worktree
Skill0 starsChanged 3 months agoMITView on GitHub
Safely remove an explicitly named local Git worktree and optionally its local branch after the user authorises cleanup of an integrated or handed-off candidate, or deliberately abandons planning or research. Use only after material work and evidence are preserved. Do not use for integration, inferred lifecycle transitions, remote branch deletion, canonical-checkout removal, or forced loss of unreviewed work or user data.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- capture-project-intakeSkill
- coordinate-parallel-workSkill
- deliver-project-workSkill
- develop-projectSkill
- integrate-reviewed-changeSkill
- investigate-projectSkill
- manage-project-workSkill
- map-project-planningSkill
- release-projectSkill
- review-project-changeSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Read the root AGENTS.md, the contributing guide, and the canonical workflow.
- Distinctive: line 62
If no finding merits retention, say so explicitly rather than creating noise.
- Very specific: line 63
When a tracked card exists, use manage-project-work for the separately named close, reject, accept, or return transition.
- Distinctive: line 68
Stop and report the exact blocker if any identity, preservation, or authority check fails.
- Distinctive: line 73
Remove the exact worktree through Git without a force flag, then verify that its registration and path are gone.
- Distinctive: line 75
Delete only the explicitly authorised local branch.
- Distinctive: line 81
Do not run broad pruning or delete another stale worktree as a side effect.
- Distinctive: line 82
Leave every remote ref untouched.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean Up a Worktree
Execution mode
inline
Confirm the exact local cleanup
- Read the root
AGENTS.md, the contributing guide, and the canonical workflow. Read the research archive for an abandoned planning or research workspace. - Require an explicit user request or an unambiguous agreement to a cleanup
offer that names the local worktree and branch. Classify the outcome as:
- an accepted reviewed candidate whose integration or handoff is complete, or untracked work the user explicitly declared complete; or
- planning or research the user deliberately chose to abandon.
- Resolve the exact worktree path, attached branch, current commit, coordinating checkout, common base when relevant, and any associated card or review evidence. Never select a target from a guessed path, wildcard, or stale lane name.
- State every proposed effect before acting. One confirmation may authorise a named lifecycle change, findings record, worktree removal, and local branch deletion only when each effect is listed explicitly.
Local cleanup authority never includes push, remote branch deletion, tag, release, history rewriting, or deletion of durable review evidence. Do not offer cleanup merely because review or acceptance completed; acceptance or an explicit completion decision and the integration, handoff, or deliberate abandonment must all be established.
Prove that removal will not lose work
- Refuse to remove the coordinating or canonical checkout. Confirm the target appears exactly once in Git's worktree inventory and that the named branch is checked out only there.
- Inspect tracked, untracked, and ignored content. Do not use forced worktree removal to bypass dirtiness, a lock, nested repository state, unreadable files, or uncertainty about user data.
- For an integrated candidate, verify that the branch still identifies the reviewed commit, the user accepted or explicitly declared the work complete, the recorded integration result contains the reviewed scope, and no later or unique work exists. Use ancestry for merge or fast-forward integration; for squash or cherry-pick, use the recorded commit mapping and patch comparison rather than pretending ancestry proves equivalence.
- For completed handoff, verify the recipient preserves the exact pinned candidate under a durable reference independent of the local branch and that the returned evidence no longer depends on the local worktree.
- For deliberate abandonment, inspect every commit and local change since the common base. Summarise what would be discarded and stop unless the user's authority clearly covers it.
- Preserve material abandoned findings in the narrowest durable Markdown owner
in the coordinating checkout. Use project documentation for current claims,
an ADR for a consequential durable decision, or
../../RESEARCH.mdfor a useful negative or exploratory result. Checkpoint that record before cleanup. If no finding merits retention, say so explicitly rather than creating noise. - When a tracked card exists, use
manage-project-workfor the separately named close, reject, accept, or return transition. Cleanup authority alone does not alter queues or boards.
Stop and report the exact blocker if any identity, preservation, or authority check fails. Never delete first and investigate afterwards.
Remove in recoverable order
- Remove the exact worktree through Git without a force flag, then verify that its registration and path are gone.
- Delete only the explicitly authorised local branch. Prefer normal deletion when Git recognises it as merged. Force-delete it only when the completed preflight proves a squash or cherry-pick integration, proves a completed handoff retains the exact commit under an independent durable reference, or proves deliberate abandonment with all material findings and work preserved, and the user explicitly authorised that branch's deletion.
- Do not run broad pruning or delete another stale worktree as a side effect. Leave every remote ref untouched.
- Report the findings record or evidence retained, the exact local worktree and branch removed, any partial failure, and that remote branches were not changed. State whether recovery still depends on a recorded commit or reflog.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

