Skip to content
Development
Command

/worktree

Manage fixed worktrees (hotfix, debug) and their lifecycle

From plugin
claude-plugin-prd-workflow
1227 skills17 agents27 commands

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.md
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 synced

Check 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-1
Read more
Ships withclaude-plugin-prd-workflow

The 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.

Get the whole plugin

Other commands on claude-plugin-prd-workflow.