Guide complet pour utiliser les worktrees hybrides avec flexibilité et efficacité.
Principe: Start simple (Main), scale up (Worktree) when needed.
- 🚀 Main pour quick fixes rapides
- 🛡️ Worktree pour isolation quand nécessaire
- 🔄 Migration facile si le fix grossit
- 🎨 Choix à chaque étape
# Créer les worktrees permanents
$ /worktree setup
✅ worktrees/hotfix/ created
✅ worktrees/debug/ created
✅ Configuration initializedRésultat:
claude-plugin-prd-workflow/
├── worktrees/
│ ├── hotfix/ (permanent, pour /ship --worktree)
│ └── debug/ (permanent, pour /debugging --worktree)
└── .claude/
└── config-worktrees.jsonNouveau fix à faire
│
├─── Petit fix ? (< 5 fichiers, < 100 lignes, < 30 min)
│ │
│ └─── OUI → /ship "Fix X" (Main)
│ │
│ ├─── Reste petit → /ship --complete
│ └─── Devient gros → /ship --to-worktree
│
└─── Gros fix ? (refactor, multi-fichiers)
│
└─── OUI → /ship "Fix X" --worktree
ou /hotfix "Fix X"Bug à investiguer
│
├─── Investigation read-only ? (logs, code reading)
│ │
│ └─── OUI → /debugging "Issue" (Main)
│ │
│ ├─── Pas de fix → /debugging --resolve
│ └─── Besoin fix → /debugging --to-worktree
│
└─── Reproduction / Fix nécessaire ?
│
└─── OUI → /debugging "Issue" --worktreeContexte: Typo, petit changement évident
# Sur Main
$ /ship "Fix typo in error message"
✅ Quick fix on Main
📝 Branch: quickship/fix-typo
# Modification: 1 fichier, 2 lignes
# Pas de warning
$ /ship --complete
✅ Committed
✅ PR merged
🧹 Done!Durée: 2-5 minutes Localisation: Main uniquement
Contexte: Fix commence simple mais révèle plus de work
# Commence sur Main
$ /ship "Fix dark mode issues"
✅ Working on Main
# Après 15 minutes...
# 6 fichiers modifiés, 120 lignes
⚠️ LARGE FIX DETECTED
- 6 files changed
- 120 lines modified
- 18 minutes elapsed
💡 Suggest migration to worktree
$ /ship --to-worktree
🔄 Migrating to worktree...
✅ Moved to worktrees/hotfix/
📂 Branch: hotfix/fix-dark-mode
💻 Open: code worktrees/hotfix/
# Continue tranquillement dans worktree
$ /ship --complete
✅ Done from worktree!Durée: 30-60 minutes Localisation: Main → Worktree (migration)
Contexte: Refactor ou changement multi-fichiers dès le départ
# Direct en worktree
$ /ship "Refactor authentication module" --worktree
🔍 Checking worktree hotfix/...
🔄 Syncing (3 commits behind)...
✅ Synced with main
✅ Started in worktrees/hotfix/
📝 Branch: hotfix/refactor-auth
🔒 Locked worktree
# Ou version courte:
$ /hotfix "Refactor authentication module"
# Développement isolé
# Pas de limites
$ /ship --complete
✅ Done!Durée: 1-4 heures Localisation: Worktree uniquement
Contexte: Investigation sans modifications de code
# Sur Main
$ /debugging "OAuth timeout in production"
🔍 Debugging on Main (read-only)
📝 Session: .prds/debug-sessions/2025-01-14-oauth-timeout.md
# Investigation:
# - Lecture logs
# - Analyse code
# - Check config
# Trouvé: Config issue
$ /debugging --resolve
💬 Status?
2. Resolved without fix (config issue)
✅ Documented
Root cause: Redis TTL too short
Solution: Updated prod configDurée: 15-60 minutes Localisation: Main uniquement
Contexte: Bug complexe nécessitant reproduction et fix
# En worktree
$ /debugging "Memory leak in WebSocket handler" --worktree
🔍 Checking worktree debug/...
🔄 Syncing...
✅ Synced
✅ Started in worktrees/debug/
📝 Branch: debug/memory-leak-websocket
📄 Session doc created
# Investigation:
# - Reproduction du bug
# - Tests hypothèses
# - Debug logging
# - Fix implementation
$ /debugging --resolve
💬 Status?
1. Resolved with fix
✅ Committed fix
📤 PR #236 created
📝 Session documented
🧹 Worktree cleaned upDurée: 1-4 heures Localisation: Worktree uniquement
Contexte: Fix en cours dans worktree, nouveau fix urgent arrive
# Fix 1 déjà en cours dans worktree
$ /ship "Fix A" --worktree
# En cours de travail...
# Fix 2 urgent arrive
$ /ship "Critical bug B" --worktree
❌ Fix already in progress in worktrees/hotfix/
Current: hotfix/fix-a
Options:
1. Complete current
2. Work on Main (quick)
3. Abort current
# Choix 2: Fix urgent sur Main
$ /ship "Critical bug B"
✅ Working on Main
# Fix rapide, pas de blocage
$ /ship --complete
✅ Done!
# Retour au fix 1
$ cd worktrees/hotfix/
$ /ship --complete
✅ Done!Durée: Variable Localisation: Worktree + Main en parallèle
Contexte: Investigation longue avec interruption
# Debug session en worktree
$ /debugging "Complex race condition" --worktree
✅ Started investigation
# Après 2 heures, meeting...
$ /debugging --pause
💾 Paused
🔄 Returned to parking branch
# Lendemain matin
$ /debugging --resume
📋 Paused sessions:
1. debug/complex-race-condition (2h ago)
Resume: 1
✅ Resumed
Continue debugging!
# Trouve solution
$ /debugging --resolve
✅ Done!Durée: Multiple sessions Localisation: Worktree avec pause/resume
# 1. Sync worktrees avec main
$ /worktree sync
🔄 Syncing all worktrees...
worktrees/hotfix/: ✅ Synced (3 commits)
worktrees/debug/: ✅ Already up-to-date
# 2. Check status
$ /worktree status
📊 Worktree Status
hotfix: 🔓 IDLE
debug: 🔓 IDLE
# 3. Ready to work!# Check pour worktrees obsolètes
$ /worktree prune
# Ou laisser auto-cleanup faire son travail| Type de Tâche | Durée | Fichiers | Commande | Localisation |
|---|---|---|---|---|
| Typo | < 5 min | 1-2 | /ship "Fix" |
Main |
| Small fix | < 30 min | 2-5 | /ship "Fix" |
Main |
| Medium fix | 30-60 min | 5-10 | /ship "Fix" → --to-worktree |
Main → Worktree |
| Large fix | > 1h | 10+ | /ship "Fix" --worktree |
Worktree |
| Refactor | > 1h | Any | /hotfix "Refactor" |
Worktree |
| Quick debug | < 30 min | 0 | /debugging "Issue" |
Main |
| Complex debug | > 1h | Any | /debugging "Issue" --worktree |
Worktree |
- ✅ Start simple (Main) pour quick fixes
- ✅ Migrate vers worktree si fix grossit
- ✅ Use worktree direct pour refactors
- ✅ Sync worktrees chaque matin
- ✅ Use
/hotfixsi préférence worktree - ✅ Documenter debug sessions
- ❌ Forcer worktree pour petits fixes
- ❌ Ignorer smart warnings sur Main
- ❌ Oublier de sync avant gros travail
- ❌ Laisser worktree locked longtemps
- ❌ Skip documentation de debug
.claude/config-worktrees.json:
{
"warnings": {
"files_threshold": 5, // Warning si > 5 fichiers
"lines_threshold": 100, // Warning si > 100 lignes
"time_threshold_minutes": 30 // Warning après 30 min
},
"sync": {
"thresholds": {
"silent_sync_max_commits": 10, // Sync auto < 10 commits
"warn_sync_max_commits": 50, // Demande si 10-50 commits
"force_sync_min_commits": 100 // Force sync si > 100
}
}
}Profil "Aggressive Worktree" (toujours isolé):
{
"warnings": {
"files_threshold": 2,
"lines_threshold": 50,
"time_threshold_minutes": 15
}
}Profil "Lazy Sync" (sync moins fréquent):
{
"sync": {
"thresholds": {
"silent_sync_max_commits": 20,
"warn_sync_max_commits": 100,
"force_sync_min_commits": 200
}
}
}$ /ship "Fix X" --worktree
❌ Locked
# Solution:
$ cd worktrees/hotfix/
$ git status
# Si rien en cours:
$ git checkout hotfix
$ rm .claude-lock
# Ou:
$ /ship --abort # Force cleanup$ /worktree sync
⚠️ 50+ commits behind!
# Force sync
$ /worktree sync --force$ /ship --to-worktree
❌ Failed
# Vérifier:
1. Uncommitted changes? → Commit first
2. Worktree locked? → Finish current fix
3. Worktree not setup? → /worktree setup| Commande | Action |
|---|---|
/worktree setup |
Setup initial |
/worktree sync |
Sync tous les worktrees |
/worktree status |
Status détaillé |
/ship "Fix" |
Quick fix sur Main |
/ship "Fix" --worktree |
Fix en worktree |
/ship --to-worktree |
Migrer vers worktree |
/ship --complete |
Terminer fix |
/hotfix "Fix" |
Alias /ship --worktree |
/debugging "Issue" |
Debug sur Main |
/debugging "Issue" --worktree |
Debug en worktree |
# Setup rapide
alias wt-setup="/worktree setup"
alias wt-sync="/worktree sync"
alias wt-status="/worktree status"
# Fixes
alias fix="/ship"
alias fixw="/ship --worktree"
alias hf="/hotfix"
# Debug
alias dbg="/debugging"
alias dbgw="/debugging --worktree"# Matin
$ /worktree sync
✅ All synced
# Fix 1 (petit)
$ /ship "Fix login typo"
$ /ship --complete
✅ Done (5 min)
# Fix 2 (moyen, devient gros)
$ /ship "Fix dark mode"
# ... travail ...
⚠️ Large fix detected
$ /ship --to-worktree
# ... continue ...
$ /ship --complete
✅ Done (45 min)
# Bug investigation
$ /debugging "API timeout"
# ... investigation ...
$ /debugging --resolve
✅ Config issue, documented
# Gros refactor
$ /hotfix "Refactor auth system"
# ... travail ...
$ /ship --complete
✅ Done (2h)Total: 4 tâches, 3h de travail, 0 conflits
# Refactor en cours dans worktree
$ /hotfix "Refactor API"
# En cours...
# BUG URGENT PRODUCTION!
$ /ship "Critical security fix" --worktree
❌ Worktree busy!
# Option: Main pour urgent
$ /ship "Critical security fix"
✅ On Main
# Fix rapide
$ /ship --complete
✅ Merged! (10 min)
# Retour au refactor
$ cd worktrees/hotfix/
$ /ship --complete
✅ DoneRésultat: Urgent fix sans interrompre long refactor
Version: 0.4.3 Plugin: claude-prd-workflow Last Updated: 2025-01-14