# remove-worktree

remove-worktree deletes a worktree by branch name: the directory, the git entry and the local branch. Useful when merged branches leave copies behind.

- command · `type=command` · Claude Code, Codex, GitHub Copilot, Gemini CLI · ★ 6529 repo stars
- Author: FlorianBruniaux
- License: CC-BY-SA-4.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/FlorianBruniaux/claude-code-ultimate-guide/tree/HEAD/.claude/commands/remove-worktree.md
- Updated: 2026-10-22
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/commands/remove-worktree

## What it 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.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/commands/remove-worktree.md` — Call it with /remove-worktree. For all projects use ~/.claude/commands/

### Codex

**Manually: put the files in place**
- File: `~/.codex/prompts/remove-worktree.md` — Call it with /prompts:remove-worktree. Codex marks this format deprecated in favour of skills

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/prompts/remove-worktree.prompt.md`

### Gemini CLI

**Manually: put the files in place**
- File: `.gemini/commands/remove-worktree.toml` — Gemini stores commands as TOML: the prompt text goes into the prompt field

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/FlorianBruniaux/claude-code-ultimate-guide/tree/HEAD/.claude/commands/remove-worktree.md

## When to use it
- 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 `main` or `develop`

## Example prompts
- Run `/remove-worktree feature/login-form` and 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.

## Similar
- [git-worktree](https://affpapa.org/en/nevibecode/skills/git-worktree.md) — skill · 111 installs
- [branch-finalization](https://affpapa.org/en/nevibecode/skills/branch-finalization.md) — skill · 131 installs
- [ce-worktree](https://affpapa.org/en/nevibecode/skills/ce-worktree.md) — skill · 3200 installs
- [worktree-init](https://affpapa.org/en/nevibecode/commands/worktree-init.md) — command · 94 installs
- [git-worktree-isolation](https://affpapa.org/en/nevibecode/skills/git-worktree-isolation.md) — skill · 2300 installs
- [worktree-check](https://affpapa.org/en/nevibecode/commands/worktree-check.md) — command · 81 installs

From the same set: [florianbruniaux/claude-code-ultimate-guide](https://affpapa.org/en/nevibecode/by/florianbruniaux/claude-code-ultimate-guide.md) — 45 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
