Autonomous Claude Code operation using Opus 4.5 for intelligent continuation decisions. Use when running long tasks, multi-step implementations, overnight development, or any workflow requiring continuous autonomous operation without human intervention.
52
58%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./skills/autonomous-opus-loop/SKILL.mdTransform Claude Code from interactive to fully autonomous using an external Opus 4.5 instance to analyze progress and decide continuation.
This skill enables Claude Code to run autonomously by using another Claude instance (Opus 4.5) to:
Key Innovation: The Stop hook's reason field becomes Claude's next instruction, creating a fully autonomous loop where two Claude instances collaborate.
┌─────────────────────────────────────┐
│ Claude Code (Executor) │
│ - Executes tasks │
│ - Writes code, runs tests │
│ - Triggers Stop hook when done │
└─────────────────┬───────────────────┘
│
▼ (Stop hook fires)
┌─────────────────────────────┐
│ autonomous-loop.sh │
│ - Reads transcript │
│ - Checks safety limits │
│ - Calls Opus analyzer │
└──────────┬──────────────────┘
│
▼
┌───────────────────────────────────┐
│ Claude Opus 4.5 (Analyzer) │
│ - Reviews all work done │
│ - Checks against objectives │
│ - Decides: CONTINUE or COMPLETE │
│ - If CONTINUE: specific next task│
└──────────┬────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Loop Controller │
│ - Tracks iterations │
│ - Monitors cost │
│ - Prevents doom loops │
│ - Returns decision to CC │
└──────────┬──────────────────┘
│
▼
Claude Code receives "reason" as next instruction
(loop repeats until COMPLETE)# Run the installation script
.claude/skills/autonomous-opus-loop/scripts/install.shOr manually add to .claude/settings.json:
{
"hooks": {
"Stop": [{
"matcher": {},
"hooks": [{
"type": "command",
"command": ".claude/skills/autonomous-opus-loop/scripts/autonomous-loop.sh"
}],
"timeout": 120
}]
}
}Create .claude/autonomous-config.json:
{
"enabled": true,
"objective": "Implement user authentication with JWT tokens",
"success_criteria": [
"All tests pass",
"Code coverage > 80%",
"No security vulnerabilities"
],
"max_iterations": 30,
"max_cost_usd": 15.00,
"analyzer_model": "claude-sonnet-4-20250514",
"verbose": true
}# Start with initial task
claude -p "Begin implementing user authentication per the objective in .claude/autonomous-config.json"Claude Code will now run autonomously until:
| Setting | Type | Description |
|---|---|---|
enabled | boolean | Enable/disable autonomous mode |
objective | string | High-level goal to achieve |
success_criteria | string[] | Conditions that define "done" |
| Setting | Type | Default | Description |
|---|---|---|---|
max_iterations | number | 50 | Maximum loop iterations |
max_cost_usd | number | 20.00 | Maximum estimated cost |
max_consecutive_failures | number | 3 | Failures before escalation |
max_runtime_minutes | number | 480 | 8-hour maximum runtime |
| Setting | Type | Default | Description |
|---|---|---|---|
analyzer_model | string | claude-sonnet-4-20250514 | Model for analysis |
analyzer_max_tokens | number | 1024 | Max tokens for analysis |
include_full_transcript | boolean | false | Send full vs. recent context |
recent_messages_count | number | 10 | Messages to include if not full |
| Setting | Type | Default | Description |
|---|---|---|---|
verbose | boolean | false | Log detailed progress |
notify_on_complete | boolean | true | System notification on completion |
save_session_log | boolean | true | Save iteration history |
escalation_mode | string | "pause" | Action on escalation: pause/notify/abort |
# Enable with default config
.claude/skills/autonomous-opus-loop/scripts/enable.sh
# Enable with specific objective
.claude/skills/autonomous-opus-loop/scripts/enable.sh \
--objective "Refactor the payment module" \
--max-iterations 20.claude/skills/autonomous-opus-loop/scripts/disable.sh.claude/skills/autonomous-opus-loop/scripts/status.shOutput:
Autonomous Loop Status
======================
Enabled: true
Objective: Implement user authentication with JWT tokens
Iterations: 12/30
Estimated Cost: $4.23/$15.00
Runtime: 45m/480m
Last Action: Implemented login endpoint
Next Action: Add password reset functionality
Status: RUNNING.claude/skills/autonomous-opus-loop/scripts/view-log.sh.claude/skills/autonomous-opus-loop/scripts/emergency-stop.shThe hook checks stop_hook_active flag to prevent infinite recursion:
if [ "$STOP_ACTIVE" == "true" ]; then
# Already in a stop hook - allow termination
exit 0
fiHard cap on iterations prevents runaway execution:
if [ "$ITERATION" -ge "$MAX_ITERATIONS" ]; then
log "Max iterations ($MAX_ITERATIONS) reached"
exit 0 # Allow stop
fiEstimated cost monitoring based on token usage:
if (( $(echo "$TOTAL_COST > $MAX_COST" | bc -l) )); then
log "Cost limit ($MAX_COST USD) exceeded"
exit 0 # Allow stop
fiConsecutive failure tracking triggers escalation:
if [ "$CONSECUTIVE_FAILURES" -ge "$MAX_FAILURES" ]; then
escalate "Doom loop detected: $CONSECUTIVE_FAILURES consecutive failures"
fiSemantic analysis detects repeated work patterns:
# Analyzer prompt includes:
"Detect if the same work is being repeated. If circular pattern detected, respond with ESCALATE."You are an autonomous development coordinator analyzing Claude Code progress.
OBJECTIVE: {objective}
SUCCESS CRITERIA:
{success_criteria}
Your task:
1. Analyze the recent work done
2. Check progress against success criteria
3. Decide: CONTINUE, COMPLETE, or ESCALATE
Response format:
- If more work needed: "CONTINUE: [specific next task with clear instructions]"
- If all criteria met: "COMPLETE: [summary of what was achieved]"
- If stuck/looping: "ESCALATE: [description of the problem]"
Be specific in CONTINUE responses. Give actionable next steps.
Do not repeat tasks that have already been completed.
Track what's done vs. what remains.Create custom prompts in .claude/autonomous-prompts/:
.claude/autonomous-prompts/
├── refactoring.txt # For refactoring tasks
├── feature-build.txt # For new features
├── bug-fix.txt # For bug fixing
└── testing.txt # For test writingReference in config:
{
"analyzer_prompt_file": ".claude/autonomous-prompts/feature-build.txt"
}The autonomous loop works alongside other hooks:
{
"hooks": {
"Stop": [{
"hooks": [{
"type": "command",
"command": ".claude/skills/autonomous-opus-loop/scripts/autonomous-loop.sh"
}]
}],
"PostToolUse": [{
"tools": ["Write", "Edit"],
"hooks": [{
"type": "command",
"command": "npx prettier --write \"$FILE\""
}]
}]
}
}Enable persistent learning across autonomous sessions:
{
"integrations": {
"agent_memory": true,
"save_episodes": true,
"learn_patterns": true
}
}Combine for enhanced progress tracking:
{
"integrations": {
"momentum_keeper": true,
"stall_detection": true,
"energy_management": false
}
}Send metrics to your observability stack:
{
"observability": {
"enabled": true,
"endpoint": "http://localhost:4317",
"metrics": ["iterations", "cost", "duration", "success_rate"]
}
}{
"enabled": true,
"objective": "Build complete user dashboard with charts, filters, and export",
"success_criteria": [
"Dashboard component renders without errors",
"All 5 chart types implemented",
"Filter functionality works",
"Export to CSV and PDF works",
"Unit tests pass with >80% coverage",
"E2E tests pass"
],
"max_iterations": 100,
"max_cost_usd": 50.00,
"max_runtime_minutes": 480,
"analyzer_model": "claude-sonnet-4-20250514",
"notify_on_complete": true,
"escalation_mode": "notify"
}{
"enabled": true,
"objective": "Refactor utils/ to use TypeScript strict mode",
"success_criteria": [
"All files converted to .ts",
"No 'any' types remain",
"TypeScript compiles without errors",
"All existing tests pass"
],
"max_iterations": 20,
"max_cost_usd": 10.00,
"analyzer_model": "claude-sonnet-4-20250514"
}{
"enabled": true,
"objective": "Find and fix the memory leak in the WebSocket handler",
"success_criteria": [
"Memory leak identified",
"Root cause documented",
"Fix implemented",
"Memory usage stable over 1000 connections",
"No regression in existing tests"
],
"max_iterations": 30,
"max_cost_usd": 15.00,
"analyzer_prompt_file": ".claude/autonomous-prompts/bug-fix.txt"
}Check hook is installed:
cat .claude/settings.json | jq '.hooks.Stop'Verify script is executable:
chmod +x .claude/skills/autonomous-opus-loop/scripts/*.shCheck for syntax errors:
bash -n .claude/skills/autonomous-opus-loop/scripts/autonomous-loop.shenabled is true in configecho $ANTHROPIC_API_KEY.claude/autonomous-log.jsonlCtrl+C or run emergency-stop.shstop_hook_active handling in scriptecho $ANTHROPIC_API_KEY | head -c 10.claude/autonomous-log.jsonlverbose: true for detailed outputAll autonomous sessions are logged to .claude/autonomous-log.jsonl:
{"timestamp": "2024-01-15T10:30:00Z", "iteration": 1, "action": "START", "objective": "..."}
{"timestamp": "2024-01-15T10:31:00Z", "iteration": 1, "action": "CONTINUE", "task": "..."}
{"timestamp": "2024-01-15T10:35:00Z", "iteration": 2, "action": "CONTINUE", "task": "..."}
{"timestamp": "2024-01-15T11:00:00Z", "iteration": 15, "action": "COMPLETE", "summary": "..."}View formatted:
.claude/skills/autonomous-opus-loop/scripts/view-log.sh --format prettyBad: "Make the code better" Good: "Refactor auth module to use dependency injection, add unit tests for all public methods"
Bad: "Code should be clean" Good: "ESLint passes with no warnings, all functions have JSDoc comments"
verbose: true initiallyclaude-sonnet-4-20250514: Good balance of speed/quality (recommended)claude-opus-4-5-20250929: Better analysis, higher costclaude-3-5-haiku-20241022: Fast/cheap for simple tasksApproximate costs per iteration (analyzer call):
| Model | Input (10k tokens) | Output (1k tokens) | Total |
|---|---|---|---|
| Sonnet 4 | $0.03 | $0.015 | ~$0.045 |
| Opus 4.5 | $0.15 | $0.075 | ~$0.225 |
| Haiku 3.5 | $0.008 | $0.004 | ~$0.012 |
Example: 30 iterations with Sonnet = ~$1.35 for analyzer alone (Plus Claude Code usage costs)
references/hook-mechanics.md - Deep dive into Stop hook behaviorreferences/analyzer-prompts.md - Prompt engineering for analyzersreferences/safety-patterns.md - Comprehensive safety documentationreferences/integration-guide.md - Integrating with other skillsscripts/autonomous-loop.sh - Main Stop hook handlerscripts/opus-analyzer.py - Python analyzer (alternative)scripts/install.sh - Install hooks to settingsscripts/enable.sh - Enable autonomous modescripts/disable.sh - Disable autonomous modescripts/status.sh - Check current statusscripts/view-log.sh - View session logsscripts/emergency-stop.sh - Emergency termination93ed392
Also appears in
since Sep 12, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.