A Claude Code slash command for cleaning up completed issue worktrees.
# Clone to your preferred location
git clone git@github.com:claude-commands/command-prune-worktree.git <clone-path>/command-prune-worktree
# Symlink (use full path to cloned repo)
ln -s <clone-path>/command-prune-worktree/prune-worktree.md ~/.claude/commands/prune-worktree.md
# Make script executable
chmod +x <clone-path>/command-prune-worktree/prune-worktrees.sh
```text
## Usage
```text
/prune-worktree
```text
No arguments needed - it scans for all issue worktrees.
## Configuration
Set the `WORKTREE_PREFIX` environment variable to match your project naming:
```bash
export WORKTREE_PREFIX="my-project"
```text
This should match the prefix used by `/start-issue`.
Default prefix is `project`.
## What it does
1. Scans for worktrees matching `{prefix}-issue-*` pattern
2. For each worktree:
- Checks if the GitHub issue is closed
- Verifies no uncommitted changes exist
- Confirms the branch is merged (via PR or directly)
3. Automatically removes worktrees that meet all criteria
4. Provides manual cleanup commands for edge cases
## Safety Features
- Only processes worktrees following the issue naming convention
- Verifies GitHub issue exists and is closed
- Confirms branch is merged into dev
- Checks for uncommitted changes
- Shows manual cleanup commands when automatic cleanup isn't safe
## Companion Command
Use with `/start-issue` to create worktrees for issues.
## Requirements
- `gh` CLI installed and authenticated
- Git repository with GitHub remote
- Worktrees created with `/start-issue` naming convention
## Updates
```bash
cd <clone-path>/command-prune-worktree && git pull
```text