.claude/skills/iterate/SKILL.md
Ralph Loop pattern with swarm mode: iterative execution until VERIFIED_DONE with multi-agent coordination. Use when: (1) iterative refinement needed, (2) quality gates must pass, (3) automated validation required. Triggers: /iterate, 'iterate until done', 'keep trying', 'fix until passing', 'loop until done'.
npx skillsauth add alfredolopez80/multi-agent-ralph-loop iterateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Execute tasks iteratively with automatic quality validation until VERIFIED_DONE signal.
~/.claude/settings.json or CLI/env varsANTHROPIC_DEFAULT_*_MODEL env varsdocs/architecture/The Ralph Loop is a continuous execution pattern that iterates through EXECUTE -> VALIDATE -> QUALITY CHECK cycles until the task passes all quality gates or reaches the iteration limit.
+------------------------------------------------------------------+
| RALPH LOOP PATTERN |
+------------------------------------------------------------------+
| |
| +----------+ +--------------+ +-----------------+ |
| | EXECUTE |--->| VALIDATE |--->| Quality Passed? | |
| | Task | | (hooks/gates)| +--------+--------+ |
| +----------+ +--------------+ | |
| NO <--+--> YES |
| | | |
| +----------------+ | |
| v v |
| +------------+ +---------------+ |
| | ITERATE | | VERIFIED_DONE | |
| | (max 15/30)| | (output) | |
| +-----+------+ +---------------+ |
| | |
| +----------> Back to EXECUTE |
| |
+------------------------------------------------------------------+
Use /iterate when:
DO NOT use for:
| Model | Max Iterations | Cost vs Claude | Quality | Use Case | |-------|----------------|----------------|---------|----------| | Claude (Sonnet/Opus) | 15 | 100% (baseline) | 85-90% SWE-bench | Complex reasoning, high accuracy | | GLM-5 | 30 | ~10% | 80%+ SWE-bench | Standard tasks (2x multiplier) | | MiniMax M2.1 | 30 | ~8% | 74% SWE-bench | Standard tasks (2x multiplier) |
ralph iterate "implement OAuth2 authentication"
Uses Claude Sonnet with 15 iteration limit:
ralph iterate "implement OAuth2 authentication" --with-glm5
Uses GLM-5 with 30 iteration limit:
ralph iterate --mmc "implement OAuth2 authentication"
Uses MiniMax M2.1 with 30 iteration limit:
# Claude mode (15 iterations)
ralph iterate "implement user authentication with JWT"
# GLM-5 mode (30 iterations)
ralph iterate "refactor database queries" --with-glm5
# MiniMax mode (30 iterations)
ralph iterate --mmc "refactor database queries to use TypeORM"
# Complex task with specific requirements
ralph iterate "add rate limiting to API endpoints with Redis"
IMPORTANT: /iterate uses swarm mode by default with full multi-agent coordination.
Task:
subagent_type: "general-purpose"
model: "sonnet"
run_in_background: true
max_iterations: 15
description: "Loop execution with swarm mode"
team_name: "iterate-execution-team"
name: "iterate-lead"
mode: "delegate"
prompt: |
Execute the following task iteratively until VERIFIED_DONE:
Task: $ARGUMENTS
Ralph Loop pattern:
1. EXECUTE - Implement the task
2. VALIDATE - Run quality gates (tsc, eslint, tests)
3. CHECK - Did all gates pass?
- YES -> VERIFIED_DONE
- NO -> ITERATE (max 15)
Output: Final implementation + quality report
Optimal Scenario: Integrated (Agent Teams + Custom Subagents)
This skill uses the INTEGRATED approach combining Agent Teams coordination with Custom Subagent specialization.
TeamCreate(team_name, description)
→ TaskCreate(iteration_n, "Implement iteration {n}")
→ Task(subagent_type="ralph-coder", team_name) for implementation
→ Task(subagent_type="ralph-tester", team_name) for validation
→ TaskUpdate(status="completed") when iteration passes gates
→ Hooks validate quality before marking complete
→ VERIFIED_DONE when all iterations pass
When /iterate is invoked, it automatically creates a dedicated team for the iteration:
# Automatic team creation
TeamCreate(
team_name: "iterate-{task-hash}",
description: "Iterative execution: {task}"
)
# Spawn implementation teammate
Task(
subagent_type: "ralph-coder",
team_name: "iterate-{task-hash}"
)
# Spawn validation teammate
Task(
subagent_type: "ralph-tester",
team_name: "iterate-{task-hash}"
)
Each iteration follows this pattern:
Phase 1: Implementation
ralph-coder teammatePhase 2: Validation
ralph-tester teammatePhase 3: Hook Verification
TeammateIdle hook triggers quality checkstask-completed-quality-gate.sh validates before completionPhase 4: Decision
VERIFIED_DONE| Hook | Trigger | Purpose |
|------|---------|---------|
| teammate-idle-quality-gate.sh | TeammateIdle | Quality checks before idle |
| task-completed-quality-gate.sh | TaskCompleted | Final validation before completion |
| ralph-subagent-start.sh | SubagentStart | Load Ralph context into teammates |
| glm5-subagent-stop.sh | SubagentStop | Quality gates when teammate stops |
When /iterate is invoked, it automatically spawns:
| Role | Purpose | Count | |------|---------|-------| | Leader | Loop coordinator, iteration management | 1 | | ralph-coder | Implementation specialist | 1 | | ralph-tester | Quality validation specialist | 1 |
Total: 3 agents working in parallel (1 leader + 2 teammates)
# Leader creates iteration task
TaskCreate(
subject: "Implement iteration {n}",
description: "{task requirements}",
activeForm: "Implementing iteration {n}"
)
# Assign to coder
TaskUpdate(
taskId: "{id}",
owner: "ralph-coder",
status: "in_progress"
)
# Coder completes work
TaskUpdate(
taskId: "{id}",
status: "completed"
)
# Leader validates, then marks VERIFIED_DONE or iterates
The Agent Teams system ensures VERIFIED_DONE through:
This creates a quality feedback loop that prevents completion until all standards are met.
# Logs saved to ~/.ralph/logs/
ls ~/.ralph/logs/iterate-*.log
# View last iterate execution
tail -f ~/.ralph/logs/iterate-latest.log
iteration=0
max_iterations=15 # or 30 for GLM-5/MiniMax
while [[ $iteration -lt $max_iterations ]]; do
# Step 1: EXECUTE
implement_task
# Step 2: VALIDATE
run_quality_gates # tsc, eslint, tests, semgrep
# Step 3: CHECK
if all_gates_passed; then
echo "VERIFIED_DONE"
exit 0
fi
# Step 4: ITERATE
((iteration++))
analyze_failures
apply_fixes
done
# Max iterations reached without VERIFIED_DONE
exit 1
Each iteration runs quality gates:
tsc --noEmiteslint .npm test or pytestsemgrep --config=autoThe loop integrates with the Stop hook:
# Initialize state
.claude/scripts/ralph-state.sh init "$SESSION_ID" iterate "$TASK"
# On VERIFIED_DONE
.claude/scripts/ralph-state.sh complete "$SESSION_ID" iterate
# On failure
.claude/scripts/ralph-state.sh fail "$SESSION_ID" iterate "$ERROR"
VERIFIED_DONE requires ALL:
When /iterate detects a metric-based optimization task, it can delegate to /autoresearch for continuous autonomous experimentation instead of running its own quality-gate loop.
A task is a candidate for autoresearch delegation when it contains:
npm run build, pytest --benchmark, time ./run.sh)| User Request | /iterate Behavior | Delegation |
|---|---|---|
| "iterate on reducing bundle size" | Detects metric: bundle size | /autoresearch src/ "npm run build" |
| "iterate on improving test coverage" | Detects metric: coverage % | /autoresearch src/ "npm run test:coverage" |
| "iterate until tests pass" | No metric, binary pass/fail | Stays in /iterate (quality-gate loop) |
| "fix lint errors" | No metric, binary pass/fail | Stays in /iterate (quality-gate loop) |
| "optimize inference latency below 50ms" | Detects metric: latency | /autoresearch src/model/ "python bench.py" |
User: /iterate "reduce bundle size by 30%"
/iterate detects:
- metric: "bundle size"
- eval: inferred from package.json -> "npm run build"
- target: src/
/iterate delegates:
/autoresearch src/ "npm run build" --checkpoint=5
The delegation happens at the start of the loop, before the first iteration. If the task does not match the metric-detection heuristic, /iterate proceeds with its standard EXECUTE -> VALIDATE -> QUALITY CHECK cycle.
| Aspect | /iterate | /autoresearch | |--------|----------|---------------| | Purpose | Fix until tests/gates pass | Optimize a metric continuously | | Loop type | Quality-gate loop | Experiment loop | | Termination | All gates pass (VERIFIED_DONE) | Budget exhausted or metric target reached | | Rollback | Fix forward | Git reset on regression | | Decision | Binary pass/fail | Delta comparison (improved/equal/worse) | | Best for | "Make it correct" | "Make it better" |
/orchestrator pipeline (orchestrator manages flow)/iterate behavior with --no-delegate flag/orchestrator - Full orchestration workflow/gates - Quality validation gates/autoresearch - Autonomous metric-driven experimentation/adversarial - Spec refinement/parallel - Parallel subagent execution/retrospective - Post-task analysisEsta skill genera reportes automáticos completos para trazabilidad:
Cuando esta skill completa, se genera automáticamente:
docs/actions/iterate/{timestamp}.md.claude/metadata/actions/iterate/{timestamp}.jsonCada reporte incluye:
# Listar todos los reportes de esta skill
ls -lt docs/actions/iterate/
# Ver el reporte más reciente
cat $(ls -t docs/actions/iterate/*.md | head -1)
# Buscar reportes fallidos
grep -l "Status: FAILED" docs/actions/iterate/*.md
source .claude/lib/action-report-lib.sh
start_action_report "iterate" "Task description"
# ... ejecución ...
complete_action_report "success" "Summary" "Recommendations"
Action Reports System - Documentación completa
action-report-lib.sh - Librería helper
action-report-generator.sh - Generador
Unified Architecture v2.88
Skills/Commands Unification
Claude Code Skills Documentation
See master table: docs/reference/anti-rationalization.md
| Excuse | Rebuttal | |---|---| | "VERIFIED_DONE — all tests pass" | Did you run ALL tests or just the new ones? | | "The error is unrelated to my change" | Prove it. Run the full test suite. | | "3 iterations is enough" | Iteration count doesn't determine quality. Exit criteria do. | | "The fix works locally" | Local works is not verified. Run exit criteria. | | "I'm stuck, marking as done with notes" | Stuck means escalate, not declare victory. | | "The loop has been running too long" | Time is not a quality metric. Results are. | | "Minor regressions are acceptable" | No regressions. Fix them or document why they're acceptable. |
development
Living knowledge base management. Actions: search (query vault), save (store learning), index (update indices), compile (raw->wiki->rules graduation), init (create vault structure). Follows Karpathy pipeline: ingest->compile->query. Use when: (1) searching accumulated knowledge, (2) saving learnings, (3) compiling raw notes into wiki, (4) initializing a new vault. Triggers: /vault, 'vault search', 'knowledge base', 'save learning'.
testing
Produce a verifiable technical specification before coding. 6 mandatory sections: Interfaces, Behaviors, Invariants (from Aristotle Phase 2), File Plan, Test Plan, Exit Criteria (executable bash commands + expected results). Use when: (1) before implementing features with complexity > 4, (2) as Step 1.5 in orchestrator workflow, (3) when requirements need formalization. Triggers: /spec, 'create spec', 'write specification', 'technical spec'.
testing
Pre-launch shipping checklist orchestrating /gates, /security, /browser-test, /perf. Ensures nothing ships without passing all quality checks. Use when: (1) before deploying, (2) before merging to main, (3) before release. Triggers: /ship, 'ship it', 'ready to deploy', 'pre-launch check'.
development
Performance optimization skill. Core Web Vitals via Lighthouse, bundle size analysis, metrics tracking over time. Use when: (1) optimizing frontend performance, (2) analyzing bundle size, (3) tracking metrics regression. Triggers: /perf, 'performance audit', 'core web vitals', 'bundle size'.