AI agent refactor plan
Use an AI agent to plan refactors by preserving behavior, sequencing changes and proving the result with tests.

Put it into practice
What you will produce
A sequence of reversible edits, each naming files, behavior preserved, focused checks and dependencies on prior steps.
- 01
State preserved behavior
Write public behavior and invariants to retain using examples from current callers or tests.
Expected result: Acceptance conditions exist before edits.
- 02
Map extraction dependencies
List candidate files, callers, data ownership, and dependency direction that constrain ordering.
Expected result: The boundary and sequence reflect the actual code path.
- 03
Break work into reversible checkpoints
For each step name files, one behavior change, focused checks, and stop or revert condition.
Expected result: A failed intermediate check is isolated and reversible.
- 04
Review final proof
Include baseline, intermediate checks, final contract validation, and rollback owner for risky steps.
Expected result: The plan is verifiable against evidence.
Acceptance checks
- Acceptance conditions exist before edits.
- A failed intermediate check is isolated and reversible.
- The plan is verifiable against evidence.
Limits and trade-offs
A plan is a hypothesis until the code is inspected. Update scope when evidence contradicts the initial map instead of forcing the plan through.
Official sources
Plan a refactor
Related guides
Claude Code Plan Mode: A Practical Guide
Claude Code Plan Mode lets you review and steer a task plan before any file is touched. Full guide: shortcut (Shift+Tab), activation, when to use it, and how to execute the plan.
Most people use Claude Code like a chat: describe the task, watch it execute. That works for small changes. For anything touching more than two files, there's a better path. If you are looking for the shortcut, press Shift+Tab to toggle Plan Mode. To turn it off, press Shift+Tab again or use /plan only for the prompt that needs planning. The dedicated Plan Mode troubleshooting guide covers the common terminal and version issues. Plan Mode. What Plan Mode does When you activate Plan Mode, Claude reads your codebase and produces a step by step execution plan but makes no changes. You see exactly what it intends to do before a single file is written. This gives you a checkpoint: approve the plan, redirect it, or catch a wrong assumption before it cascades into 15 wrong edits. How to activate Plan Mode the shortcut Two ways: Keyboard shortcut : press Shift+Tab…
Read the guideClaude Code Subagents: Parallel Agents
Learn when Claude Code subagents help, how to split parallel work, and how to configure a focused custom subagent without creating conflicts.
Subagents are useful when a task can be split cleanly: one agent searches the authentication code, another traces the database path, and the main conversation compares what they found. They add little to "read this file" or to work where every step depends on the same context. Short version: delegate independent research or a separate review when the results are worth the extra context and usage. Give each agent a narrow scope, the files or area to inspect, and a specific report format. Keep dependent work in the main conversation. Claude Code agents vs subagents Claude Code's documentation calls delegated workers subagents and uses Agent for the tool that starts them. When people search for Claude Code agents in this context, they usually mean subagents: workers that handle a delegated task in their own context and return a result to the main conversation. Claude Code's subagent documentation uses this terminology.…
Read the guideMy Claude Code workflow: context, planning, skills and review
The workflow I use with Claude Code, what I keep in project context, when I plan or delegate, and where I still review the result myself.
Claude Code is my main coding environment and part of my full development setup. This article describes the workflow I use: give the tool project context, plan changes that span several files, reuse stable procedures, then review the diff. It is a personal workflow, not a controlled speed benchmark. This is what changed. The shift: from editor to conversation The useful part is being able to point to an existing pattern: "implement the blog post page following the same pattern as the freebie page" . Claude can inspect the project and propose a change that follows its types, error handling and imports. I still check whether it actually did. That only works if Claude knows your codebase conventions. Which brings me to point one. 1. CLAUDE.md is non negotiable Every project gets a CLAUDE.md at the root. It's a plain markdown file Claude reads at the start of every session.…
Read the guide