/headless - Enhanced Planning + Headless Development
Creates isolated git worktree with detailed plan and generates headless execution command for review.
/plugin marketplace add jleechanorg/claude-commands/plugin install claude-commands@claude-commands-marketplaceWhen this command is invoked, YOU (Claude) must execute these steps immediately: This is NOT documentation - these are COMMANDS to execute right now. Use TodoWrite to track progress through multi-phase workflows.
Action Steps:
Purpose: Combine /handoff planning with /headless automation - creates detailed analysis then generates copy-paste command for headless execution
Usage: /headless [prompt]
Enhanced Workflow:
Phase 1 - Planning (from /handoff):
Phase 2 - Command Generation:
Implementation:
#!/bin/bash
# Get the prompt from arguments
PROMPT="$*"
if [ -z "$PROMPT" ]; then
echo "ā Error: No prompt provided"
echo "Usage: /headless [prompt]"
exit 1
fi
# Generate a unique branch name based on timestamp and prompt
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BRANCH_NAME="headless_${TIMESTAMP}"
WORKTREE_DIR="headless_${TIMESTAMP}"
echo "š Creating headless development environment..."
echo "Branch: $BRANCH_NAME"
echo "Worktree: $WORKTREE_DIR"
echo "Prompt: $PROMPT"
# Determine the default branch dynamically
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
# Create git worktree with new branch from the default branch
git worktree add -b "$BRANCH_NAME" "$WORKTREE_DIR" "$DEFAULT_BRANCH"
if [ $? -ne 0 ]; then
echo "ā Error: Failed to create git worktree"
exit 1
fi
# Change to worktree directory
cd "$WORKTREE_DIR"
echo "š Working in: $(pwd)"
echo "šÆ Running Claude Code headlessly..."
# Run Claude Code in headless mode with stream monitoring
claude -p "$PROMPT" --output-format stream-json --verbose --dangerously-skip-permissions
if [ $? -ne 0 ]; then
echo "ā Error: Claude Code execution failed"
cd ..
git worktree remove "$WORKTREE_DIR"
exit 1
fi
echo "ā
Claude Code execution completed"
echo "š Creating pull request..."
# Run /pr command to create PR
if [ -f ".claude/commands/pr.md" ] && [ -x "./claude_command_scripts/pr.sh" ]; then
# Extract and run the PR creation logic
./claude_command_scripts/pr.sh
else
echo "ā ļø /pr command or script not found or not executable, creating PR manually..."
# Push the branch
git push -u origin "$BRANCH_NAME"
# Create PR using gh
gh pr create --title "Headless: $(echo "$PROMPT" | cut -c1-50)..." --body "$(cat <<EOF
## Automated Headless Development
**Prompt**: $PROMPT
**Branch**: $BRANCH_NAME
**Generated**: $(date)
This PR was created automatically using the /headless command.
š¤ Generated with [Claude Code](https://claude.ai/code)
EOF
)"
fi
echo "š Headless development completed!"
echo "š Worktree location: $WORKTREE_DIR"
echo "šæ Branch: $BRANCH_NAME"
# Return to original directory
cd ..
Enhanced Features:
/handoff)Safety Features:
--dangerously-skip-permissions for true headless operationExample Usage:
/headless "Add user authentication system with login/logout functionality"
/headless "Fix the responsive design issues on mobile devices"
/headless "Implement automated testing for the payment processing module"
Example Output:
š Enhanced Headless Development with Planning
Task: Add user authentication system
Branch: headless_20250718_143022
Worktree: headless_20250718_143022
š Phase 1: Creating Analysis and Planning
š Creating isolated worktree...
š Working in: /path/to/headless_20250718_143022
š Creating detailed planning scratchpad...
================================================================================
ā
PLANNING PHASE COMPLETE
================================================================================
š Planning file: roadmap/scratchpad_headless_20250718_143022.md
šæ Branch: headless_20250718_143022 (pushed to remote)
š Worktree: /path/to/headless_20250718_143022
================================================================================
š¤ HEADLESS COMMAND READY (Copy & Paste)
================================================================================
claude -p "TASK: Add user authentication system
CONTEXT: Complete analysis and implementation plan available
WORKTREE: /path/to/headless_20250718_143022
BRANCH: headless_20250718_143022
SETUP: Already in isolated worktree with clean branch
GOAL: Add user authentication system
IMPLEMENTATION: See detailed plan below
FILES TO MODIFY: See specific file list in implementation section
SUCCESS CRITERIA: All requirements met with tests passing
TIMELINE: Implement according to step-by-step plan
FULL SPECIFICATION: /path/to/headless_20250718_143022/roadmap/scratchpad_headless_20250718_143022.md
START: Implement the detailed plan below" --output-format stream-json --verbose --dangerously-skip-permissions
================================================================================
š Next Steps:
1. Review the generated plan in: roadmap/scratchpad_headless_20250718_143022.md
2. Modify the plan if needed (add details, adjust approach)
3. Copy and paste the command above when ready to execute
4. The command will run Claude in headless mode in this worktree
ā
Ready for headless execution!
Integration with Orchestration System: