Skip to content

Commit 9099903

Browse files
marcusgollclaude
andcommitted
feat(worktrees): integrate worktree creation into /feature command
- Load worktrees.auto_create preference (default: true) - Call worktree-manager.sh create instead of git checkout -b - Store worktree path in state.yaml (git.worktree_enabled, git.worktree_path) - Display worktree path in success message with cd instructions - Graceful fallback to regular branch if worktree creation fails Now /feature commands create isolated worktrees by default, enabling parallel development with multiple Claude Code instances. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 79efcf1 commit 9099903

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

.spec-flow/scripts/bash/feature-workflow.sh

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ fi
354354

355355
echo "Project type: $PROJECT_TYPE"
356356

357+
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
358+
# WORKTREE CONFIGURATION (v11.8)
359+
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
360+
361+
WORKTREE_AUTO_CREATE=$(bash "$SCRIPT_DIR/utils/load-preferences.sh" --key "worktrees.auto_create" --default "true" 2>/dev/null || echo "true")
362+
WORKTREE_PATH=""
363+
357364
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
358365
# BRANCH MANAGEMENT
359366
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -377,7 +384,29 @@ else
377384
BASE="feature/$FEATURE_NUM-$SLUG"
378385
BRANCH_NAME="$BASE"
379386
i=2; while git rev-parse --verify --quiet "$BRANCH_NAME" >/dev/null 2>&1; do BRANCH_NAME="$BASE-$i"; i=$((i+1)); done
380-
git checkout -b "$BRANCH_NAME"
387+
388+
# Create worktree or regular branch based on preference
389+
if [ "$WORKTREE_AUTO_CREATE" = "true" ]; then
390+
echo "Creating worktree for feature..."
391+
WORKTREE_RESULT=$("$SCRIPT_DIR/worktree-manager.sh" --json create "feature" "$FEATURE_NUM-$SLUG" "$BRANCH_NAME" 2>&1)
392+
if [ $? -eq 0 ]; then
393+
# Extract worktree path from JSON result
394+
WORKTREE_PATH=$(echo "$WORKTREE_RESULT" | grep -o '"worktree_path": *"[^"]*"' | sed 's/.*: *"\([^"]*\)"/\1/')
395+
if [ -n "$WORKTREE_PATH" ] && [ -d "$WORKTREE_PATH" ]; then
396+
echo "✅ Worktree created: $WORKTREE_PATH"
397+
cd "$WORKTREE_PATH"
398+
else
399+
echo "⚠️ Worktree creation returned empty path, falling back to regular branch"
400+
git checkout -b "$BRANCH_NAME"
401+
fi
402+
else
403+
echo "⚠️ Worktree creation failed, falling back to regular branch"
404+
echo " Error: $WORKTREE_RESULT"
405+
git checkout -b "$BRANCH_NAME"
406+
fi
407+
else
408+
git checkout -b "$BRANCH_NAME"
409+
fi
381410
else
382411
BRANCH_NAME="$CURRENT_BRANCH"
383412
fi
@@ -402,6 +431,12 @@ start_phase_timing "$FEATURE_DIR" "spec-flow"
402431

403432
[ -n "$ISSUE_NUMBER" ] && yq -i ".feature.github_issue = $ISSUE_NUMBER" "$FEATURE_DIR/state.yaml" || true
404433

434+
# Add worktree info to state.yaml (v11.8)
435+
if [ -n "$WORKTREE_PATH" ]; then
436+
yq -i '.git.worktree_enabled = true' "$FEATURE_DIR/state.yaml" 2>/dev/null || true
437+
yq -i ".git.worktree_path = \"$WORKTREE_PATH\"" "$FEATURE_DIR/state.yaml" 2>/dev/null || true
438+
fi
439+
405440
# Optional: generate feature CLAUDE.md
406441
.spec-flow/scripts/bash/generate-feature-claude-md.sh "$FEATURE_DIR" 2>/dev/null || true
407442

@@ -410,6 +445,12 @@ echo "✅ Feature initialized: $FEATURE_NUM-$SLUG"
410445
echo " Branch: $BRANCH_NAME"
411446
echo " Directory: $FEATURE_DIR"
412447
[ -n "$ISSUE_NUMBER" ] && echo " GitHub Issue: #$ISSUE_NUMBER"
448+
if [ -n "$WORKTREE_PATH" ]; then
449+
echo " Worktree: $WORKTREE_PATH"
450+
echo ""
451+
echo "📂 Working directory: $WORKTREE_PATH"
452+
echo "💡 Run 'cd $WORKTREE_PATH' to continue development"
453+
fi
413454
echo ""
414455

415456
# Exit here - LLM will handle phase execution through slash commands

0 commit comments

Comments
 (0)