1. Bottleneck Detection
#### Command Syntax
```bash
npx claude-flow bottleneck detect [options]
```
#### Options
--swarm-id, -s - Analyze specific swarm (default: current)--time-range, -t - Analysis period: 1h, 24h, 7d, all (default: 1h)--threshold - Bottleneck threshold percentage (default: 20)--export, -e - Export analysis to file--fix - Apply automatic optimizations
#### Usage Examples
```bash
# Basic detection for current swarm
npx claude-flow bottleneck detect
# Analyze specific swarm over 24 hours
npx claude-flow bottleneck detect --swarm-id swarm-123 -t 24h
# Export detailed analysis
npx claude-flow bottleneck detect -t 24h -e bottlenecks.json
# Auto-fix detected issues
npx claude-flow bottleneck detect --fix --threshold 15
# Low threshold for sensitive detection
npx claude-flow bottleneck detect --threshold 10 --export critical-issues.json
```
#### Metrics Analyzed
Communication Bottlenecks:
- Message queue delays
- Agent response times
- Coordination overhead
- Memory access patterns
- Inter-agent communication latency
Processing Bottlenecks:
- Task completion times
- Agent utilization rates
- Parallel execution efficiency
- Resource contention
- CPU/memory usage patterns
Memory Bottlenecks:
- Cache hit rates
- Memory access patterns
- Storage I/O performance
- Neural pattern loading times
- Memory allocation efficiency
Network Bottlenecks:
- API call latency
- MCP communication delays
- External service timeouts
- Concurrent request limits
- Network throughput issues
#### Output Format
```
π Bottleneck Analysis Report
βββββββββββββββββββββββββββ
π Summary
βββ Time Range: Last 1 hour
βββ Agents Analyzed: 6
βββ Tasks Processed: 42
βββ Critical Issues: 2
π¨ Critical Bottlenecks
- Agent Communication (35% impact)
βββ coordinator β coder-1 messages delayed by 2.3s avg
- Memory Access (28% impact)
βββ Neural pattern loading taking 1.8s per access
β οΈ Warning Bottlenecks
- Task Queue (18% impact)
βββ 5 tasks waiting > 10s for assignment
π‘ Recommendations
- Switch to hierarchical topology (est. 40% improvement)
- Enable memory caching (est. 25% improvement)
- Increase agent concurrency to 8 (est. 20% improvement)
β
Quick Fixes Available
Run with --fix to apply:
- Enable smart caching
- Optimize message routing
- Adjust agent priorities
```
2. Performance Profiling
#### Real-time Detection
Automatic analysis during task execution:
- Execution time vs. complexity
- Agent utilization rates
- Resource constraints
- Operation patterns
#### Common Bottleneck Patterns
Time Bottlenecks:
- Tasks taking > 5 minutes
- Sequential operations that could parallelize
- Redundant file operations
- Inefficient algorithm implementations
Coordination Bottlenecks:
- Single agent for complex tasks
- Unbalanced agent workloads
- Poor topology selection
- Excessive synchronization points
Resource Bottlenecks:
- High operation count (> 100)
- Memory constraints
- I/O limitations
- Thread pool saturation
#### MCP Integration
```javascript
// Check for bottlenecks in Claude Code
mcp__claude-flow__bottleneck_detect({
timeRange: "1h",
threshold: 20,
autoFix: false
})
// Get detailed task results with bottleneck analysis
mcp__claude-flow__task_results({
taskId: "task-123",
format: "detailed"
})
```
Result Format:
```json
{
"bottlenecks": [
{
"type": "coordination",
"severity": "high",
"description": "Single agent used for complex task",
"recommendation": "Spawn specialized agents for parallel work",
"impact": "35%",
"affectedComponents": ["coordinator", "coder-1"]
}
],
"improvements": [
{
"area": "execution_time",
"suggestion": "Use parallel task execution",
"expectedImprovement": "30-50% time reduction",
"implementationSteps": [
"Split task into smaller units",
"Spawn 3-4 specialized agents",
"Use mesh topology for coordination"
]
}
],
"metrics": {
"avgExecutionTime": "142s",
"agentUtilization": "67%",
"cacheHitRate": "82%",
"parallelizationFactor": 1.2
}
}
```
3. Report Generation
#### Command Syntax
```bash
npx claude-flow analysis performance-report [options]
```
#### Options
--format - Report format: json, html, markdown (default: markdown)--include-metrics - Include detailed metrics and charts--compare - Compare with previous swarm--time-range - Analysis period: 1h, 24h, 7d, 30d, all--output - Output file path--sections
- Comma-separated sections to include
#### Report Sections
- Executive Summary
- Overall performance score
- Key metrics overview
- Critical findings
- Swarm Overview
- Topology configuration
- Agent distribution
- Task statistics
- Performance Metrics
- Execution times
- Throughput analysis
- Resource utilization
- Latency breakdown
- Bottleneck Analysis
- Identified bottlenecks
- Impact assessment
- Optimization priorities
- Comparative Analysis (when --compare used)
- Performance trends
- Improvement metrics
- Regression detection
- Recommendations
- Prioritized action items
- Expected improvements
- Implementation guidance
#### Usage Examples
```bash
# Generate HTML report with all metrics
npx claude-flow analysis performance-report --format html --include-metrics
# Compare current swarm with previous
npx claude-flow analysis performance-report --compare swarm-123 --format markdown
# Custom output with specific sections
npx claude-flow analysis performance-report \
--sections summary,metrics,recommendations \
--output reports/perf-analysis.html \
--format html
# Weekly performance report
npx claude-flow analysis performance-report \
--time-range 7d \
--include-metrics \
--format markdown \
--output docs/weekly-performance.md
# JSON format for CI/CD integration
npx claude-flow analysis performance-report \
--format json \
--output build/performance.json
```
#### Sample Markdown Report
```markdown
# Performance Analysis Report