# API Reference - Complete API Documentation This comprehensive reference documents all Claude Flow commands, their parameters, return values, and usage examples. ## Core Commands ### `claude-flow` Main entry point for all Claude Flow operations. ```bash claude-flow [command] [options] ``` **Global Options:** - `--version, -v` - Display version information - `--help, -h` - Show help for command - `--config, -c ` - Specify config file location - `--verbose` - Enable verbose logging - `--json` - Output in JSON format - `--no-color` - Disable colored output ## Swarm Management ### `swarm init` Initialize a new swarm with specified topology and configuration. ```bash claude-flow swarm init [options] ``` **Parameters:** - `--topology, -t ` - **Required**. Swarm topology: `hierarchical`, `mesh`, `ring`, `star` - `--max-agents, -m ` - Maximum number of agents (default: 8) - `--strategy, -s ` - Coordination strategy: `auto`, `manual`, `adaptive` (default: auto) - `--name, -n ` - Swarm identifier name - `--memory-pool ` - Shared memory pool size in MB **Returns:** ```json { "swarmId": "swarm-123456", "topology": "hierarchical", "maxAgents": 8, "status": "initialized", "createdAt": "2024-01-15T10:30:00Z" } ``` **Example:** ```bash claude-flow swarm init \ --topology hierarchical \ --max-agents 12 \ --name "dev-team" \ --memory-pool 256 ``` ### `swarm status` Monitor swarm health and performance metrics. ```bash claude-flow swarm status [swarmId] [options] ``` **Parameters:** - `swarmId` - Optional swarm identifier (uses current if omitted) - `--detailed, -d` - Show detailed agent information - `--metrics, -m` - Include performance metrics - `--watch, -w` - Continuous monitoring mode **Returns:** ```json { "swarmId": "swarm-123456", "topology": "hierarchical", "agents": { "total": 8, "active": 6, "idle": 2 }, "health": "healthy", "uptime": "2h 15m", "tasksCompleted": 145, "performance": { "avgResponseTime": "1.2s", "throughput": "12 tasks/min" } } ``` ### `swarm scale` Dynamically adjust swarm size. ```bash claude-flow swarm scale [options] ``` **Parameters:** - `targetSize` - **Required**. Target number of agents - `--swarm-id, -s ` - Swarm to scale - `--strategy ` - Scaling strategy: `immediate`, `gradual`, `auto` - `--min ` - Minimum agents to maintain - `--max ` - Maximum agents allowed **Example:** ```bash claude-flow swarm scale 15 \ --strategy gradual \ --min 5 \ --max 20 ``` ### `swarm destroy` Gracefully shutdown a swarm. ```bash claude-flow swarm destroy [options] ``` **Parameters:** - `swarmId` - **Required**. Swarm identifier to destroy - `--force, -f` - Force immediate shutdown - `--save-state` - Save swarm state before destruction - `--timeout ` - Shutdown timeout (default: 30) ## Agent Management ### `agent spawn` Create specialized AI agents for specific tasks. ```bash claude-flow agent spawn [options] ``` **Parameters:** - `type` - **Required**. Agent type (see [Agent Types](#agent-types)) - `--task, -t ` - Task description for agent - `--capabilities, -c ` - Comma-separated capabilities - `--swarm-id, -s ` - Target swarm for agent - `--priority ` - Task priority: `low`, `medium`, `high`, `critical` - `--timeout ` - Task timeout - `--memory-access ` - Memory access: `read`, `write`, `read-write` **Returns:** ```json { "agentId": "agent-789012", "type": "coder", "status": "active", "task": "Implement user authentication", "swarmId": "swarm-123456", "capabilities": ["typescript", "nodejs", "testing"] } ``` **Example:** ```bash claude-flow agent spawn backend-dev \ --task "Create REST API for user management" \ --capabilities "nodejs,express,postgresql" \ --priority high \ --memory-access read-write ``` ### `agent list` List active agents and their capabilities. ```bash claude-flow agent list [options] ``` **Parameters:** - `--swarm-id, -s ` - Filter by swarm - `--type, -t ` - Filter by agent type - `--status ` - Filter by status: `active`, `idle`, `busy` - `--detailed, -d` - Show detailed information **Returns:** ```json { "agents": [ { "id": "agent-001", "type": "coder", "status": "busy", "currentTask": "Implementing auth service", "uptime": "45m", "tasksCompleted": 12 } ], "total": 8, "byType": { "coder": 3, "tester": 2, "reviewer": 1, "planner": 2 } } ``` ### `agent metrics` Get performance metrics for specific agent. ```bash claude-flow agent metrics [options] ``` **Parameters:** - `agentId` - **Required**. Agent identifier - `--period, -p ` - Time period: `1h`, `24h`, `7d`, `30d` - `--metrics, -m ` - Specific metrics to include **Returns:** ```json { "agentId": "agent-789012", "metrics": { "tasksCompleted": 45, "avgCompletionTime": "12.5 min", "successRate": "95.5%", "resourceUsage": { "cpu": "25%", "memory": "512MB" } } } ``` ## Task Orchestration ### `task orchestrate` Orchestrate complex task workflows across agents. ```bash claude-flow task orchestrate [options] ``` **Parameters:** - `--task, -t ` - **Required**. Task description - `--strategy, -s ` - Execution strategy: `parallel`, `sequential`, `adaptive`, `balanced` - `--dependencies, -d ` - Task dependencies - `--priority, -p ` - Priority level - `--checkpoint` - Enable checkpointing - `--memory-sync` - Synchronize memory across agents - `--max-concurrent ` - Maximum concurrent operations **Example:** ```bash claude-flow task orchestrate \ --task "Refactor authentication system" \ --strategy parallel \ --checkpoint \ --memory-sync \ --max-concurrent 5 ``` ### `task status` Check task execution status. ```bash claude-flow task status [options] ``` **Parameters:** - `taskId` - **Required**. Task identifier - `--detailed, -d` - Show subtask details - `--watch, -w` - Watch for updates **Returns:** ```json { "taskId": "task-345678", "status": "in-progress", "progress": 65, "subtasks": { "completed": 4, "inProgress": 2, "pending": 1 }, "estimatedCompletion": "15 min" } ``` ### `task results` Retrieve task completion results. ```bash claude-flow task results [options] ``` **Parameters:** - `taskId` - **Required**. Task identifier - `--format, -f ` - Output format: `json`, `summary`, `detailed` - `--artifacts` - Include generated artifacts ## Memory Management ### `memory usage` Store, retrieve, and manage persistent memory. ```bash claude-flow memory usage [options] ``` **Parameters:** - `--action, -a ` - **Required**. Action: `store`, `retrieve`, `list`, `delete`, `search` - `--key, -k ` - Memory key (required for store/retrieve/delete) - `--value, -v ` - Value to store (required for store) - `--namespace, -n ` - Memory namespace (default: "default") - `--ttl ` - Time to live in seconds **Examples:** ```bash # Store memory claude-flow memory usage \ --action store \ --key "project-config" \ --value '{"database": "postgresql", "cache": "redis"}' \ --namespace "architecture" \ --ttl 86400 # Retrieve memory claude-flow memory usage \ --action retrieve \ --key "project-config" \ --namespace "architecture" # List memories claude-flow memory usage \ --action list \ --namespace "architecture" ``` ### `memory search` Search memory with patterns. ```bash claude-flow memory search [options] ``` **Parameters:** - `pattern` - **Required**. Search pattern (supports wildcards) - `--namespace, -n ` - Limit to namespace - `--limit, -l ` - Maximum results (default: 10) - `--regex` - Use regex pattern matching **Example:** ```bash claude-flow memory search "auth*" \ --namespace "decisions" \ --limit 20 ``` ### `memory backup` Create memory backups. ```bash claude-flow memory backup [options] ``` **Parameters:** - `--path, -p ` - Backup destination path - `--compress` - Compress backup - `--encrypt` - Encrypt backup - `--namespace ` - Specific namespace to backup ### `memory restore` Restore from memory backup. ```bash claude-flow memory restore [options] ``` **Parameters:** - `backupPath` - **Required**. Path to backup file - `--overwrite` - Overwrite existing memories - `--namespace ` - Restore to specific namespace ## Neural Network Operations ### `neural train` Train neural patterns with WASM SIMD acceleration. ```bash claude-flow neural train [options] ``` **Parameters:** - `--pattern-type, -p ` - **Required**. Pattern type: `coordination`, `optimization`, `prediction` - `--training-data, -d ` - **Required**. Training data or file path - `--epochs, -e ` - Training epochs (default: 50) - `--model-id, -m ` - Model identifier - `--learning-rate ` - Learning rate (default: 0.001) **Example:** ```bash claude-flow neural train \ --pattern-type optimization \ --training-data "./data/performance-metrics.json" \ --epochs 100 \ --model-id "perf-optimizer-v2" ``` ### `neural predict` Make predictions using trained models. ```bash claude-flow neural predict [options] ``` **Parameters:** - `--model-id, -m ` - **Required**. Model identifier - `--input, -i ` - **Required**. Input data for prediction - `--confidence` - Include confidence scores - `--explain` - Include prediction explanation **Returns:** ```json { "prediction": "high-load", "confidence": 0.92, "explanation": { "factors": [ { "feature": "request_rate", "impact": 0.45 }, { "feature": "time_of_day", "impact": 0.28 } ] } } ``` ### `neural status` Check neural network status. ```bash claude-flow neural status [modelId] [options] ``` **Parameters:** - `modelId` - Optional model identifier - `--detailed, -d` - Show detailed metrics - `--performance` - Include performance benchmarks ## GitHub Integration ### `github repo analyze` Comprehensive repository analysis. ```bash claude-flow github repo analyze [options] ``` **Parameters:** - `repo` - **Required**. Repository in format `owner/repo` - `--analysis-type, -t ` - Analysis type: `code_quality`, `performance`, `security` - `--branch, -b ` - Target branch (default: main) - `--depth ` - Analysis depth: `shallow`, `normal`, `deep` **Example:** ```bash claude-flow github repo analyze myorg/myrepo \ --analysis-type security \ --depth deep ``` ### `github pr manage` Pull request management operations. ```bash claude-flow github pr manage [options] ``` **Parameters:** - `--repo, -r ` - **Required**. Repository - `--action, -a ` - **Required**. Action: `review`, `merge`, `close` - `--pr-number, -p ` - PR number - `--auto-merge` - Enable auto-merge - `--squash` - Squash commits on merge ## SPARC Methodology ### `sparc run` Execute specific SPARC phase. ```bash claude-flow sparc run [options] ``` **Parameters:** - `mode` - **Required**. SPARC mode: `specification`, `pseudocode`, `architecture`, `refinement`, `completion` - `task` - **Required**. Task description - `--parallel` - Enable parallel processing - `--memory-persist` - Persist artifacts to memory - `--include ` - Additional items to include **Example:** ```bash claude-flow sparc run architecture \ "Design microservices for e-commerce platform" \ --parallel \ --memory-persist ``` ### `sparc tdd` Run complete TDD workflow using SPARC. ```bash claude-flow sparc tdd [options] ``` **Parameters:** - `feature` - **Required**. Feature description - `--test-first` - Enforce test-first development - `--coverage ` - Minimum coverage requirement - `--style