remove_worktree_prompt — Claude Code command to remove a worktree
The remove_worktree_prompt command stops processes tied to a worktree, then removes the worktree and its Git branch. Check the branch name first: deletion cannot be undone.
no license ★ 1,573 updated 2026-02-08
.claude/commands/remove_worktree_prompt.mdWhat remove_worktree_prompt does
Pass a branch name and the command looks for its worktree under trees/. It reads server and client ports from .env files when available, then tries to stop processes using those ports. If the files are absent, it estimates ports from the number of worktrees. The command removes the worktree before deleting its branch, and checks whether both are gone. It can force either removal when the regular operation fails; both deletions are permanent.
It also checks for leftover processes, SQLite WAL files, and lock files. A directory that remains after removal is not erased automatically; the command reports that it needs manual cleanup. For Claude Code, place the command file at .claude/commands/remove_worktree_prompt.md and call it with the required <branch-name> argument.
What it helps with
- stop server and client processes using a worktree’s ports
- remove a Git worktree from
trees/ - delete the branch associated with a worktree
- verify that the directory, branch, and processes are gone
- identify leftover files and report manual cleanup needs
Example prompts for the agent
- Remove the worktree and branch for
feature-login:/remove_worktree_prompt feature-login. - Stop processes and clean up the worktree for
bugfix-header:/remove_worktree_prompt bugfix-header. - Check and remove the worktree for
experiment-api:/remove_worktree_prompt experiment-api.
How to install remove_worktree_prompt
Manually: put the files in place
.claude/commands/remove_worktree_prompt.mdCall it with /remove_worktree_prompt. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/remove_worktree_prompt.mdCall it with /prompts:remove_worktree_prompt. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/remove_worktree_prompt.prompt.mdManually: put the files in place
.gemini/commands/remove_worktree_prompt.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about remove_worktree_prompt
How do I install remove_worktree_prompt in Claude Code?
Place the command file at .claude/commands/remove_worktree_prompt.md.
What does remove_worktree_prompt do?
It finds a worktree under trees/, stops related processes, removes the worktree and its Git branch, then checks the results.
Can I undo the branch deletion?
No. The command deletes the branch permanently, and may force deletion if the regular Git operation fails.