This loop systematically refactors your codebase to improve structure while maintaining test coverage. The agent identifies opportunities for cleaner code without breaking existing functionality.
Improve code structure
Use this loop in any supported IDE or CLI tool to iteratively refactor code with safety nets. Simply provide your codebase and let the agent handle the refactoring process.
Setup Environment
Ensure you have Node.js and npm installed. Clone or open your project in one of the supported tools (Cursor, Claude Code, Codex, etc.).
Initiate the Loop
Run the kickoff prompt to start the refactoring process. The agent will take control from there.
Monitor Progress
Watch as the agent makes changes, runs tests, and iterates. Intervene only if necessary based on feedback.
Analyze current codebase state and identify refactoring targets
Make targeted improvements to code structure (variables, functions, classes)
Run npm test to verify changes don't break existing functionality
If tests fail, inspect results and adjust the refactoring approach
Quality
Automatically identifies and removes unused code to improve codebase quality and maintainability. This loop performs iterative scans for dead code, removes it gradually, and ensures no regressions are introduced.
Quality
Automatically iterates through lint error detection and resolution until the codebase passes linting with zero issues. This loop ensures code quality and consistency by having the agent fix problems as they are identified.
Quality
A prompt-only loop designed to iteratively improve code quality and maintainability until a specified quality gate passes. The agent analyzes the codebase, identifies quality issues, and applies targeted fixes to achieve an 'A' grade quality score.
Repeat until tests pass or maximum iterations reached
Start the "Refactor Safely" loop. Goal: Improve code structure Max iterations: 10 Between iterations run: npm test Exit when: Tests pass Please refactor the provided codebase to improve code structure while ensuring all tests continue to pass. Focus on making the code more readable and maintainable through proper naming, breaking down large functions, removing duplication, and organizing modules logically. Begin now. Self-pace this loop. After each iteration, run `npm test` and evaluate the output, and only continue if the exit condition is not met (Tests pass). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.