remove-worktree
From rtk-ai
Remove a specific worktree (directory + git reference + branch)
Removes a git worktree's directory, git reference, local branch, and optionally remote branch by name.
Use it when
- Cleaning up a finished feature or fix worktree
- Deleting a worktree branch merged into master
- Force-removing an unmerged worktree after confirmation
- Also removing the corresponding remote branch
Skip it if
- Not using git worktrees in your workflow
- Working on master or main (protected, won't remove)
- Prefer manual git worktree remove/branch -D commands
Install
/remove-worktreeFacts
- Repository
- rtk-ai/rtk
- Status
- Actively maintained
- Last commit
- Model
- haiku
- Source file
- .claude/commands/tech/remove-worktree.md
Source preview
The instructions Claude Code reads when this command runs.
# Remove Worktree
Remove a specific worktree, cleaning up directory, git references, and optionally the branch.
## Usage
```bash
/tech:remove-worktree feature/new-filter
/tech:remove-worktree fix/session-bug
```
## Implementation
Execute this script with branch name from `$ARGUMENTS`:
```bash
#!/bin/bash
set -euo pipefail
BRANCH_NAME="$ARGUMENTS"
if [ -z "$BRANCH_NAME" ]; then
echo "❌ Usage: /tech:remove-worktree <branch-name>"
echo ""
echo "Example:"
echo " /tech:remove-worktree feature/new-filter"
exit 1
fi
echo "🔍 Checking worktree: $BRANCH_NAME"
echo ""
# Check if worktree exists in git
if ! git worktree list | grep -q "$BRANCH_NAME"; then
echo "❌ Worktree not found: $BRANCH_NAME"
echo ""
echo "Available worktrees:"
git worktree list
exit 1
fi
# Get worktree path from git
WORKTREE_FULL_PATH=$(git worktree list | grep "$BRANCH_NAME" | awk '{print $1}')
# Safety check: never remove main repo
if [ "$WORKTREE_FULL_PATH" = "$(pwd)" ]; then
echo "❌ Cannot remove main repository worktree"
exit 1
fi
# Safety check: never remove master or main
if [ "$BRANCH_NAME" = "master" ] || [ "$BRANCH_NAME" = "main" ]; then
echo "❌ Cannot remove $BRANCH_NAME (protected branch)"
exit 1
fi
echo "📂 Worktree path: $WORKTREE_FULL_PATH"
echo "🌿 Branch: $BRANCH_NAME"
echo ""
# Check if branch is merged
IS_MERGED=false
if git branch --merged master | grep View full source on GitHub →Other slash commands
feature-development
★ 229,918Workflow command scaffold for feature-development in everything-claude-code.
affaan-mupdated 15d agoMITdatabase-migration
★ 229,918Workflow command scaffold for database-migration in everything-claude-code.
affaan-mupdated 15d agoMITadd-language-rules
★ 229,918Workflow command scaffold for add-language-rules in everything-claude-code.
affaan-mupdated 15d agoMITcommit-push-pr
★ 137,934Commit, push, and open a PR
anthropicsupdated 14d agodedupe
★ 137,934Find duplicate GitHub issues
anthropicsupdated 14d agotriage-issue
★ 137,934Triage GitHub issues by analyzing and applying labels
anthropicsupdated 14d ago