refactoring-code
Refactoring Code
Refactoring changes the internal structure of code to make it easier to understand and cheaper to modify without changing its observable behavior. This skill teaches you how to think through a refactoring engagement — understand, diagnose, assess risk, transform incrementally, verify, and review — not just which transformations exist. The catalogs (smells, patterns, architecture, security, performance, testing) live in references/ and are loaded only when the step you're on needs them.
The two hats
Make the change easy, then make the easy change.
At any moment you wear exactly one hat: refactoring (structure changes, behavior identical) or adding functionality (behavior changes, structure stable). Never both in the same step. If a task needs both, refactor first with tests green, commit, then change behavior. Mixing them makes failures undiagnosable: when a test breaks you can't tell whether the structure or the behavior change caused it.
The contract
These rules are not preferences — they are what makes a change refactoring rather than rewriting: