agentleFS
amntoppoamntoppo/MasterDeck-Terminal/skills/kill-worktree/SKILL.md

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.

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
  1. Distinctive:

    If the main checkout itself is dirty, STOP and ask the user — checking out the worktree branch and popping a stash onto unrelated local …

    line 37
  2. Very specific:

    If the user says the work is abandoned (explicitly), the flow is different: ExitWorktree remove with discard_changes: true after confirming …

    line 68
  3. Distinctive:

    If the branch was already pushed / has an open PR, removing the local worktree changes nothing remotely — the babysit-pr monitor keeps …

    line 71

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Preserve uncommitted work (inside the worktree).
    git status --porcelain
    If dirty:
    git stash push -u -m "kill-worktree: <branch>"
    (-u includes 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).
  2. 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.
  3. Check the main checkout is safe to receive the branch.
    git status --porcelain
    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.
  4. Remove the worktree directory, keep the branch.
    git worktree remove <worktree-path>
    git worktree prune
    (Refuses if the worktree is still dirty — step 1 should have made it clean. Use --force only with explicit user approval, never to skip step 1.)
  5. Move the branch into the main checkout.
    git checkout <branch>
    (Possible only now — a branch cannot be checked out in two worktrees at once.)
  6. Restore the stash, if one was made in step 1.
    git stash list   # find the "kill-worktree: <branch>" entry
    git stash pop <that-entry>
    Pop only the stash this skill created — do not pop unrelated stashes. On conflict, resolve it and tell the user which files conflicted.
  7. Report. Branch now checked out in the main repo, uncommitted changes restored, worktree gone. Show git status as proof.

Rules

  • If the user says the work is abandoned (explicitly), the flow is different: ExitWorktree remove with discard_changes: true after 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, then git worktree remove.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.