kill-worktree
Skill4 starsChanged 25 days agoMITView on GitHub
Tear down the session's worktree while preserving all work — stash uncommitted changes, keep the branch, return the session to the main repo, check the branch out there, pop the stash, and delete the worktree directory. Use when the user says "/kill-worktree", "drop the worktree", or wants worktree work moved back to the main checkout.
In this repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- babysit-prSkill
- babysit-ticketSkill
- babysit-worktreeSkill
- masterdeck-notesSkill
- masterSkill
- queueSkill
- worktree-janitorSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
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 37
If the main checkout itself is dirty, STOP and ask the user — checking out the worktree branch and popping a stash onto unrelated local …
- Very specific: line 68
If the user says the work is abandoned (explicitly), the flow is different: ExitWorktree remove with discard_changes: true after confirming …
- Distinctive: line 71
If the branch was already pushed / has an open PR, removing the local worktree changes nothing remotely — the babysit-pr monitor keeps …
≈ “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
kill-worktree — drop the worktree, keep every change
Goal: the worktree directory is gone; its branch and any uncommitted work live on in the main checkout. Nothing is lost.
⚠ Never use ExitWorktree action:"remove" here — that deletes the branch along
with the directory. This skill exits with keep and removes the directory with git,
so the branch survives.
Steps
- Preserve uncommitted work (inside the worktree).
If dirty:git status --porcelain
(git stash push -u -m "kill-worktree: <branch>"-uincludes untracked files; stashes live in the shared repo, so this stash is visible from the main checkout.) Record the branch name:branch=$(git branch --show-current)and the worktree path (pwd). - Exit the session back to the main repo. ExitWorktree with
action: "keep"— restores the session's working directory to the original checkout, leaves the worktree and branch on disk untouched. - Check the main checkout is safe to receive the branch.
If the main checkout itself is dirty, STOP and ask the user — checking out the worktree branch and popping a stash onto unrelated local changes can conflict. Options to offer: commit/stash main's changes first, or keep the worktree instead.git status --porcelain - Remove the worktree directory, keep the branch.
(Refuses if the worktree is still dirty — step 1 should have made it clean. Usegit worktree remove <worktree-path> git worktree prune--forceonly with explicit user approval, never to skip step 1.) - Move the branch into the main checkout.
(Possible only now — a branch cannot be checked out in two worktrees at once.)git checkout <branch> - Restore the stash, if one was made in step 1.
Pop only the stash this skill created — do not pop unrelated stashes. On conflict, resolve it and tell the user which files conflicted.git stash list # find the "kill-worktree: <branch>" entry git stash pop <that-entry> - Report. Branch now checked out in the main repo, uncommitted changes restored,
worktree gone. Show
git statusas proof.
Rules
- If the user says the work is abandoned (explicitly), the flow is different:
ExitWorktree
removewithdiscard_changes: trueafter confirming — that deletes directory, branch, and changes in one step. Only on an explicit "discard it". - If the branch was already pushed / has an open PR, removing the local worktree changes nothing remotely — the babysit-pr monitor keeps running.
- Worktree entered via
path(not created this session): ExitWorktree cannot remove it anyway; same flow works —keep, thengit worktree remove.
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.

