Skip to main content

/sw:auto - Autonomous Execution

Start autonomous execution session using Claude Code's Stop Hook.

Auto mode enables continuous autonomous execution until all tasks are complete. It uses a stop hook feedback loop to keep Claude working until completion.

Usage

/sw:auto [INCREMENT_IDS...] [OPTIONS]

Arguments

  • INCREMENT_IDS: One or more increment IDs to process (e.g., 0001, 0001-feature)
    • If omitted, uses current in-progress increment

Options

OptionDescriptionDefault
--max-iterations NMaximum iterations before stopping100
--max-hours NMaximum hours to runNone
--simpleSimple mode (minimal context)false
--dry-runPreview without startingfalse
--all-backlogProcess all backlog itemsfalse
--skip-gates G1,G2Pre-approve specific gatesNone

How It Works

1. User runs /sw:auto 0001


2. setup-auto.sh creates session state
└─ .specweave/state/auto-session.json


3. Claude starts working on tasks
└─ /sw:do executes tasks


4. Claude tries to exit (naturally)


5. Stop Hook intercepts (stop-auto.sh)
├─ Checks: All tasks complete?
├─ Checks: Max iterations reached?
├─ Checks: Completion promise?
└─ Checks: Human gate pending?

┌──────┴──────┐
▼ ▼
INCOMPLETE COMPLETE
│ │
▼ ▼
Block exit Approve exit
Re-feed Session ends
prompt

Examples

Basic Usage

# Start auto on current increment
/sw:auto

# Start on specific increment
/sw:auto 0001-user-auth

# Multiple increments
/sw:auto 0001 0002 0003

With Options

# Limit iterations
/sw:auto --max-iterations 50

# Time limit
/sw:auto --max-hours 8

# Simple mode (minimal context)
/sw:auto --simple

# Preview only
/sw:auto --dry-run

# All backlog items
/sw:auto --all-backlog

Pre-approve Gates

# Skip deploy gate (pre-approved)
/sw:auto --skip-gates deploy

# Multiple gates
/sw:auto --skip-gates "deploy,migrate"

Session Management

Check Status

/sw:auto-status

See: /sw:auto-status Documentation

Cancel Session

/sw:cancel-auto

See: /sw:cancel-auto Documentation

Resume After Crash

Just run /sw:do - it will detect incomplete tasks and continue.

Or use Claude Code's built-in:

/resume           # Pick session to resume
claude --continue # Continue last session

Configuration

In .specweave/config.json:

{
"auto": {
"enabled": true,
"maxIterations": 100,
"maxHours": 24,
"testCommand": "npm test",
"coverageThreshold": 80,
"enforceTestFirst": false,
"humanGated": {
"patterns": ["deploy", "migrate", "publish"],
"timeout": 1800
}
}
}

Completion Signals

The session ends when ANY of these occur:

SignalDescription
All tasks completetasks.md has all [x] checkboxes
Completion promiseOutput contains <!-- auto-complete:DONE --> (hidden HTML comment)
Max iterationsReached configured limit (default: 100)
Max hoursTime limit exceeded
User cancellationUser runs /sw:cancel-auto
Human gate timeoutGate pending too long
Low confidence scoreSelf-assessment score < 0.50

Simple Mode (--simple)

Pure stop hook loop behavior:

  • Minimal context in re-feed prompt
  • No session state UI
  • No queue management
  • Just: loop + tasks.md completion + max iterations
/sw:auto --simple

Safety Features

FeatureDescription
Human GatesSensitive operations (deploy, publish, force-push) require approval
Circuit BreakersExternal service failures (GitHub/JIRA/ADO) handled gracefully
Max IterationsPrevents runaway loops (default: 100)
Max HoursOptional time boxing
stop_hook_activePrevents infinite continuation loops
Self-AssessmentScores below 0.50 pause for human review
Test FailuresMultiple failures (>3) pause for review
Credential ErrorsRepeated deployment errors pause for credential check

Self-Assessment Scoring

Auto mode uses self-assessment scoring to guide continuation decisions.

Confidence Scoring

After each task, Claude self-assesses execution quality:

{
"iteration": 5,
"task": "T-003",
"confidence": {
"execution_quality": 0.92,
"test_coverage": 0.85,
"spec_alignment": 0.95,
"credential_success": 1.0,
"overall": 0.93
}
}

Score Thresholds

Overall ScoreAction
≥ 0.90✅ Continue confidently
0.70-0.89⚠️ Continue with caution, log concerns
0.50-0.69🟡 Pause for self-review before continuing
< 0.50🔴 Stop and request human review

Test Execution Integration

Auto mode runs tests after completing testable tasks in a self-healing loop:

┌─────────────────────────────────────────────────────────────┐
│ IMPLEMENT → TEST → FAIL? → FIX → TEST → PASS → NEXT TASK │
│ ↑________________↓ │
│ (max 3 iterations) │
└─────────────────────────────────────────────────────────────┘

Mandatory Test Reporting after every task:

## 🧪 Test Status Report (after T-003)

| Type | Status | Pass/Total | Coverage |
|------|--------|------------|----------|
| Unit || 42/42 | 87% |
| Integration || 12/12 | - |
| E2E | ⚠️ | 8/10 | - |

Auto-Execute Rules

In auto mode, all agents MUST follow auto-execute rules:

❌ FORBIDDEN: "Next Steps: Run wrangler deploy"
❌ FORBIDDEN: "Execute the schema in Supabase SQL Editor"

✅ REQUIRED: Execute commands DIRECTLY using available credentials

Credential Lookup Order

  1. .env file - Primary credential storage
  2. Environment variables - Already loaded in session
  3. CLI tool auth - wrangler whoami, gh auth status, etc.
  4. Config files - wrangler.toml, .specweave/config.json

If credentials found → AUTO-EXECUTE If credentials missing → ASK (don't show manual steps)


Human-Gated Operations

These operations require manual approval even in auto mode:

  • npm publish, git push --force, rm -rf /
  • Any production deployment
  • API key or credential changes
  • Database migrations (drop, delete from, migrate)

Session State

Session state is stored in .specweave/state/auto-session.json:

{
"sessionId": "auto-2025-12-29-abc123",
"status": "running",
"startTime": "2025-12-29T10:00:00Z",
"iteration": 47,
"maxIterations": 100,
"incrementQueue": ["0001-user-auth", "0002-payment"],
"currentIncrement": "0001-user-auth",
"completedIncrements": [],
"simple": false
}

For Non-Claude AI Systems

If using SpecWeave with other AI systems (GPT, Gemini, etc.), implement this loop pattern:

# Bash loop for autonomous execution
while true; do
# Check if all tasks complete
TOTAL=$(grep -c "^### T-" .specweave/increments/*/tasks.md 2>/dev/null || echo "0")
DONE=$(grep -c '\[x\].*completed' .specweave/increments/*/tasks.md 2>/dev/null || echo "0")

if [ "$TOTAL" -gt 0 ] && [ "$DONE" -ge "$TOTAL" ]; then
echo "All tasks complete!"
break
fi

# Feed prompt to your AI
cat PROMPT.md | your-ai-cli

# Safety: max iterations
ITER=$((ITER + 1))
if [ "$ITER" -ge 100 ]; then
echo "Max iterations reached"
break
fi
done

CommandPurpose
/sw:auto-statusCheck session status
/sw:cancel-autoCancel running session
/sw:doExecute tasks (also works standalone)
/sw:progressShow increment progress

See Also