Orchestration system for Claude Code with memory-driven planning, multi-agent coordination, Agent Teams integration, and automatic learning.
Ralph extends Claude Code with intelligent orchestration capabilities. It classifies tasks, routes to appropriate models, coordinates multiple agents, and maintains persistent memory across sessions.
Key capabilities:
- Agent Teams Integration - Multiple Claude Code instances working in parallel
- Task classification and routing
- Parallel memory search across multiple backends
- Multi-agent coordination with swarm mode
- Automatic learning from GitHub repositories
- Quality validation with adversarial review
- Session state management with checkpoints
Current: v2.93.0
- Memory System Optimization — Smart memory search re-enabled + cleanup policies implemented
- Re-enabled
smart-memory-search.shhook (700+ lines of parallel memory search) - Implemented episodic memory cleanup: 30-day TTL (previously: NO cleanup)
- Removed redundant storage: memvid.json (175KB) and semantic.json (62KB)
- Streamlined to primary memory storage: claude-mem + episodic + handoffs + ledgers
- Removed memvid integration from
ralphCLI (tool definition + validation)
- Re-enabled
- Removed Obsolete Dependencies — Cleaned up llm-tldr and claude-sneakpeek references
- Removed
llm-tldrintegration (hook, tests, CLI command) - Removed
claude-sneakpeekhistorical references - Updated context tree to use ast-grep backend instead of llm-tldr
- Simplified architecture without deprecated tooling
- Removed
- Optional Code Quality Improvements — Enhanced defensive coding practices
- API key validation: Format checking (minimum length, placeholder detection)
- JSON error handling: Comprehensive try/except blocks in 2 files
- Subprocess safety validation: All patterns confirmed safe
- Console.log analysis: All uses verified as legitimate
- Security grade: Maintained at A- with enhanced robustness
- SQL injection warnings: Added to 7 test files for security awareness
- MCP Servers Integration — Structural code search and Zai vision capabilities
- ast-grep MCP: AST-based code search (13 MCP servers total)
- Tool selection guide: ast-grep vs Grep vs Glob based on benchmark results
- 4 cases where only ast-grep works: containment, blocks, negation, scope-aware
- Complete rule reference (atomic, relational, composite, metavariables)
- Zai MCP Servers: 4 servers with 13 tools
zai-mcp-server: 8 vision tools (ui_to_artifact, extract_text, diagnose_error, etc.)web-search-prime: Web search with rich resultsweb-reader: Full webpage content extractionzread: GitHub repository documentation (search_doc, read_file, get_repo_structure)
- ast-grep MCP: AST-based code search (13 MCP servers total)
- v2.89.2 - Hooks alignment with official Claude Code hooks guide, 15 additional security fixes
- v2.89.1 - 14 security vulnerability fixes (command chaining, SHA-256 checksums, deny list expansion, settings self-protection, file locking, SEC-111 compliance), 37 security tests, threat model documentation
- v2.88.2 - LSP Integration, Batch Task Execution, 950+ BATS tests passing
- v2.88.0 - Agent Teams, Multi-Agent Scenarios,
/task-batchand/create-task-batchskills - v2.86.0 - Session Lifecycle Hooks, Agent Teams hooks
- v2.84.1 - GLM-5 integration, model-agnostic architecture
- Claude Code v2.1.42 or higher (for Agent Teams + SessionEnd support)
- GLM-5 API access (configured via Z.AI)
- Bash 4.0+
- jq 1.6+
- git 2.0+
- curl
Optional:
- GitHub CLI (
gh) for enhanced API access - Zai CLI (
@z_ai/coding-helper) for MCP server management uvpackage manager for ast-grep MCP serverast-grepbinary for structural code search
# Clone repository
git clone https://github.com/alfredolopez80/multi-agent-ralph-loop.git
cd multi-agent-ralph-loop
# Run setup script (creates symlinks)
./.claude/scripts/centralize-all.sh
# Verify installation
ralph health --compact
# Run orchestration (uses configured default model)
/orchestrator "Create a REST API endpoint"
# Complex task with swarm mode
/orchestrator "Implement distributed caching" --launch-swarm --teammate-count 3Ensure you have the following installed:
| Tool | Version | Purpose |
|---|---|---|
| Claude Code | v2.1.42+ | Main CLI tool |
| Bash | 3.2+ | Shell scripts |
| jq | 1.6+ | JSON processing |
| git | 2.0+ | Version control |
| curl | Any | HTTP requests |
| python3 | 3.8+ | Python tooling |
git clone https://github.com/alfredolopez80/multi-agent-ralph-loop.git
cd multi-agent-ralph-loopThis script creates symlinks from your global ~/.claude/ directory to the repository:
./.claude/scripts/centralize-all.shWhat it does:
- Creates backup of existing configuration
- Symlinks skills from repository to
~/.claude/skills/ - Symlinks agents from repository to
~/.claude/agents/ - Consolidates plugins from multiple sources
LSP provides intelligent code navigation for skills like /gates, /security, and /code-reviewer:
# Install essential language servers (TypeScript, Python, C/C++, Swift)
./scripts/install-language-servers.sh --essential
# Or install all servers including optional ones
./scripts/install-language-servers.sh --all
# Check what's installed
./scripts/install-language-servers.sh --checkEssential Language Servers:
| Server | Language | Install Command |
|---|---|---|
typescript-language-server |
TypeScript/JavaScript | npm install -g typescript-language-server typescript |
pyright |
Python | npm install -g pyright |
clangd |
C/C++ | brew install llvm (macOS) or system package |
sourcekit-lsp |
Swift | Included with Xcode (macOS) |
Optional Language Servers:
bash-language-server- Shell scriptsdockerfile-language-server- Dockerfilesyaml-language-server- YAML filesjson-language-server- JSON fileshtml-language-server- HTMLcss-language-server- CSS
./scripts/install-security-tools.shThis installs:
semgrep- Static analysis for securitygitleaks- Secret detection
Run the comprehensive validation script:
# Full validation
./scripts/validate-installation.sh
# Quick check (critical only)
./scripts/validate-installation.sh --quick
# Verbose output
./scripts/validate-installation.sh --verbose
# JSON output for CI/CD
./scripts/validate-installation.sh --format jsonValidation checks:
- System Requirements - Required tools and versions
- Shell Environment - PATH, aliases, environment
- Directory Structure - Required directories and permissions
- Hooks Registration - All hooks registered and executable
- Skills Registration - All skills properly installed
- Agents Registration - All agents properly defined
- LSP Servers - Language servers availability
ralph health --compactExpected output:
✓ System healthy
✓ Memory system operational
✓ LSP servers available: typescript-language-server, pyright, clangd
✓ Hooks registered: 89
✓ Skills available: 30+
✓ Agents available: 46
The project includes comprehensive test suites to verify everything works:
# Run all installer tests
bats tests/installer/
# Run specific test suites
bats tests/installer/test-complete-installation.bats # 55 tests
bats tests/installer/test-lsp-usage-validation.bats # 36 tests
# Run all integration tests
./tests/test_all_integration.shIf language servers are not detected:
# Check if servers are in PATH
which typescript-language-server
which pyright
which clangd
# Verify npm global packages
npm list -g --depth=0 | grep -E 'typescript-language-server|pyright'
# Reinstall language servers
./scripts/install-language-servers.sh --essential --forceIf hooks are not running:
# Validate hook registration
./scripts/validate-all-hooks.sh
# Check hook permissions
chmod +x .claude/hooks/*.sh
chmod +x .claude/hooks/*.pyIf skills are not showing up:
# Re-run centralization
./.claude/scripts/centralize-all.sh
# Verify symlinks
ls -la ~/.claude/skills/ | head -20If Agent Teams features aren't working:
# Check Claude Code version
claude --version # Should be v2.1.39+
# Verify Agent Teams is enabled
grep -A5 '"env"' ~/.claude/settings.json | grep AGENT_TEAMSUser Request
|
v
Claude Code (v2.1.39+)
|
v
+-------------------+
| ~/.claude/ |
| settings.json | -- Hook registration & Agent Teams config
+-------------------+
|
v
+-------------------+ +------------------+
| Memory Systems | | Learning System |
| - claude-mem MCP | | - Repo curation |
| - Local JSON | | - Pattern extract|
| - Ledgers | | - Rule validation|
+-------------------+ +------------------+
| |
v v
+-------------------------------------------+
| Orchestration Layer |
| - Task classification (1-10 complexity) |
| - Model routing (GLM-5 primary) |
| - Agent Teams coordination |
| - Quality gates validation |
+-------------------------------------------+
|
v
+-------------------------------------------+
| Agent Teams (v2.86) |
| - ralph-coder (implementation) |
| - ralph-reviewer (code review) |
| - ralph-tester (testing & QA) |
| - ralph-researcher (research) |
+-------------------------------------------+
|
v
Implementation / Analysis / Review
multi-agent-ralph-loop/
├── .claude/
│ ├── agents/ # 46 agent definitions (4 ralph-* + 42 specialized)
│ ├── commands/ # 41 slash commands
│ ├── hooks/ # 89 hook scripts
│ ├── skills/ # Ralph-specific skills
│ └── scripts/ # Utility scripts
├── docs/ # Architecture and guides
│ └── agent-teams/ # Agent Teams documentation
├── scripts/ # CLI utilities
├── tests/ # Test suites
│ ├── session-lifecycle/ # Session lifecycle tests
│ └── agent-teams/ # Agent Teams tests
└── .ralph/ # Session data (not in repo)
Custom subagents for parallel execution:
| Agent | Role | Tools | Max Turns |
|---|---|---|---|
ralph-coder |
Code implementation | Read, Edit, Write, Bash | 50 |
ralph-reviewer |
Code review | Read, Grep, Glob | 25 |
ralph-tester |
Testing & QA | Read, Edit, Write, Bash(test) | 30 |
ralph-researcher |
Research | Read, Grep, Glob, WebSearch, WebFetch | 20 |
All subagents use the configured default model from ~/.claude/settings.json.
Model Configuration (in ~/.claude/settings.json):
{
"env": {
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5",
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}The system is model-agnostic - change the model in settings and all skills/agents automatically use it.
# Spawn teammates (uses configured default model)
Task(subagent_type="ralph-coder", team_name="my-project")
Task(subagent_type="ralph-reviewer", team_name="my-project")The Ralph system supports three distinct execution scenarios for multi-agent coordination. Each skill is configured with its optimal scenario based on task requirements.
| Scenario | Description | Best For |
|---|---|---|
| A: Pure Agent Teams | Native Claude Code teams with built-in coordination | Simple coordination, low specialization |
| B: Custom Subagents | Direct spawn of ralph-* agents without team overhead | Specialized tasks, independent execution |
| C: Integrated | TeamCreate + ralph-* subagents + quality hooks | Complex workflows, production-grade |
Uses native Claude Code team coordination with TeamCreate, TaskCreate, TaskUpdate, and SendMessage tools. Best for tasks requiring simple coordination without specialized agent behavior.
Characteristics:
- Native Claude Code integration
- Automatic task coordination via shared task list
- Built-in quality gates via hooks
- No custom agent specialization
Skills using Scenario A:
clarify- Sequential question flowretrospective- Single-threaded analysisglm5-parallel- Same-type parallel execution
Direct spawn of specialized ralph-* agents via the Task tool. Best for independent specialized tasks where coordination overhead is unnecessary.
Characteristics:
- Full customization of agent behavior
- Tool restrictions per agent type
- Simpler setup without team overhead
- Manual coordination when needed
Skills using Scenario B:
bugs- Bug scanning (independent)code-reviewer- Code review (single-purpose)
Combines TeamCreate coordination with ralph-* specialized subagents and quality validation hooks (TeammateIdle, TaskCompleted). This is the most powerful scenario.
Characteristics:
- Native task coordination from Agent Teams
- Custom agent specialization from ralph-* subagents
- Quality gates via hooks for VERIFIED_DONE guarantee
- Tool restrictions per agent type
Skills using Scenario C:
orchestrator- Multi-phase workflow coordinationparallel- Parallel execution with results aggregationloop- Iterative execution with quality validationsecurity- Security analysis with specialized patternsgates- Quality validation (meta-validation)quality-gates-parallel- Parallel quality checksadversarial- Multi-agent attack coordination
┌─────────────────────────────────────────────────────────────────────────────┐
│ MULTI-AGENT SCENARIO DECISION TREE │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Does the task require tight coordination between agents? │
│ │ │
│ ┌──────────┴──────────┐ │
│ ▼ ▼ │
│ YES NO ──► SCENARIO B (Custom Subagents) │
│ │ │
│ Does it need specialized agents (coder, tester, reviewer)? │
│ │ │
│ ┌────┴────┐ │
│ ▼ ▼ │
│ YES NO ──► SCENARIO A (Pure Agent Teams) │
│ │ │
│ ▼ │
│ SCENARIO C (Integrated) │
│ - TeamCreate for coordination │
│ - ralph-* for specialization │
│ - Hooks for quality gates │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
| Category | Agents |
|---|---|
| Agent Teams | ralph-coder, ralph-reviewer, ralph-tester, ralph-researcher |
| Orchestration | orchestrator, debugger, code-reviewer |
| Security | security-auditor, blockchain-security-auditor |
| Quality | test-architect, refactorer, quality-auditor |
| GLM-5 Teammates | glm5-coder, glm5-reviewer, glm5-tester, glm5-orchestrator |
| Specialized | frontend-reviewer, docs-writer, repository-learner |
Core commands:
/orchestrator- Full orchestration workflow/loop- Iterative execution with validation/task-batch- Autonomous batch task execution (v2.88)/create-task-batch- Interactive PRD/task list creator (v2.88)/gates- Quality gate validation/bugor/bugs- Systematic debugging/security- Security audit/parallel- Parallel code review
Model-agnostic (v2.88+):
# All commands use the configured default model automatically
/orchestrator "Task"
/loop "Fix errors"
/security src/
# For specific GLM-5 evaluations, use dedicated skills
/glm5 "Task" # GLM-5 specific evaluation
/glm5-parallel "Task" # GLM-5 parallel execution| Event | Hook | Purpose |
|---|---|---|
PreCompact |
pre-compact-handoff.sh | Save state BEFORE compaction |
SessionStart(compact) |
post-compact-restore.sh | Restore context AFTER compaction |
SessionEnd |
session-end-handoff.sh | Save state when session terminates |
Stop |
summarize, reports | Session reports and cleanup |
Note:
PostCompactdoes not exist in Claude Code. UseSessionStart(matcher="compact")instead.SessionEndandStopare separate events — useSessionEndfor state persistence,Stopfor reports.
| Event | Purpose | Exit 2 Behavior |
|---|---|---|
TeammateIdle |
Quality gate when teammate goes idle | Keep working + feedback |
TaskCompleted |
Quality gate before task completion | Prevent completion + feedback |
SubagentStart |
Load Ralph context into subagents | - |
SubagentStop |
Quality gates when subagent stops | - |
Hook events:
SessionStart- Context restoration at startupPreToolUse- Validation before tool executionPostToolUse- Quality checks after tool executionUserPromptSubmit- Command routing and context injectionPreCompact- State save before context compactionTeammateIdle- Quality gates for Agent TeamsTaskCompleted- Task completion validationSubagentStart/Stop- Subagent lifecycleStop- Session reports
Critical hooks (must be registered):
| Hook | Event | Purpose |
|---|---|---|
git-safety-guard.py |
PreToolUse (Bash) | Blocks rm -rf, git reset --hard |
repo-boundary-guard.sh |
PreToolUse (Bash) | Prevents work outside current repo |
learning-gate.sh |
PreToolUse (Task) | Triggers /curator when memory empty |
teammate-idle-quality-gate.sh |
TeammateIdle | Quality checks before idle |
task-completed-quality-gate.sh |
TaskCompleted | Validation before completion |
Model-Agnostic Architecture (v2.88): The system works with any model configured in Claude Code settings.
| Model | Provider | Configuration |
|---|---|---|
| GLM-5 | Z.AI | ANTHROPIC_DEFAULT_*_MODEL: "glm-5" |
| Claude Sonnet/Opus | Anthropic | ANTHROPIC_DEFAULT_*_MODEL: "claude-sonnet-4" |
| Minimax M2.5 | Minimax | ANTHROPIC_DEFAULT_*_MODEL: "minimax-m2.5" |
To change the default model, update ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "your-model",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "your-model",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "your-model",
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}All skills, agents, and subagents automatically use the configured model. No flags required.
Three-tier architecture:
| Tier | Type | Storage | Purpose |
|---|---|---|---|
| Semantic | Persistent | ~/.ralph/memory/semantic.json |
Facts, preferences |
| Episodic | Session | ~/.ralph/episodes/ |
Experiences (30-day TTL) |
| Procedural | Learned | ~/.ralph/procedural/rules.json |
Patterns, best practices |
Memory commands:
ralph memory-search "query"
ralph agent-memory init <agent>
ralph agent-memory write <agent> semantic "fact"
ralph healthAutomatic learning pipeline:
- Discovery - GitHub API search for quality repositories
- Scoring - Quality metrics + context relevance
- Ranking - Top N with max-per-org limits
- Learning - Pattern extraction from approved repos
Commands:
/curator full --type backend --lang typescript
/curator discovery --query "microservice" --max-results 200
/curator learn --repo nestjs/nest
/curator learn --allCurrent statistics:
- Total rules: 1003+
- Auto-learning: Enabled
- System status: Production
Validation stages:
- CORRECTNESS - Syntax errors (blocking)
- QUALITY - Type errors (blocking)
- SECURITY - semgrep + gitleaks (blocking)
- CONSISTENCY - Linting (advisory)
3-Fix Rule: Maximum 3 attempts per validation failure before escalation.
| Gate | Type | Detection |
|---|---|---|
| Gate 1 | Blocking | `console.log |
| Gate 2 | Blocking | `debugger |
| Gate 3 | Blocking | `TODO: |
| Gate 4 | Blocking | Placeholder code |
| Gate 5 | Advisory | Empty function bodies |
Primary settings: ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
},
"hooks": {
"TeammateIdle": [{"matcher": "*", "hooks": [...]}],
"TaskCompleted": [{"matcher": "*", "hooks": [...]}],
"SubagentStart": [{"matcher": "ralph-*", "hooks": [...]}],
"SubagentStop": [
{"matcher": "ralph-*", "hooks": [...]},
{"matcher": "glm5-*", "hooks": [...]}
]
}
}Memory configuration: ~/.ralph/config/memory-config.json
Learning configuration: ~/.ralph/curator/config.json
Test structure:
tests/
├── session-lifecycle/ # Session lifecycle tests
│ └── test_session_lifecycle_hooks.sh
├── agent-teams/ # Agent Teams tests
│ └── test_agent_teams_integration.sh
├── skills/ # Skill tests (v2.88)
│ ├── test-task-batch.sh
│ ├── test-create-task-batch.sh
│ └── test-batch-skills-integration.sh
├── quality-parallel/ # Quality gate tests
├── swarm-mode/ # Swarm mode tests
└── unit/ # Unit tests
Run tests:
# All integration tests
./tests/test_all_integration.sh
# Session lifecycle tests
./tests/session-lifecycle/test_session_lifecycle_hooks.sh
# Agent Teams tests
./tests/agent-teams/test_agent_teams_integration.sh
# Hook validation
./tests/unit/test-hooks-validation.shCurrent test status: 100% passing (102 hooks validated, 37 security tests, 950+ BATS tests)
# Orchestration
ralph orch "task" # Full orchestration
ralph loop "task" # Iterative execution
ralph gates # Quality gates
# Context
ralph context dev # Development mode
ralph context review # Review mode
ralph context debug # Debug mode
# Memory
ralph memory-search "query" # Search memory
ralph health # System health check
# Checkpoints
ralph checkpoint save "name" # Save state
ralph checkpoint restore "name" # Restore state
ralph checkpoint list # List checkpoints
# Learning
ralph curator full --type backend --lang typescript
ralph curator learn --repo owner/repo
# Events
ralph events status # Event bus status
ralph trace show 30 # Recent events| Topic | Location |
|---|---|
| Architecture | docs/architecture/ |
| Agent Teams | docs/agent-teams/ |
| Batch Execution | docs/batch-execution/BATCH_SKILLS_v2.88.0.md |
| Swarm Mode | docs/swarm-mode/ |
| Learning System | docs/guides/LEARNING_SYSTEM_INTEGRATION_GUIDE.md |
| Hooks Reference | docs/hooks/ |
| Security | docs/security/ |
- Fork the repository
- Create a feature branch
- Make changes following existing patterns
- Run tests:
./tests/run-all.sh - Submit pull request
Code standards:
- All code in English
- Documentation in English
- Conventional commits format
- Tests required for new features
MIT License - see LICENSE file for details.
- Claude Code Agent Teams Docs
- Claude Code Subagents Docs
- Claude Code Hooks Guide
- cc-mirror - Documentation patterns