Refactor features that touch many modules
Give Claude Opus 4.5 the related modules, their call graph and the existing tests, ask for a step-by-step plan first, then the changes one step at a time. Run the tests after each step and continue only when behavior is unchanged.
Example: How should we break up this payment module?
Material
- Current state
- PaymentService is 1,800 lines and handles charging, refunds, invoices and reconciliation; all four share a single status field.
- Constraints
- No downtime; existing API inputs and responses stay the same.
PromptGive a step-by-step refactoring plan: what each step changes and how to verify behavior is unchanged. Do the lowest-risk steps first.
Sample answer · written by hand to show the reasoning
Step 1: add API-level tests for charging, refunds, invoices and reconciliation as the baseline for every later step. Step 2: split status into paymentStatus and invoiceStatus, and keep returning the old field computed from the new ones so the API doesn’t change. Step 3: move invoices and reconciliation, the read-heavy parts, into their own services first. Step 4: split charging and refunds last. After each release, compare a week of reconciliation results and move on only when they match.