Loop/loopRefactoringmedium riskintermediatesafety B · 85Forward Futurepre-dates current gate · under review

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.
claude-code · codex

Use this when

Use this when a code project has accumulated small maintenance problems—unused code, stale files, duplicated logic, broken links, old comments, inconsistent names, or confusing organization—but broad deletion would be risky.

How it runs

  1. Inspect the current code-project state and identify active branches, uncommitted edits, generated files, configuration, and other work that must not be disturbed.
  2. Collect possible cleanups, then use code references, configuration, documentation, tests, or runtime behavior to prove one candidate is genuinely low risk.
  3. Make the smallest useful change and run the existing build, tests, application checks, and diff review; keep it only when behavior stays intact and no unrelated work changes.
  4. Repeat until no confirmed low-risk cleanup remains, progress stalls, verification is unavailable, or the next candidate needs approval.

Done when

✓ No confirmed low-risk cleanup remains, and existing behavior still passes. Every retained cleanup is supported by direct evidence, relevant builds and tests pass, the application still runs where applicable, unrelated work is untouched, and uncertain candidates are deferred rather than deleted.

Why it works

One proven cleanup at a time keeps the work easy to review and undo. Requiring evidence before deletion—and protecting uncertain files and edits—prevents a tidy-up pass from removing code that is active but poorly understood.

Implementation note

Here, repository means the code project and its files. This loop cleans source and project structure; the separate repository cleanup loop handles Git branches, pull requests, commits, and worktrees. Never delete something merely because its purpose is not immediately obvious.

Source: Forward Future ↗graded B · 85/100 — how grades work →

More refactoring loops

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

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.