Skip to content
Development
Command

/complete

Complete a worktree task. Verifies all phases are complete, commits code changes (excluding planning files), merges to target branch, and removes worktree. Can be run from any directory. Usage: /plan-cascade:complete [target-branch]

From plugin
plan-cascade
14030 skills30 commands
Install
> /plugin marketplace add Taoidle/plan-cascade
> /plugin install plan-cascade@plan-cascade

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/complete

Context preview

What this command does when you run it.

Complete a worktree task. Verifies all phases are complete, commits code changes (excluding planning files), merges to target branch, and removes worktree. Can be run from any directory. Usage: /plan-cascade:complete [target-branch]

Command definition

complete.md
description: "Complete a worktree task. Verifies all phases are complete, commits code changes (excluding planning files), merges to target branch, and removes worktree. Can be run from any directory. Usage: /plan-cascade:complete [target-branch]"

Planning with Files - Complete Worktree Task

You are now completing a worktree task. This will: 1. Verify all phases are complete 2. **CRITICAL: Commit code changes (planning files excluded)** 3. Delete planning files from the worktree 4. Navigate to the root directory 5. Merge the task branch to target branch 6. Remove the worktree 7. Delete the task branch

Path Storage Modes

This command works with both new and legacy path storage modes:

New Mode (Default)

  • Worktrees in: `~/.plan-cascade/<project-id>/.worktree/`
  • State files in: `~/.plan-cascade/<project-id>/.state/`
  • Cleanup removes files from user data directory

Legacy Mode

  • Worktrees in: `<project-root>/.worktree/`
  • State files in project root

The command auto-detects which mode is active based on `.planning-config.json` contents.

Step 1: Detect Current Location

Check if we're in a worktree or the root directory:

if [ -f ".planning-config.json" ]; then
    # We're in a worktree directory
    echo "Currently in worktree directory: $(pwd)"
    IN_WORKTREE=true
else
    # We're not in a worktree, check if there are any worktrees
    IN_WORKTREE=false

    # Check for worktrees
    WORKTREES=$(git worktree list 2>/dev/null | grep -v "\bare$" | wc -l)

    if [ "$WORKTREES" -eq 0 ]; then
        echo "ERROR: No worktrees found."
        echo "This command requires an existing worktree."
        echo ""
        echo "Create one first with:"
        echo "  /plan-cascade:worktree <task-name> <branch>"
        exit 1
    fi

    echo "Not in a worktree directory. Found $WORKTREES worktree(s):"
    echo ""
    git worktree list
    echo ""

    # Find all worktrees with .planning-config.json (check both new and legacy locations)
    echo "Scanning for planning worktrees..."
    WORKTREE_LIST=()

    # Get worktree base directory from PathResolver
    WORKTREE_BASE=$(uv run python -c "from plan_cascade.state.path_resolver import PathResolver; from pathlib import Path; print(PathResolver(Path.cwd()).get_worktree_dir())" 2>/dev/null || echo ".worktree")

    while IFS= read -r line; do
        worktree_path=$(echo "$line" | awk '{print $1}')
        worktree_branch=$(echo "$line" | awk '{print $2}')

        # Check if this is a planning worktree
        if [ -f "$worktree_path/.planning-config.json" ]; then
            # Exclude hybrid mode worktrees (those use /plan-cascade:hybrid-complete)
            mode=$(jq -r '.mode // empty' "$worktree_path/.planning-config.json" 2>/dev/null)
            if [ "$mode" != "hybrid" ]; then
                task_name=$(jq -r '.task_name // empty' "$worktree_path/.planning-config.json" 2>/dev/null)
                WORKTREE_LIST+=("$worktree_path|$task_name|$worktree_branch")
            fi
        fi
    done < <(git worktree list 2>/dev/null | grep -v "\bare$")

    if [ ${#WORKTREE_LIST[@]} -eq 0 ]; then
        echo "ERROR: No planning worktrees found."
        echo "Found worktrees but none are in planning mode."
        echo ""
        echo "Note: Hybrid mode worktrees should use /plan-cascade:hybrid-complete"
        exit 1
    fi

    echo "Found ${#WORKTREE_LIST[@]} planning worktree(s):"
    echo ""

    # Display options
    for i in "${!WORKTREE_LIST[@]}"; do
        IFS='|' read -r path name branch <<< "${WORKTREE_LIST[$i]}"
        echo "  [$((i+1))] $name"
        echo "      Path: $path"
        echo "      Branch: $branch"
        echo ""
    done

    # Ask user to select
    echo "Which worktree would you like to complete?"
    read -p "Enter number (or 0 to cancel): " selection

    if [ "$selection" = "0" ]; then
        echo "Cancelled."
        exit 0
    fi

    if [ "$selection" -lt 1 ] || [ "$selection" -gt ${#WORKTREE_LIST[@]} ]; then
        echo "Invalid selection."
        exit 1
    fi

    # Get the selected worktree
    selected="${WORKTREE_LIST[$((selection-1))]}"
    IFS='|' read -r WORKTREE_PATH TASK_NAME TASK_BRANCH <<< "$selected"

    echo ""
    echo "Selected: $TASK_NAME"
    echo "Navigating to worktree: $WORKTREE_PATH"

    # Change to worktree directory
    cd "$WORKTREE_PATH" || {
        echo "ERROR: Failed to navigate to worktree: $WORKTREE_PATH"
        exit 1
    }

    echo "✓ Now in worktree: $(pwd)"
    IN_WORKTREE=true
fi

Step 2: Read Configuration

Read the planning configuration from `.planning-config.json`:

config=$(cat .planning-config.json)
MODE=$(echo "$config" | jq -r '.mode // empty')
TASK_NAME=$(echo "$config" | jq -r '.task_name')
TASK_BRANCH=$(echo "$config" | jq -r '.task_branch')
TARGET_BRANCH=$(echo "$config" | jq -r '.target_branch')
WORKTREE_DIR=$(echo "$config" | jq -r '.worktree_dir')
ROOT_DIR=$(echo "$config" | jq -r '.root_dir')
ORIGINAL_BRANCH=$(echo "$config" | jq -r '.original_branch')

Step 3: Parse Override Target (Optional)

If user provided a target branch argument, use that instead:

OVERRIDE_TARGET="{{args|first arg or empty}}"
TARGET_FINAL="${OVERRIDE_TARGET:-$TARGET_BRANCH}"

Step 4: Verify Task Completion

Check if all phases in task_plan.md are complete:

SCRIPT_DIR="${CLAUDE_PLUGIN_ROOT:-$HOME/.claude/plugins/planning-with-files}/scripts"
if [ -f "$SCRIPT_DIR/check-complete.sh" ]; then
    bash "$SCRIPT_DIR/check-complete.sh"
fi

If the check fails (exit code 1), ask the user:

WARNING: Not all phases are marked complete

[Show the output from check-complete.sh]

Continue anyway? [y/N]:

Wait for user confirmation before proceeding.

Step 5: CRITICAL - Check for Uncommitted Code Changes

**IMPORTANT**: Planning files are NOT included in the commit. We check only actual code changes.

# Define planning files to exclude from commit
PLANNING_FILES=(
    "task_plan.md"
Read more
Ships withplan-cascade

AI-Powered Cascading Development Framework Transform complex projects into parallel executable tasks with intelligent decomposition and multi-provider execution Why Plan Cascade? • Product Editions • Quick Start • Architecture

Get the whole plugin

Other commands on plan-cascade.