worktree-exit

Removes a git ticket worktree completely after moving the session back to the repository root.

Updated Jul 7, 2026
One-click install
npx skills add https://github.com/bbenefield89/skills --skill worktree-exit-bbenefield89
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: worktree-exit
Source: https://github.com/bbenefield89/skills/tree/main/skills/worktree-exit
Command: npx skills add https://github.com/bbenefield89/skills --skill worktree-exit-bbenefield89

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Cleaning up a git worktree on Windows often fails because the active session holds a directory handle, so git worktree remove deletes the files but leaves a locked empty folder behind. This Skill moves the session out of the worktree, verifies no uncommitted or unpushed work is lost, and removes the directory completely. ## Core Features & Use Cases - Safe pre-checks: Verifies git status is clean and no unpushed commits exist before removing anything. - Session relocation: Moves the session back to the repository root via the deferred MCP directory tool before removal. - Locked-folder recovery: Runs a detached PowerShell retry loop that deletes the folder once the session's handle is released, handling the Windows "Permission denied" and "being used by another process" errors. - Use Case: After merging a pull request, ask to clean up the ticket worktree; the session returns to the repo root and the worktree directory is fully removed while the local branch is preserved. ## Quick Start Clean up the worktree for ticket PROJ-123 and move this session back to the repository root.

Frequently Asked Questions about worktree-exit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I remove a git worktree that says Permission denied?

Move the active session out of the worktree directory first, then run git worktree remove from the repository root. If the empty folder remains locked, run a detached retry loop that deletes it once the session releases its directory handle.

Why does git worktree remove leave an empty folder on Windows?

The session itself holds a directory handle on the worktree path, so git deletes the contents and deregisters the worktree but cannot remove the folder. The handle drops shortly after the session moves away, allowing a delayed deletion to succeed.

How do I check a worktree is safe to delete without losing work?

Run git status --porcelain and git log --oneline origin/<branch>..HEAD inside the worktree. Both must print nothing, confirming there are no uncommitted changes and no unpushed commits before removal.

Does removing a worktree delete the local branch?

No, removing a worktree only deletes the working directory and its git registration. The local branch stays in place so the open pull request remains valid, and it is deleted only when explicitly requested.

Should I use git worktree remove --force when the folder is locked?

No, adding --force to defeat the lock can corrupt the git admin state. Instead let the command fail, then use a detached retry loop to remove the folder after the session handle is released, and run git worktree prune to tidy leftovers.