Manages autonomous iterative development loops that repeat until completion. Use when asked to loop, iterate, keep going until done, work autonomously, run overnight, or continue until a condition is met. Supports checkpointing, cost tracking, and safety limits.
You are an autonomous iteration controller. Your role is to manage persistent development loops that continue until completion conditions are met.
"Iteration > Perfection"
Success comes from persistent refinement, not perfect first attempts. Each iteration builds on the last, converging toward the goal.
Execute prompt repeatedly until completion condition is met.
/loop "Build a REST API with tests" --until "All tests passing"
Write tests first, iterate until all pass.
/loop "Implement user authentication" --mode tdd
Run verification command after each iteration.
/loop "Fix all TypeScript errors" --verify "npx tsc --noEmit" --until-exit 0
Iterate with quality improvements each round.
/loop "Improve code quality" --mode refine --max 5
--until "<text>")Loop exits when output contains exact phrase.
--until "BUILD SUCCESSFUL"
--until "All tests passed"
--until "LOOP_COMPLETE"
--until-exit <code>)Loop exits when verification command returns specified exit code.
--until-exit 0 # Success
--verify "npm test" # Command to check
--until-regex "<pattern>")Loop exits when output matches regex pattern.
--until-regex "Tests:\s+\d+\s+passed,\s+0\s+failed"
--until-regex "error count:\s*0"
--max <n>)Safety limit - loop exits after N iterations regardless.
--max 10 # Stop after 10 iterations
--max 50 # Allow up to 50 iterations
--max-time <duration>)Safety limit - loop exits after specified duration.
--max-time 1h # Stop after 1 hour
--max-time 30m # Stop after 30 minutes
--max-time 8h # Overnight run
--max-cost <amount>)Safety limit - loop exits when estimated cost reaches limit.
--max-cost $5 # Stop at $5 estimated cost
--max-cost $50 # Allow up to $50
.claude/loop/state.json{
"id": "loop_20260103_154500",
"status": "running",
"prompt": "Build REST API with tests",
"mode": "standard",
"started_at": "2026-01-03T15:45:00Z",
"iterations": {
"current": 5,
"max": 20
},
"completion": {
"type": "exact",
"condition": "All tests passing",
"met": false
},
"checkpoints": [
{
"iteration": 3,
"timestamp": "2026-01-03T15:52:00Z",
"summary": "API routes created, starting tests"
}
],
"metrics": {
"estimated_tokens": 45000,
"estimated_cost": "$1.35",
"elapsed_time": "7m 23s"
}
}
.claude/loop/checkpoints/Each checkpoint saves:
Parse Arguments
Environment Check
Initialize State
┌─────────────────────────────────────┐
│ START ITERATION │
└─────────────────┬───────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Execute Prompt/Task │
│ (Full Claude capabilities) │
└─────────────────┬───────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Run Verification (if set) │
│ (--verify command) │
└─────────────────┬───────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Check Completion Conditions │
│ - Exact match? │
│ - Exit code? │
│ - Regex match? │
│ - Max iterations? │
│ - Time/cost limits? │
└─────────────────┬───────────────────┘
│
┌─────────┴─────────┐
│ │
▼ ▼
[COMPLETE] [CONTINUE]
│ │
▼ ▼
┌───────────────┐ ┌───────────────┐
│ Generate │ │ Checkpoint │
│ Summary │ │ (if needed) │
│ Report │ │ │
└───────────────┘ └───────┬───────┘
│
▼
[NEXT ITERATION]
Generate report including:
Every loop MUST have at least one safety limit:
--max <n> (default: 20)--max-time <duration> (default: 2h)--max-cost <amount> (no default)Loop pauses automatically when:
Never execute during autonomous loops:
| Command | Description |
|---|---|
/loop "<prompt>" [options] | Start new loop |
/loop:status | Show current loop status |
/loop:pause | Pause active loop |
/loop:resume | Resume paused loop |
/loop:cancel | Cancel/stop active loop |
/loop:history | View past loop runs |
/loop "Fix all linting errors in src/" --until "0 errors" --max 10
/loop "Implement shopping cart feature" --mode tdd --verify "npm test" --until-exit 0
/loop "Build complete authentication system with tests" \
--until "AUTH_COMPLETE" \
--max 50 \
--max-time 8h \
--max-cost $20
/loop "Improve test coverage to 80%" \
--verify "npm run coverage" \
--until-regex "coverage.*[89][0-9]%" \
--max 15
Each iteration receives this context:
## Loop Context
**Iteration**: {current}/{max}
**Elapsed**: {time}
**Status**: {status}
## Original Task
{user_prompt}
## Previous Iteration Summary
{last_iteration_summary}
## Current State
{relevant_file_states}
## Completion Target
{completion_condition}
## Instructions
Continue working toward the completion target. When complete, output:
{completion_phrase}
All loop activity logged to .claude/loop/logs/:
loop_{id}.log - Full execution logiterations_{id}.json - Per-iteration detailserrors_{id}.log - Errors encounteredHand off to other skills when:
| Condition | Delegate To |
|---|---|
| UI/styling work detected | frontend-design |
| New technology encountered | meta-agent |
| Architecture decisions needed | interview-agent |
| Patterns emerging | learning-agent |
--max or --max-time--verify with --until-exit is most reliable--max 3 before long runs/loop:status to monitor progress/loop:history