worktree-cleanup
Skill6 starsChanged 47 days agoMITView on GitHub
Create and tear down git worktrees for tickets and lanes. Use to run a ticket in isolation off the default branch, and to clean up after it lands or is abandoned — removing a per-ticket worktree, but keeping a lane worktree and deleting only the merged ticket branch.
- Commits and pushes
10 other projects use a version of this.
Adopted by
Most recently taken up by
- anotherben/claude-harnesstheir own version, first seen Nov 8, 2026
- perber/leafwikitheir own version, first seen Oct 17, 2026
- TentacleOpera/switchboardtheir own version, first seen Oct 8, 2026
- dstotijn/agent-skillstheir own version, first seen Sep 21, 2026
- syanga/astacktheir own version, first seen Sep 20, 2026
- Jador/skillstheir own version, first seen Aug 27, 2026
Used with
Projects with it also use handoff.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillhandoff
Compact the current conversation into a handoff document for another agent to pick up.
Also in 4 projects that use this
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- perber/leafwiki★ 1.2ksame name
- TentacleOpera/switchboard★ 215same name
- anotherben/claude-harness★ 7same name
- dstotijn/agent-skills★ 1same name
- Jador/skills★ 1same name
- jelbirt/LLM-Skill-Build★ 1same name
- luw2007/skills★ 1same name
- EdenGibson/claude-skills★ 0same name
- Enverge-Labs/skills★ 0same name
- syanga/astack★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository24 other files it gives its agents.
- docs/AGENTS.mdAGENTS.md
- atomic-reportSkill
- board-validateSkill
- data-modelSkill
- delivery-hygieneSkill
- dev-reportSkill
- dev-setupSkill
- frontend-qualitySkill
- gcSkill
- git-branchSkill
- land-and-archiveSkill
- orchestration-healthSkill
- orchestratorSkill
- pipeline-qualitySkill
- plan-updateSkill
- project-planSkill
- release-gateSkill
- repo-auditSkill
- scaleSkill
- security-reviewSkill
- swarmSkill
- test-coverageSkill
- tpmSkill
- trackerSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 4 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Fast path: if the main checkout already has a good, up-to-date install, link it in rather than reinstalling from scratch:
- Very specific: line 34
Otherwise: run the dev-setup skill's install step inside the new worktree first.
- Very specific: line 36
Run the ticket's agent_plan inside ../.maestro-wt/T-014/.
- Distinctive: line 73
Keep the worktree: Don't git worktree remove it.
- Distinctive: line 89
Remove a lane's worktree only when the lane itself is retired — its queue is empty and nothing will be scheduled onto it — and then only …
- Very specific: line 102
Keep worktrees under one predictable parent dir (e.g.
- Distinctive: line 104
Never remove a worktree with uncommitted work you didn't create — inspect it first.
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Worktree Cleanup
Each ticket runs in its own git worktree so parallel tickets never collide and a bad branch never dirties your main checkout. This skill covers both ends: create, and clean up.
Create a worktree for a ticket
Resolve the default branch — don't hardcode origin/main; plenty of repos default to
master (or something else) and a hardcoded ref fails on them:
git fetch origin
git remote set-head origin -a # in case the clone skipped setting origin/HEAD
default_branch=$(git symbolic-ref --short refs/remotes/origin/HEAD | sed 's@^origin/@@')
git worktree add ../.maestro-wt/T-014 -b feat/T-014-rate-limit-api "origin/$default_branch"Bring its dependencies with it. A fresh worktree has the tracked code but none of the
gitignored install output (node_modules, .venv, vendor caches) — nothing installs it
automatically, and a ticket dispatched into a worktree that can't build or run tests is a
wasted run. Before dispatching work:
- Fast path: if the main checkout already has a good, up-to-date install, link it in
rather than reinstalling from scratch:
(or the language equivalent: aln -s /absolute/path/to/main/checkout/node_modules node_modules.venvsymlink, a shared package-manager cache, …). - Otherwise: run the
dev-setupskill's install step inside the new worktree first.
Run the ticket's agent_plan inside ../.maestro-wt/T-014/. The main checkout stays clean.
Clean up after landing or abandoning
After a ticket lands (merged) — only when the worktree is not a lane (see Lanes below):
git worktree remove ../.maestro-wt/T-014 # removes the worktree dir
git branch -d feat/T-014-rate-limit-api # delete the merged local branch
git push origin --delete feat/T-014-rate-limit-api # if it was pushedWhen a ticket is abandoned (branch never merged): same, but use git worktree remove
--force and git branch -D since the branch has unmerged commits you're intentionally
dropping. Confirm you're discarding the right branch first — read what's on it, don't
force-remove blind.
Lanes: a worktree that outlives its ticket
With orchestration.maxWorktrees set, work runs in lanes (see maestro lanes and the
swarm skill). A lane is a persistent worktree that runs a queue of tickets one at a time,
landing each before starting the next. The worktree belongs to the lane, not to any one ticket,
so the per-ticket teardown above would delete live work for the tickets still queued behind it.
The kit fixes no directory name for a lane worktree, so identify it by what it has checked out, not by its path:
git worktree list --porcelain # each entry's `worktree` path and its `branch`A worktree is a lane when the lane plan (maestro lanes) or the running swarm still has
tickets queued on it. When in doubt, treat it as a lane and leave it in place.
After a lane's ticket lands:
- Keep the worktree. Don't
git worktree removeit. - Delete only the merged ticket branch, locally and on the remote:
git branch -d feat/T-014-rate-limit-api git push origin --delete feat/T-014-rate-limit-api # if it was pushedgit branch -drefuses a branch that is still checked out, so first move the lane onto the next ticket (step 3) or detach it (git -C <lane-worktree> switch --detach). - Re-base the lane for its next ticket by branching fresh off the updated default branch
inside the same worktree (resolve
default_branchas above):
Refresh dependencies there if the lockfile changed (see "Bring its dependencies with it").git -C <lane-worktree> fetch origin git -C <lane-worktree> switch -c feat/T-015-next-ticket "origin/$default_branch"
Remove a lane's worktree only when the lane itself is retired — its queue is empty and nothing will be scheduled onto it — and then only after the checks in "Hygiene" below.
Hygiene
- List and prune regularly:
git worktree list # see everything checked out git worktree prune # drop administrative entries for deleted dirs - A per-ticket worktree that's been idle across many tickets is a smell — either it's live work that should be on the board, or it's abandoned and should be removed. A lane worktree that has hosted many tickets is normal; judge it by its current branch, not its age.
- Keep worktrees under one predictable parent dir (e.g.
../.maestro-wt/) so they're easy to find and never accidentally committed into the repo. - Never remove a worktree with uncommitted work you didn't create — inspect it first; it may be another session's in-flight ticket.
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.

