Skip to main content
command CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/remove-worktree.md
Open on GitHub

What 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 main or develop

Example prompts for the agent

  • 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.

How to install remove-worktree

Manually: put the files in place

.claude/commands/remove-worktree.md

Call it with /remove-worktree. For all projects use ~/.claude/commands/

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.

Similar slash commands

All slash commands for Git and GitHub →

From the same set45

The whole set →
update-threat-db update-threat-db — a skill for Claude Code and Codex that refreshes threat intelligence and IOC feeds via AgentSec Triage. Synchronizes security advisories for coding agents and MCP tools. CX Codex +1 ★ 6,529repo stars source-command-sync source-command-sync runs a sync check between the guide repository and its landing page, then shows which counters drifted. Handy when the site is generated from repo data. CX Codex +1 ★ 6,529repo stars guide-reviewer guide-reviewer audits technical documentation drafts for factual errors, marketing buzzwords, and AI phrasing patterns before committing. CX Codex ★ 6,529repo stars update-threat-db The update-threat-db command delegates threat database changes to AgentSec and checks the resulting feed, catalogue, and compatibility data. CX Codex +1 ★ 6,529repo stars clean-worktrees clean-worktrees cleans up Git worktrees for branches already merged into main. Useful after landing pull requests to reclaim disk space without prompt fatigue. CX Codex +1 ★ 6,529repo stars park park stores the active session in a Markdown file so work can resume after a restart. It is made for Claude Code and Codex workflows. CX Codex +1 ★ 6,529repo stars worktree Creates a separate git worktree folder for feature or fix branches. Useful when you need to work on multiple tasks in parallel without conflicts in your main branch. CX Codex +1 ★ 6,529repo stars worktree-status worktree-status is a Claude Code command that reports the branch, path, commit hash, and modified-file count for each active git worktree. CX Codex +1 ★ 6,529repo stars

Project sponsors

Companies that keep this analytics open