Claude Code Planning - 2026
Planning Skill for Large-Scale Refactoring
Large-scale refactoring without a plan is how codebases die. Before you rename that core function or restructure that module, use Claude Code to map dependencies, plan the migration order, and validate each step. Here is how to do it right.
The Problem with Unplanned Refactoring
Large refactoring fails in predictable ways. You rename a function. Three files still call the old name. You fix those. Now something downstream breaks. You fix that. Thirty minutes later you are deep in a rabbit hole of cascading fixes and wondering why you started.
The root cause: refactoring is a tree traversal problem, not a linear search. Code has dependencies. When you change a leaf, you must update its parent. When you update the parent, you may affect siblings. Without mapping this first, you are guessing.
The solution: plan the refactoring as a dependency-ordered sequence of changes. Claude Code can help map these dependencies accurately.
Step 1: Map the Dependency Graph
Before changing anything, ask Claude to analyze the scope of the proposed change:
I want to refactor the authenticateUser function in auth/service.js. 1. Find all files that call authenticateUser 2. Find all files that call functions which authenticateUser calls 3. Identify which call sites are in production code vs tests 4. Map the dependency tree from this function outward Show me the full list of files that will need updating if I rename or change this function signature.
Claude will trace the call graph and give you the complete set of files that need updating. This is the migration map - do not proceed until you have it.
Step 2: Order the Changes
With the dependency map, plan the change order. The rule: work from leaves toward roots. Change the deepest dependencies first, then update their callers, then the callers of those callers:
- Step 1: Change the core function itself (rename, restucture, or reimplement)
- Step 2: Update all direct callers
- Step 3: Update indirect callers (callers of the direct callers)
- Step 4: Continue until you reach the entry points
For each step: make the change, run the tests, verify behavior is preserved. Only proceed to the next step when the current one passes.
This ordered approach means each intermediate state is a working system. If something breaks, you know exactly which step introduced it.
Step 3: Write the Migration Script
For large refactoring, write a step-by-step migration script that Claude Code follows:
## Migration: Rename authenticateUser to createUserSession Phase 1: - Edit auth/service.js: rename function to createUserSession - Edit auth/middleware.js: update the import and call site - Run tests: npm test -- --testPathPattern=auth - Verify: auth flows still work in staging Phase 2: - Edit users/profile.js: update call site - Edit payments/checkout.js: update call site - Run tests: npm test -- --testPathPattern="users|payments" - Verify: user profile and checkout flows work Phase 3: - Edit api/v1/auth.js: update remaining call sites - Run full test suite: npm test - Verify: all tests pass Do not proceed to Phase 2 until Phase 1 tests pass.
Having the script as a document means you can stop and resume without losing your place. Each phase is a self-contained unit that preserves functionality.
Step 4: Validate at Each Step
The critical discipline: validate after each incremental change. What to check:
- Tests pass - Not just that they run, but that assertions actually exercise the changed code
- Behavior preserved - Manually walk through the user flow in staging or locally
- Type checking - If using TypeScript, run the type checker after each change
- No dead code introduced - The old function should have no remaining call sites before you remove it
If tests fail at any step, stop and fix before proceeding. Large refactoring only works when every intermediate state is a working system.
Common Refactoring Patterns
| Pattern | Risk | Mitigation |
|---|---|---|
| Rename function | Breaks all call sites | Use IDE refactor tool + update all call sites in dependency order |
| Split large function | Loses context, changes call signature | Extract new functions first, update call sites, then remove old logic |
| Move function between modules | Import paths break, circular deps | Update imports in target module first, then all callers, then delete original |
| Change data structure | All consumers need updating | Deprecate old structure, add new structure, update consumers one by one |
Plan before you refactor
Use Claude Code dependency analysis before starting any large refactoring. The upfront investment in planning saves hours of debugging.
Browse All Skills - Planning Skills -