← Patterns

Agentic Refactor Loop

Core Concept

A template for driving large-scale, mechanical refactors across a codebase using AI agents with human pair review — the plan is a first-class reviewable artifact (committed to git), and the agent executes the approved plan in bite-size chunks that feed learning back into the plan.

The Loop

  1. Pair on framing — human + human agree on what the refactor is and why
  2. Robot drafts the plan — specific steps, rules, exceptions
  3. Pair reviews the plan — catch obvious gaps
  4. A different robot analyzes the plan — cross-model check (a different model / different prompt finds what the first one missed)
  5. Commit the plan as a PR — the plan lives in git, is reviewable on its own, and becomes durable documentation
  6. Approved plan goes live — robot executes across the codebase
  7. Pair reviews the changes — could be large, so keep batches bite-size
  8. Ship — then iterate: review comments on one batch feed back into the plan for the next

Why It Works

Variations / Extensions

When to Use / When Not To

Use:

Don’t use: