Autonomous Loop Framework
Enable Claude Code to work autonomously in a continuous iteration loop with built-in safety guardrails, progress tracking, and automatic stopping conditions. Ideal for large refactoring tasks, test suite creation, and batch file processing.
Description
The Autonomous Loop Framework allows Claude Code to work iteratively on large tasks without requiring user input at every step. It implements a think-act-verify cycle with safety mechanisms to prevent runaway execution, accidental deletions, and scope creep.
Instructions
When activated, Claude Code enters a loop of: Assess -> Act -> Verify -> Report. The loop continues until the task is complete, a safety limit is reached, or the user interrupts.
Workflow
[INIT] Define task scope, success criteria, safety limits
|
v
[ASSESS] What's the current state? What's the next step?
|
v
[ACT] Make one focused change
|
v
[VERIFY] Did it work? Run tests/checks
| |
| (pass) | (fail)
v v
[PROGRESS] [DIAGNOSE & RETRY]
|
v
[COMPLETE?] --no--> [ASSESS]
|
yes
v
[REPORT] Summary of all changes made
Safety Guardrails
Iteration Limits
- Max iterations: 25 per session (configurable)
- Max file changes: 50 files per session
- Max deletions: 0 (deletions require explicit approval)
- Timeout: 10 minutes per iteration
Automatic Stop Conditions
- Test suite starts failing after a change (rollback + stop)
- Same error encountered 3 times in a row
- Changes drift outside the defined scope
- Token budget approaches limit
Forbidden Actions (require user approval)
- Deleting files
- Modifying configuration files (.env, package.json dependencies)
- Git operations (commit, push, branch)
- Installing new dependencies
- Changes outside the specified directory scope
Rules
- Define scope first: Always establish task boundaries before starting the loop
- One change per iteration: Make small, verifiable changes
- Verify every change: Run relevant tests or validation after each modification
- Track progress: Maintain a running log of completed steps
- Stop on uncertainty: If unsure about next step, pause and ask the user
- No side effects: Changes should be limited to the stated task
- Rollback capability: Every change should be reversible
Configuration
autonomous_loop: max_iterations: 25 max_files: 50 allow_deletions: false allow_new_files: true scope: "src/components/" # Restrict changes to this directory verify_command: "npm test" # Run after each change stop_on_test_failure: true report_interval: 5 # Report progress every N iterations
Examples
Large Refactoring
User: Convert all class components in src/components/ to functional
components with hooks. Use the autonomous loop.
[INIT] Scope: src/components/*.tsx, 23 class components found
[ITER 1] Converting Button.tsx... PASS
[ITER 2] Converting Modal.tsx... PASS
[ITER 3] Converting Table.tsx... FAIL (lifecycle method needs useEffect)
[DIAGNOSE] Adding useEffect for componentDidMount logic
[ITER 3b] Table.tsx retry... PASS
...
[ITER 23] All components converted. Test suite: 142/142 passing.
[REPORT] 23 files modified, 0 test regressions.
Batch Test Generation
User: Generate unit tests for all service files in src/services/
[INIT] Scope: src/services/*.ts, 12 service files, 0 existing tests
[ITER 1] Creating userService.test.ts (8 tests)... PASS
[ITER 2] Creating authService.test.ts (12 tests)... PASS
...
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.