remove-worktree — Claude Code slash command: what it does
remove-worktree deletes a worktree by branch name: the directory, the git entry and the local branch. Useful when merged branches leave copies behind.
CC-BY-SA-4.0 ★ 6,529 updated 2026-10-22
.claude/commands/remove-worktree.mdWhat remove-worktree does
Pass a branch name and the command tears down that worktree: the directory under .worktrees/, the git entry and the local branch. Slashes in the name turn into dashes when the script builds the path. Drop it at .claude/commands/remove-worktree.md for Claude Code or ~/.codex/prompts/remove-worktree.md for Codex.
A bash script does the work, with haiku set in the frontmatter. No argument means it prints the available worktrees and stops. It also refuses the repo root, main and develop. Unmerged branch? Then it asks first, and anything except y aborts with files untouched.
Cleanup runs git worktree remove, falling back to rm -rf plus git worktree prune when git balks. The branch goes next: git branch -d if merged, git branch -D if not, so for the second case git skips its merge check. Remaining worktrees are listed at the end.
What it helps with
- clear out a worktree once its pull request merges
- reclaim disk space from forgotten branch checkouts
- delete a local branch together with its directory
- check which worktrees are still registered
- block accidental removal of
mainordevelop
Example prompts for the agent
- Run
/remove-worktree feature/login-formand list what is left. /remove-worktree fix/typo-readme— drop that worktree and its branch.- Call
/remove-worktree hotfix/payments; ask me before deleting if the branch is unmerged.
How to install remove-worktree
Manually: put the files in place
.claude/commands/remove-worktree.mdCall it with /remove-worktree. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/remove-worktree.mdCall it with /prompts:remove-worktree. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/remove-worktree.prompt.mdManually: put the files in place
.gemini/commands/remove-worktree.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about remove-worktree
How do I install remove-worktree in Claude Code?
Copy the command file into the project at .claude/commands/remove-worktree.md, then call /remove-worktree in a session.
What does remove-worktree do?
Takes a branch name and removes its worktree: directory, git entry and local branch. It prints the worktrees that remain.
What happens when the branch is not merged into main?
You get a warning and a y prompt. Any other answer cancels the run, and on agreement the branch is dropped with git branch -D.