v2/examples/06-tutorials/sparc-batchtool-orchestration.md
BatchTool enables powerful parallel and concurrent execution of SPARC modes, allowing for sophisticated orchestration patterns that dramatically accelerate development workflows.
Run multiple independent SPARC modes simultaneously:
batchtool run --parallel \
"npx claude-flow sparc run code 'user authentication' --non-interactive" \
"npx claude-flow sparc run code 'database schema' --non-interactive" \
"npx claude-flow sparc run code 'API endpoints' --non-interactive"
Iterative development where each phase informs the next:
batchtool orchestrate --boomerang \
--phase1 "Research and gather requirements" \
--phase2 "Design based on research" \
--phase3 "Implement the design" \
--phase4 "Test the implementation" \
--phase5 "Optimize based on test results"
Handle task dependencies intelligently:
batchtool run --dependency-aware \
--task "db:npx claude-flow sparc run code 'database layer' --non-interactive" \
--task "auth:npx claude-flow sparc run code 'auth service' --non-interactive:depends=db" \
--task "api:npx claude-flow sparc run code 'API layer' --non-interactive:depends=auth,db"
# Complete application development with SPARC + BatchTool
batchtool orchestrate --name "full-app-development" --boomerang \
--phase1-parallel "Research Phase" \
"npx claude-flow sparc run ask 'research best practices for modern web apps' --non-interactive" \
"npx claude-flow sparc run ask 'analyze competitor features' --non-interactive" \
"npx claude-flow sparc run security-review 'identify security requirements' --non-interactive" \
--phase2-sequential "Design Phase" \
"npx claude-flow sparc run spec-pseudocode 'create detailed specifications' --non-interactive" \
"npx claude-flow sparc run architect 'design system architecture' --non-interactive" \
--phase3-parallel "Implementation Phase" \
"npx claude-flow sparc run code 'implement frontend' --non-interactive" \
"npx claude-flow sparc run code 'implement backend' --non-interactive" \
"npx claude-flow sparc run code 'implement database' --non-interactive" \
--phase4-sequential "Integration Phase" \
"npx claude-flow sparc run integration 'integrate all components' --non-interactive" \
"npx claude-flow sparc run tdd 'comprehensive testing suite' --non-interactive" \
--phase5-parallel "Optimization Phase" \
"npx claude-flow sparc run optimization 'optimize performance' --non-interactive" \
"npx claude-flow sparc run security-review 'security hardening' --non-interactive" \
"npx claude-flow sparc run docs-writer 'complete documentation' --non-interactive"
# Develop multiple microservices concurrently
batchtool run --parallel --tag "microservices" \
"npx claude-flow sparc run code 'user-service' --non-interactive" \
"npx claude-flow sparc run code 'auth-service' --non-interactive" \
"npx claude-flow sparc run code 'notification-service' --non-interactive" \
"npx claude-flow sparc run code 'payment-service' --non-interactive" \
"npx claude-flow sparc run code 'api-gateway' --non-interactive"
# Then integrate and test
batchtool run --sequential \
"npx claude-flow sparc run integration 'integrate all microservices' --non-interactive" \
"npx claude-flow sparc run tdd 'end-to-end testing' --non-interactive" \
"npx claude-flow sparc run devops 'kubernetes deployment' --non-interactive"
# Sprint planning and execution
batchtool orchestrate --sprint "feature-sprint-1" \
--planning \
"npx claude-flow sparc run sparc 'break down epic into features' --non-interactive" \
--development-parallel \
"npx claude-flow sparc run code 'feature: user profile' --non-interactive" \
"npx claude-flow sparc run code 'feature: notifications' --non-interactive" \
"npx claude-flow sparc run code 'feature: settings page' --non-interactive" \
--testing-parallel \
"npx claude-flow sparc run tdd 'test user profile' --non-interactive" \
"npx claude-flow sparc run tdd 'test notifications' --non-interactive" \
"npx claude-flow sparc run tdd 'test settings' --non-interactive" \
--review \
"npx claude-flow sparc run security-review 'audit all features' --non-interactive" \
"npx claude-flow sparc run optimization 'performance review' --non-interactive"
# Continuous improvement cycle
while true; do
batchtool orchestrate --boomerang \
--monitor "npx claude-flow sparc run monitoring 'analyze metrics' --non-interactive" \
--identify "npx claude-flow sparc run debug 'identify bottlenecks' --non-interactive" \
--optimize "npx claude-flow sparc run optimization 'improve performance' --non-interactive" \
--validate "npx claude-flow sparc run tdd 'verify improvements' --non-interactive"
sleep 3600 # Run every hour
done
# Implement two approaches in parallel and compare
batchtool run --ab-test \
--variant-a "npx claude-flow sparc run code 'implement with approach A' --non-interactive" \
--variant-b "npx claude-flow sparc run code 'implement with approach B' --non-interactive" \
--compare "npx claude-flow sparc run optimization 'compare performance' --non-interactive"
# Build features progressively
batchtool orchestrate --progressive \
--mvp "npx claude-flow sparc run code 'minimal viable product' --non-interactive" \
--enhance-1 "npx claude-flow sparc run code 'add user authentication' --non-interactive" \
--enhance-2 "npx claude-flow sparc run code 'add real-time updates' --non-interactive" \
--enhance-3 "npx claude-flow sparc run code 'add analytics' --non-interactive" \
--polish "npx claude-flow sparc run optimization 'final optimizations' --non-interactive"
# Monitor all running SPARC tasks
batchtool monitor --dashboard --refresh 5s
# Get status of specific orchestration
batchtool status --orchestration "full-app-development"
# View logs from all parallel executions
batchtool logs --follow --filter "error|warning"
# Limit concurrent executions
batchtool config --max-concurrent 5
# Set memory limits per task
batchtool run --memory-limit 2GB \
"npx claude-flow sparc run code 'heavy processing task' --non-interactive"
# Priority-based execution
batchtool run --priority high \
"npx claude-flow sparc run security-review 'urgent security audit' --non-interactive"
Use --non-interactive for all BatchTool orchestrations
Tag related tasks for easier management
batchtool run --tag "auth-system" --parallel ...
Implement proper error handling
batchtool run --on-error retry --max-retries 3 ...
Use memory namespaces to share context
--namespace "project-x-auth"
Monitor resource usage
batchtool stats --orchestration "my-workflow"
# Example GitHub Actions workflow
name: SPARC Development Pipeline
on: [push]
jobs:
develop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
npm install -g claude-flow
npm install -g batchtool
- name: Run SPARC orchestration
run: |
batchtool orchestrate --boomerang \
--analyze "npx claude-flow sparc run architect 'analyze changes' --non-interactive" \
--implement "npx claude-flow sparc run code 'implement features' --non-interactive" \
--test "npx claude-flow sparc run tdd 'run tests' --non-interactive" \
--deploy "npx claude-flow sparc run devops 'deploy to staging' --non-interactive"
# Enable verbose logging
batchtool run --verbose --debug ...
# Dry run to see execution plan
batchtool orchestrate --dry-run ...
# Export orchestration plan
batchtool export --format json --output plan.json