Orchestrate swarms of Claude subagents with natural language
Project description
MAOS - Multi-Agent Orchestration System
Orchestrate Claude Code Subagent Swarms with Natural Language ๐ค
MAOS orchestrates multiple Claude Code instances using the official SDK, creating and managing subagent swarms through natural language commands.
๐ Quick Start (2 minutes)
Prerequisites
- Claude Code CLI installed and authenticated:
npm install -g @anthropic-ai/claude-code export ANTHROPIC_API_KEY="your-api-key" # or use 'claude login'
Install with pipx (Recommended)
# Install pipx if you don't have it
python3 -m pip install --user pipx
pipx ensurepath
# Install MAOS
pipx install maos-cli
# Start using in any project
cd ~/your-project
maos
Alternative: Install from Source
# Clone and install
git clone https://github.com/yourusername/maos.git
cd maos
pipx install -e .
# Or use pip in a virtual environment
python -m venv venv
source venv/bin/activate
pip install -e .
That's it! Now just type naturally:
MAOS> spawn 3 agents to review my code for security issues
โ Creating Claude subagents: security-auditor, reviewer, tester
โ Launching 3 Claude SDK sessions in parallel
โ Subagents created in .claude/agents/
MAOS> implement the requirements in prd.md
โ Analyzing PRD file...
โ Created specialized subagents for each requirement
โ Executing with --max-turns 10 per session
MAOS> show status
๐ Active Sessions: 3
๐ฐ Total Cost: $0.0234
โฑ๏ธ Runtime: 45 seconds
๐ฌ Natural Language Examples
No Python code needed! Just type what you want:
- "spawn a swarm of agents to deliver the requirements in prd.md"
- "create 5 parallel agents to analyze different modules"
- "review my codebase for security vulnerabilities"
- "run comprehensive tests across all services"
- "show me the status of all running agents"
- "save a checkpoint before the big refactor"
- "restore from yesterday's checkpoint"
๐ฏ What MAOS Actually Does
MAOS orchestrates multiple Claude Code SDK sessions using proper subagents:
- ๐ Creates Claude Subagents: Generates
.claude/agents/*.mdfiles with specialized prompts - ๐ SDK Mode Execution: Uses
claude -pwith--output-format jsonfor reliable automation - ๐ Session Management: Leverages
--resumeand--continuefor multi-turn conversations - โก Parallel Processing: Runs multiple SDK sessions concurrently with different subagents
- ๐ฐ Cost Tracking: Monitors API usage and costs per session
- ๐ฃ๏ธ Natural Language: No Python code needed - just chat
๐ Usage Examples
Example 1: Implement a PRD
$ python maos.py
MAOS> spawn a swarm to implement the requirements in prd.md
๐ Creating agent swarm...
โ Spawned 3 agents: architect, developer, tester
โ Analyzing prd.md...
โ Distributed 12 tasks across agents
โก Agents working in parallel:
โข architect: Designing system architecture...
โข developer: Implementing core features...
โข tester: Writing test specifications...
MAOS> show progress
๐ Swarm Progress:
โข architect: 75% complete (3/4 tasks)
โข developer: 50% complete (4/8 tasks)
โข tester: 100% complete (2/2 tasks)
MAOS> checkpoint before deployment
โ Checkpoint saved: pre-deployment-2024-01-15
Example 2: Code Review
MAOS> review my codebase for security issues and performance
๐ Spawning specialized review agents...
โ Created security-auditor agent
โ Created performance-analyzer agent
โ Starting parallel review...
๐ Review Complete:
โข Security: Found 3 medium-priority issues
โข Performance: Identified 5 optimization opportunities
MAOS> show me the security issues
๐ Security Issues Found:
1. SQL injection risk in user_controller.py:45
2. Hardcoded API key in config.py:12
3. Missing CSRF protection in forms.py:78
Example 3: Restore and Continue
MAOS> list my checkpoints
๐ Available Checkpoints:
โข pre-deployment-2024-01-15 (2 hours ago)
โข feature-complete-2024-01-14 (yesterday)
โข initial-setup-2024-01-13 (2 days ago)
MAOS> restore from pre-deployment-2024-01-15
โ Restored checkpoint successfully
โ 3 agents resumed with full context
MAOS> continue the deployment preparation
โก Agents resuming work...
๐๏ธ How It Actually Works
Architecture
Your Project Directory
โโโ .claude/agents/ # Claude subagents created by MAOS
โ โโโ developer.md # Subagent with development expertise
โ โโโ tester.md # Subagent with testing expertise
โ โโโ reviewer.md # Subagent with review expertise
โ
โโโ MAOS Orchestrator
โ โโโ ClaudeSubagentManager # Creates .claude/agents/*.md files
โ โโโ ClaudeSDKManager # Manages SDK sessions
โ โโโ NaturalLanguageProcessor # Interprets your commands
โ
โโโ Claude SDK Sessions (via 'claude -p')
โโโ Session 1: "claude -p 'task' --output-format json --resume abc123"
โโโ Session 2: "claude -p 'task' --output-format json --resume def456"
โโโ Session 3: "claude -p 'task' --output-format json --resume ghi789"
What Really Happens
- Subagent Creation: MAOS creates specialized subagents in
.claude/agents/with YAML frontmatter - SDK Execution: Uses
claude -p(non-interactive mode) with JSON output - Session Management: Each task gets a session ID for continuation with
--resume - Parallel Execution: Multiple SDK calls run concurrently via asyncio
- Natural Delegation: Claude automatically picks appropriate subagents based on task
- Cost Tracking: JSON responses include
total_cost_usdfor monitoring
โ FAQ
How is this different from just using Claude Code?
MAOS creates and manages multiple Claude subagents that work in parallel. Each subagent has specialized expertise (developer, tester, reviewer, etc.) and runs in its own SDK session. You coordinate them all through natural language.
What are Claude subagents?
Subagents are Markdown files in .claude/agents/ with YAML frontmatter defining their expertise. Claude automatically delegates tasks to appropriate subagents. MAOS creates and manages these for you.
Does this use the official Claude SDK?
Yes! MAOS uses the official @anthropic-ai/claude-code package in SDK mode (claude -p) with proper flags like --output-format json, --resume, and --max-turns.
Do I need Redis or Docker?
No! Redis and Docker are optional for advanced features. Basic functionality works with just Claude Code CLI and Python.
How does session management work?
Each Claude SDK call returns a session_id. MAOS tracks these and can continue conversations using --resume <session_id> or --continue for the most recent.
What about costs?
MAOS tracks costs via the JSON responses (total_cost_usd). Start with 2-3 parallel sessions and scale up. Each session respects --max-turns to control usage.
Can I customize the subagents?
Yes! MAOS creates standard subagents, but you can edit .claude/agents/*.md files or create your own. They're just Markdown with YAML frontmatter.
๐ ๏ธ Configuration
Subagent Templates
MAOS includes pre-configured subagent templates:
architect- System design and architecturedeveloper- Implementation and codingtester- Test creation and validationreviewer- Code review and qualitysecurity-auditor- Security analysisperformance-optimizer- Performance tuningdocumentation-writer- Documentation creation
SDK Configuration
# Default SDK settings used by MAOS
sdk_config = {
"output_format": "json", # Structured responses
"max_turns": 10, # Per session limit
"verbose": True, # Detailed logging
"permission_mode": "default", # Can be "plan" for read-only
"allowed_tools": ["Read", "Write", "Edit", "Bash", "Grep"]
}
Environment Variables (.env)
# Optional Redis URL (overrides config)
REDIS_URL=redis://localhost:6379
# Logging
LOG_LEVEL=INFO
# Monitoring
ENABLE_METRICS=true
๐งช Testing & Development
# Test Claude SDK integration
claude -p "test" --output-format json # Should return JSON
# Test MAOS installation
maos --version
# Run in development mode
python maos.py # From source directory
# Check created subagents
ls -la .claude/agents/
# Monitor costs
grep "total_cost_usd" ~/.maos/sessions.log
๐ฆ Installation Options
Option 1: PyPI with pipx (Recommended)
pipx install maos-cli
maos # Use in any directory
Option 2: From Source
git clone https://github.com/yourusername/maos.git
cd maos
pipx install -e . # Or: pip install -e .
Option 3: Docker (Optional, for Redis)
# Only if you want Redis for distributed features
docker run -d -p 6379:6379 redis:alpine
๐ง Troubleshooting
Claude Code not found
# Verify installation
which claude
claude --version
# If not installed:
npm install -g @anthropic-ai/claude-code
Redis connection failed
# Check Redis is running
redis-cli ping
# Start Redis
docker run -d -p 6379:6379 redis:7.2-alpine
Agent spawn failures
# Check Claude authentication
claude status
# Re-authenticate if needed
claude login
Context restoration issues
# Check checkpoint directory
ls -la ./maos_checkpoints/
# Verify Redis has data
redis-cli keys "maos:*"
๐ Performance Characteristics
| Metric | Typical Value | Notes |
|---|---|---|
| SDK Session Start | 1-2 seconds | Using claude -p |
| Subagent Creation | <100ms | Per .md file |
| Parallel Sessions | 2-10+ | Limited by API rate |
| JSON Parse Time | <10ms | Structured responses |
| Cost per Session | $0.01-0.10 | With --max-turns 10 |
| Session Resume | <1 second | Using --resume flag |
๐ Advanced Usage
Creating Custom Subagents
# .claude/agents/database-expert.md
---
name: database-expert
description: Database optimization and query specialist
tools: Read, Bash, Grep
---
You are a database expert specializing in SQL optimization,
schema design, and query performance tuning.
Direct SDK Usage
from maos.core.claude_sdk_manager import ClaudeSDKManager
# Use MAOS programmatically
manager = ClaudeSDKManager()
result = await manager.create_session(
prompt="Review this code",
max_turns=5,
subagents=["reviewer", "security-auditor"]
)
Production Deployment
See docs/deployment-guide.md for:
- Kubernetes deployment
- Multi-region setup
- High availability configuration
- Security hardening
๐ค Contributing
See CONTRIBUTING.md for guidelines.
๐ License
MIT License - see LICENSE file.
๐ Acknowledgments
- Built with Claude Code CLI
- Redis for distributed coordination
- The Python async community
โญ Star this repo if you find MAOS useful!
๐ฌ Questions? Open an issue or start a discussion.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file maos_cli-0.2.4.tar.gz.
File metadata
- Download URL: maos_cli-0.2.4.tar.gz
- Upload date:
- Size: 804.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fabcecf8cf60407e779d11511853121174a4856f0e11a5737bdcc37a0a677cd9
|
|
| MD5 |
00fe12103f0e25e5c79878e56e1d5a50
|
|
| BLAKE2b-256 |
113f49bcbd37a15c3b26b113553fbdfd79d89cd6d3392f187ed7eee7d189850b
|
File details
Details for the file maos_cli-0.2.4-py3-none-any.whl.
File metadata
- Download URL: maos_cli-0.2.4-py3-none-any.whl
- Upload date:
- Size: 207.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
328baccfe8d5104b7d03b60229519e023261f9e53fdfa5548b1c5d9a0de5518f
|
|
| MD5 |
598c1fd46482c89cb5b196134066fcff
|
|
| BLAKE2b-256 |
33af4f15a29fc58979215eef8a0026219ce47f788130127b4e495d82142cae23
|