# /worktree — Git Worktree Management

Manage git worktrees for parallel development. Each worktree gets its own directory and branch, enabling simultaneous Claude Code sessions.

## Usage

```
/worktree list                         # Show all worktrees
/worktree create <name>                # Create new worktree + branch
/worktree remove <name>                # Remove worktree + branch
/worktree setup                        # Create standard 5 parallel worktrees
/worktree status                       # Status across all worktrees
/worktree clean                        # Remove all worktrees except main
```

**Examples:**
- `/worktree list`
- `/worktree create auth-refactor`
- `/worktree remove auth-refactor`
- `/worktree setup`

## Workflow

### List Worktrees
```bash
git worktree list
```
Show each worktree with:
- Directory path
- Branch name
- Last commit

### Create Worktree
1. Validate name (kebab-case, no spaces)
2. Create worktree with new branch:
   ```bash
   git worktree add ../mawidi-<name> -b feature/<name>
   ```
3. Verify creation:
   ```bash
   git worktree list
   ls ../mawidi-<name>/package.json
   ```
4. Report the worktree path so user can open a new terminal there

### Remove Worktree
1. Check if the worktree exists:
   ```bash
   git worktree list | grep <name>
   ```
2. Check for uncommitted changes in the worktree:
   ```bash
   cd ../mawidi-<name> && git status
   ```
3. If uncommitted changes exist, **WARN the user** and ask for confirmation
4. Remove the worktree:
   ```bash
   git worktree remove ../mawidi-<name>
   ```
5. Optionally delete the branch:
   ```bash
   git branch -d feature/<name>
   ```

### Setup (5 Parallel Worktrees)
Create 5 standard worktrees for parallel development:
```bash
git worktree add ../mawidi-w1 -b feature/w1
git worktree add ../mawidi-w2 -b feature/w2
git worktree add ../mawidi-w3 -b feature/w3
git worktree add ../mawidi-w4 -b feature/w4
git worktree add ../mawidi-w5 -b feature/w5
```
Report:
```
WORKTREE SETUP COMPLETE
=======================
Worktree 1: ../mawidi-w1 (feature/w1)
Worktree 2: ../mawidi-w2 (feature/w2)
Worktree 3: ../mawidi-w3 (feature/w3)
Worktree 4: ../mawidi-w4 (feature/w4)
Worktree 5: ../mawidi-w5 (feature/w5)

Open a terminal in each directory and run Claude Code for parallel development.
```

### Status Across All Worktrees
For each worktree, show:
```bash
git worktree list --porcelain
```
Then for each:
- Branch name
- Commits ahead of main
- Uncommitted changes count
- Last commit message and date

### Clean All Worktrees
1. List all worktrees
2. **WARN the user** about uncommitted changes
3. For each non-main worktree:
   ```bash
   git worktree remove ../mawidi-<name>
   git branch -d feature/<name>
   ```
4. Prune stale entries:
   ```bash
   git worktree prune
   ```

## Worktree Naming Convention
- Worktree directories: `../mawidi-<name>` (sibling to main repo)
- Branch names: `feature/<name>` or `fix/<name>`
- Generic worktrees: `../mawidi-w1` through `../mawidi-w5`

## Key Rules
- ALWAYS check for uncommitted changes before removing
- ALWAYS warn user before destructive operations
- Worktrees are siblings to the main repo directory
- Each worktree gets its own branch
- Use `git worktree prune` to clean up stale entries
- Never remove the main worktree
