/worktree
Manage fixed worktrees (hotfix, debug) and their lifecycle
How it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/worktree
Context preview
What this command does when you run it.
Manage fixed worktrees (hotfix, debug) and their lifecycle
Command definition
worktree.mdname: worktree
description: Manage fixed worktrees (hotfix, debug) and their lifecycle
category: Development Tools
version: 0.4.3
Worktree Management Command
Centralized management for fixed worktrees (hotfix, debug) with intelligent sync.
Purpose
Manage permanent worktrees for quick fixes and debugging sessions:
- ๐ง **hotfix/** - Quick fixes and UI tweaks
- ๐ **debug/** - Debugging sessions with modifications
Commands
Setup
/worktree setup
**Initial setup of fixed worktrees**:
- Creates `worktrees/hotfix/` on branch `hotfix`
- Creates `worktrees/debug/` on branch `debug`
- Configures lock files
- Sets up Git hooks (optional)
**What happens**:
1. Create worktrees/ directory if needed
2. git worktree add worktrees/hotfix hotfix
3. git checkout -b hotfix main # Parking branch
4. git worktree add worktrees/debug debug
5. git checkout -b debug main # Parking branch
6. Create .claude-lock files
7. git checkout main # Return to main
Sync
/worktree sync
/worktree sync --force
/worktree sync hotfix
/worktree sync debug
**Sync all or specific worktrees with main**:
- Intelligent sync strategy (Option C)
- Skips locked worktrees (fix in progress)
- Shows recent changes preview
- Force sync bypasses thresholds
**Sync Strategy (Intelligent)**:
- **0 commits behind**: โ
Nothing to do
- **1-10 commits**: ๐ Silent auto-sync
- **10-50 commits**: โ ๏ธ Propose sync with preview
- **50+ commits**: โ Force sync (required)
Status
/worktree status
/worktree status --verbose
/worktree status hotfix
**Show status of all worktrees**:
- Lock status (idle/in_progress)
- Current branch
- Sync status (commits behind main)
- Last used timestamp
- Available actions
List
/worktree list
**List all worktrees** (including PRD worktrees):
- Path and branch
- Status
- Sync info
Prune
/worktree prune
/worktree prune --force
**Clean up obsolete worktrees**:
- Remove merged PRD worktrees
- Clean orphaned worktree directories
- Reset fixed worktrees to clean state (if idle)
Workflow
Initial Setup (Once)
$ /worktree setup
๐ง Setting up fixed worktrees...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Creating worktrees/hotfix/
โ
Worktree created
๐ Branch: hotfix (parking, synced with main)
๐ Lock file initialized
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Creating worktrees/debug/
โ
Worktree created
๐ Branch: debug (parking, synced with main)
๐ Lock file initialized
๐ Session directory: .prds/debug-sessions/
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Setup complete!
Next steps:
- Use /ship "fix" --worktree for isolated fixes
- Use /debugging "issue" --worktree for debug sessions
- Use /worktree status to check worktree state
Daily Sync (Morning Routine)
$ /worktree sync
๐ Syncing all fixed worktrees with main...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ worktrees/hotfix/
๐ Checking status...
๐ Idle (no active fix)
๐ Was 3 commits behind, syncing...
Recent changes:
- a3f2c1d fix: OAuth timeout handling
- 8d4e2a9 feat: Improved error logging
- 1c8f3b2 refactor: API restructure
โ
Synced successfully
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ worktrees/debug/
๐ Checking status...
๐ Idle (no active session)
โ
Already up-to-date
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
All worktrees syncedCheck Status
$ /worktree status
๐ Worktree Status Report
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ worktrees/hotfix/
Status: ๐ IN_PROGRESS
Branch: hotfix/fix-login-button
Started: 15 minutes ago
Sync: โ
Up-to-date with main
Files: 3 modified, 87 lines changed
Commits: 2 commits on branch
Actions:
- /ship --complete (finish)
- /ship --abort (cancel)
- /ship --status (details)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ worktrees/debug/
Status: ๐ IDLE
Branch: debug (parking)
Sync: โ
Up-to-date with main
Last used: 2 days ago
Actions:
- /debugging "issue" --worktree (start)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary:
Total fixed worktrees: 2
Active: 1 (hotfix)
Idle: 1 (debug)
Need sync: 0
๐ก All worktrees up-to-date!
Intelligent Sync Logic
Auto-Sync on Start
When starting `/ship --worktree` or `/debugging --worktree`:
1. Fetch latest main
2. Check commits behind
3. Apply sync strategy:
- 0 commits: โ
Continue
- 1-10 commits: ๐ Silent sync
- 10-50 commits: โ ๏ธ Propose sync with preview
- 50+ commits: โ Force sync (required)
Sync Algorithm
sync_worktree_intelligent() {
local worktree_path=$1
local parking_branch=$2
local force=${3:-false}
cd "$worktree_path"
git fetch origin main -q
BEHIND=$(git rev-list --count HEAD..origin/main)
# Force sync (explicit request)
if [ "$force" = true ]; then
git reset --hard origin/main
return 0
fi
# Critical staleness (50+ commits) - Force sync
if [ $BEHIND -gt 50 ]; then
echo "โ ๏ธ Critically stale ($BEHIND commits)"
echo "Auto-syncing required..."
git reset --hard origin/main
return 0
fi
# Moderate staleness (10-50) - Propose sync
if [ $BEHIND -gt 10 ]; then
echo "โ ๏ธ $BEHIND commits behind main"
echo "Recent changes:"
git log --oneline -5 origin/main ^HEAD
read -p "Sync before starting? (Y/n) " -r
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
git reset --hard origin/main
else
echo "โ ๏ธ Continuing without sync"
fi
return 0
fi
# Light staleness (1-10) - Silent sync
if [ $BEHIND -gt 0 ]; then
echo "๐ Syncing ($BEHIND commits)..."
git reset --hard origin/main
return 0
fi
# Up-to-date
echo "โ
Already up-to-date"
}Lock File Format
`.claude-lock` in each worktree:
{
"status": "in_progress",
"type": "hotfix",
"branch": "hotfix/fix-login-button",
"started_at": "2025-01-1Read more
name: worktree description: Manage fixed worktrees (hotfix, debug) and their lifecycle category: Development Tools version: 0.4.3
Worktree Management Command
Centralized management for fixed worktrees (hotfix, debug) with intelligent sync.
Purpose
Manage permanent worktrees for quick fixes and debugging sessions:
- ๐ง **hotfix/** - Quick fixes and UI tweaks
- ๐ **debug/** - Debugging sessions with modifications
Commands
Setup
/worktree setup
**Initial setup of fixed worktrees**:
- Creates `worktrees/hotfix/` on branch `hotfix`
- Creates `worktrees/debug/` on branch `debug`
- Configures lock files
- Sets up Git hooks (optional)
**What happens**:
1. Create worktrees/ directory if needed 2. git worktree add worktrees/hotfix hotfix 3. git checkout -b hotfix main # Parking branch 4. git worktree add worktrees/debug debug 5. git checkout -b debug main # Parking branch 6. Create .claude-lock files 7. git checkout main # Return to main
Sync
/worktree sync /worktree sync --force /worktree sync hotfix /worktree sync debug
**Sync all or specific worktrees with main**:
- Intelligent sync strategy (Option C)
- Skips locked worktrees (fix in progress)
- Shows recent changes preview
- Force sync bypasses thresholds
**Sync Strategy (Intelligent)**:
- **0 commits behind**: โ Nothing to do
- **1-10 commits**: ๐ Silent auto-sync
- **10-50 commits**: โ ๏ธ Propose sync with preview
- **50+ commits**: โ Force sync (required)
Status
/worktree status /worktree status --verbose /worktree status hotfix
**Show status of all worktrees**:
- Lock status (idle/in_progress)
- Current branch
- Sync status (commits behind main)
- Last used timestamp
- Available actions
List
/worktree list
**List all worktrees** (including PRD worktrees):
- Path and branch
- Status
- Sync info
Prune
/worktree prune /worktree prune --force
**Clean up obsolete worktrees**:
- Remove merged PRD worktrees
- Clean orphaned worktree directories
- Reset fixed worktrees to clean state (if idle)
Workflow
Initial Setup (Once)
$ /worktree setup ๐ง Setting up fixed worktrees... โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ Creating worktrees/hotfix/ โ Worktree created ๐ Branch: hotfix (parking, synced with main) ๐ Lock file initialized โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ Creating worktrees/debug/ โ Worktree created ๐ Branch: debug (parking, synced with main) ๐ Lock file initialized ๐ Session directory: .prds/debug-sessions/ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Setup complete! Next steps: - Use /ship "fix" --worktree for isolated fixes - Use /debugging "issue" --worktree for debug sessions - Use /worktree status to check worktree state
Daily Sync (Morning Routine)
$ /worktree sync
๐ Syncing all fixed worktrees with main...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ worktrees/hotfix/
๐ Checking status...
๐ Idle (no active fix)
๐ Was 3 commits behind, syncing...
Recent changes:
- a3f2c1d fix: OAuth timeout handling
- 8d4e2a9 feat: Improved error logging
- 1c8f3b2 refactor: API restructure
โ
Synced successfully
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ worktrees/debug/
๐ Checking status...
๐ Idle (no active session)
โ
Already up-to-date
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
All worktrees syncedCheck Status
$ /worktree status ๐ Worktree Status Report โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ worktrees/hotfix/ Status: ๐ IN_PROGRESS Branch: hotfix/fix-login-button Started: 15 minutes ago Sync: โ Up-to-date with main Files: 3 modified, 87 lines changed Commits: 2 commits on branch Actions: - /ship --complete (finish) - /ship --abort (cancel) - /ship --status (details) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ worktrees/debug/ Status: ๐ IDLE Branch: debug (parking) Sync: โ Up-to-date with main Last used: 2 days ago Actions: - /debugging "issue" --worktree (start) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Summary: Total fixed worktrees: 2 Active: 1 (hotfix) Idle: 1 (debug) Need sync: 0 ๐ก All worktrees up-to-date!
Intelligent Sync Logic
Auto-Sync on Start
When starting `/ship --worktree` or `/debugging --worktree`:
1. Fetch latest main 2. Check commits behind 3. Apply sync strategy: - 0 commits: โ Continue - 1-10 commits: ๐ Silent sync - 10-50 commits: โ ๏ธ Propose sync with preview - 50+ commits: โ Force sync (required)
Sync Algorithm
sync_worktree_intelligent() {
local worktree_path=$1
local parking_branch=$2
local force=${3:-false}
cd "$worktree_path"
git fetch origin main -q
BEHIND=$(git rev-list --count HEAD..origin/main)
# Force sync (explicit request)
if [ "$force" = true ]; then
git reset --hard origin/main
return 0
fi
# Critical staleness (50+ commits) - Force sync
if [ $BEHIND -gt 50 ]; then
echo "โ ๏ธ Critically stale ($BEHIND commits)"
echo "Auto-syncing required..."
git reset --hard origin/main
return 0
fi
# Moderate staleness (10-50) - Propose sync
if [ $BEHIND -gt 10 ]; then
echo "โ ๏ธ $BEHIND commits behind main"
echo "Recent changes:"
git log --oneline -5 origin/main ^HEAD
read -p "Sync before starting? (Y/n) " -r
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
git reset --hard origin/main
else
echo "โ ๏ธ Continuing without sync"
fi
return 0
fi
# Light staleness (1-10) - Silent sync
if [ $BEHIND -gt 0 ]; then
echo "๐ Syncing ($BEHIND commits)..."
git reset --hard origin/main
return 0
fi
# Up-to-date
echo "โ
Already up-to-date"
}Lock File Format
`.claude-lock` in each worktree:
{
"status": "in_progress",
"type": "hotfix",
"branch": "hotfix/fix-login-button",
"started_at": "2025-01-1The complete Claude Code plugin for Product-Driven Development Transform PRDs from ideas to shipped features with AI-powered review, guided implementation, and automated quality gates. Never ship unclear requirements again.
Repo: Yassinello/claude-plugin-prd-workflow

