Safely remove one or more Git worktrees and their directories, handling uncommitted changes and orphaned folders.
Running worktree-remove:
- Resolves the target worktree/directory (branch name, worktree path, or parent-directory name; supports
<repo>-<branch>naming). - Checks if the worktree is registered with Git.
- Safely handles "orphaned" directories (directories that exist but Git no longer recognizes as worktrees).
- Checks for uncommitted changes (if registered) and, when found, asks "Remove anyway?" before proceeding.
- Asks for a final confirmation to remove the registered worktree or orphaned directory (unless
--yesor--dry-run). - If you are inside the target directory, warns and switches the process to the main worktree before removal (your shell directory does not change, so after removal it may still point to a directory that no longer exists).
- Moves the directory to the system trash when possible (safer than
rm -rf). - Unregisters the worktree from Git (
git worktree remove/git worktree prune). - Reports the outcome when
--verboseor--dry-runis used.
- Node.js ≥ 22.14.0
- Git with
git worktreesupport - Optional: set
WORKTREE_REMOVE_GIT_PATHto override the git executable
You usually don’t need a global install.
# inside any worktree of /my/path/my-app
# one-off
npx worktree-remove -i
# or pass a target directly
npx worktree-remove feature/login-form
# or install globally
pnpm add -g worktree-remove # or: npm i -g worktree-remove
worktree-remove -iRun this from any worktree of your project. You can remove a sibling worktree, or even the worktree you are currently in.
By default, the CLI is quiet and requires an explicit target (non-interactive selection). Pass a target explicitly, or use --interactive to pick from a list. In a TTY it will still prompt for confirmations unless --no-interactive, --yes, or --dry-run is used. Use --force to bypass safety prompts around failures and uncommitted changes.
Use the -i flag to open an interactive multi-select list of worktrees:
# inside any worktree for the repository
worktree-remove -iThis allows you to select one or more worktrees to remove from a list. All selected worktrees are checked for uncommitted changes upfront, confirmed in a single batch, and removed in parallel.
You can also specify the worktree directly by:
- branch name (for worktrees on a branch)
- worktree path (works for detached HEAD worktrees)
- directory name in the parent folder (useful when there's no branch)
Note: If you pass a path that exists but isn't a registered worktree, it will be treated as an orphaned directory and moved to trash after confirmation. Path targets can point anywhere, so use caution when providing absolute or home-relative paths. For safety, unregistered directories inside the main worktree are refused.
worktree-remove <target...>Example:
# remove a single worktree
worktree-remove feature/login-form
# remove multiple worktrees at once
worktree-remove feature/login-form feature/signupDetached HEAD example:
worktree-remove ../my-app-test-29Sibling directory name example:
worktree-remove my-app-test-29-i, --interactiveinteractively select worktrees to remove (multi-select)--no-interactivedisable all prompts and interactive selection-y, --yesassume yes for all confirmation prompts-f, --forceskip safety prompts on failures and uncommitted changes (final confirmation still required unless--yesor--dry-run)--dry-runshow what would be removed without making changes--verboseshow detailed progress output--quietsuppress non-error output
# remove a worktree by branch name
worktree-remove feature/login-form# remove multiple worktrees at once
worktree-remove feature/login-form feature/signup hotfix/typo# preview what would be removed
worktree-remove --dry-run feature/login-form feature/signup# use an interactive multi-select
worktree-remove --interactive# pipe a worktree path from git + fzf
git worktree list --porcelain | rg '^worktree ' | sed 's/^worktree //' | fzf | xargs worktree-remove --yesIn CI or non-interactive shells, pass --yes or --dry-run. Use --no-interactive to prevent any prompts.
Add to your CLAUDE.md or AGENTS.md:
# Rule: `worktree-remove` Usage
Run `npx -y worktree-remove --help` to learn available options.
Use `worktree-remove` when you need to safely remove Git worktrees.
It handles uncommitted changes, orphaned directories, and moves
files to trash instead of permanent deletion.MIT