Refactoring loops

Incremental refactors with a green-tests invariant: small steps, verified after each one.

9 graded loops in this category.

Repair React issues in small batches

Baseline the scan, fix a small batch of real errors or warnings, and verify each change improves it without regressions.

prompt
→ Claude Code
Run `pnpm exec react-doctor . --verbose --yes --offline --fail-on none` to record the baseline, then rerun with `--fail-on error`. Fix at most five genuine findings, run the same scan and relevant project checks, and keep only verified improvements. Clear errors before high-confidence warnings. Stop when clean, blocked, approval is required, a finding is false-positive, or another pass makes no measurable progress. Finish with baseline and final results, retained fixes, reverted attempts, checks, and remaining findings.

Refactor auth module, pass tests

Loop/goalGitHubB

Refactor the authentication module iteratively until all tests pass, stopping after ten attempts.

prompt
→ Claude Code
/goal "Refactor auth module until all tests pass" --max-iterations 10
refactoringlow risk

Migrate an API import by import

Loop/goalXB

Sweep a codebase from a legacy API to its v2 replacement with tests and typecheck as the safety net, capped at 30 turns.

prompt
→ Claude Code
/goal every file importing from `./legacy-api` now imports from `./v2-api`, all tests pass, and `npm run typecheck` is clean — stop after 30 turns

Dead code elimination

Loop/goallooprepoB

Hunt down unreferenced exports, unused files, and unreachable branches, deleting them in small verified steps until the analyzer reports clean.

prompt
→ Claude Code
/goal `npx knip` reports no unused files or exports — remove one cluster of dead code at a time, run the full test suite and typecheck after each removal, and revert any deletion that breaks them; stop after 15 turns

Tidy code, one safe change at a time

Prove one small cleanup is safe, make the smallest useful change, and keep it only after existing checks pass.

prompt
→ Claude Code
Review [repository or code project] for dead code, meaning unreachable or unused code; stale files or comments; unused dependencies; duplication; broken links; inconsistent names; and confusing structure. Protect unrelated, active, uncommitted, generated, and uncertain work. Prove one low-risk cleanup, make the smallest coherent change, then rerun the build, tests, runtime checks, and diff review. Keep only verified improvements. Stop when none remain, progress stalls, verification is unavailable, or approval is required. Return changes, evidence, and deferred candidates.

Complete the task, ship it

Loop/ralphGitHubB

Work autonomously through subtasks, verify lint and tests pass, then commit and push to main until done.

prompt
→ Claude Code
# Persistent Task Loop Task: $ARGUMENTS --- ## Loop Protocol You are in a persistent development loop. Work autonomously until the task is 100% complete. ### Each Iteration: 1. Assess - Track subtasks with the task tools (TaskCreate/TaskUpdate — TodoWrite no longer exists) - Check current state: git status , test results - Identify what remains 2. Execute - Do the next step - Follow the auto-loaded MeshForge rules (CLAUDE.md + .claude/rules/security.md ) - Walk .claude/rules/honest failure modes.md over every error path you write - Write tests for new functionality 3. Verify — capture real exit codes; never judge from truncated streams bash python3 scripts/lint.py --all 1>/tmp/lint.log 2>&1; echo LINT EXIT=$? python3 -m pytest tests/ -q 1>/tmp/pytest.log 2>&1; echo TEST EXIT=$? tail -5 /tmp/pytest.log 4. Continue - If not done, loop back to Assess - Mark completed tasks as you go --- ## Exit Conditions ALL must be true: - [ ] Task is 100% complete - [ ] scripts/lint.py --all exits 0 - [ ] All tests pass (exit code 0, not a "passed" line in a truncated stream) - [ ] Changes committed on main (solo workflow — PR/feature-branch flow retired 2026-04-19) - [ ] Pushed: git push origin main (then pull the fleet boxes) --- ## MeshForge Context Key paths: src/ (source) · tests/ · src/gateway/ · src/launcher tui/ · src/utils/ Security rules are auto-loaded from .claude/rules/security.md — don't restate, just follow them (lint + pre-commit hook enforce). --- ## Completion Signal When ALL exit conditions verified: <promise>DONE</promise> Do NOT output the promise until fully verified complete. --- "I'm in danger!" - Ralph Wiggum (but you're not, keep looping
refactoringhigh risk

Refactor API to use dependency injection

Loop/ralphGitHubB

Refactor src/api/ to use dependency injection, keep all existing tests passing, add tests for the new DI container, and output completion promise when done.

prompt
→ Claude Code
/ralph-loop "Refactor src/api/ to use dependency injection. Keep all existing tests passing. Add tests for new DI container. Output <promise>COMPLETE</promise> when done and all tests pass." --max-iterations 20
refactoringmedium risk

Convert codebase to TypeScript

Loop/ralphGitHubB

Refactor all files to TypeScript and run tests until the full suite passes.

prompt
→ Claude Code
/ralph-loop "Refactor codebase to use TypeScript. Output COMPLETE when all files converted and tests pass." --completion-promise "COMPLETE" --max-iterations 100
refactoringhigh risk

Ralph a refactor, module by module

Break a large refactor into a JSON backlog of modules and let fresh-context iterations convert one module per pass, with guardrails capturing every pattern decision so the result stays consistent.

prompt
→ Claude Code
/loop fresh context each iteration: read refactor-plan.json and .ralph/guardrails.md, take the next module not marked converted, migrate it to the target pattern described in PROMPT.md, run tests and typecheck, and mark it converted only when green; record every convention decision you make (naming, file layout, error handling) in .ralph/guardrails.md so later modules match earlier ones; stop when all modules are converted or after 30 turns