← ClaudeAtlas

refactoringlisted

MUST USE when restructuring existing code without changing behavior: extracting functions/modules, inlining, simplifying, decoupling, reorganizing files, renaming across the codebase, or cleaning up code structure. Enforces behavior-locking tests before any structural change and incremental verification after each move. Distinct from brainstorming (which designs new behavior) and bug fixing (which changes behavior). Triggers on: "refactor", "restructure", "reorganize", "clean up this code", "extract into", "inline this", "simplify", "decouple", "modularize", "move these files", "split this module", "consolidate", "reduce complexity". Routed by using-superpowers, or invoke directly via /refactoring.
brunob54/superpowers-orchestrator · ★ 3 · Code & Development · score 76
Install: claude install-skill brunob54/superpowers-orchestrator
# Refactoring Change structure without changing behavior. Prove it at every step. ## Why This Exists Refactoring feels safe — "I'm just moving things around." That's exactly why it's dangerous. Without a behavior lock, structural changes silently break contracts, reorder side effects, or drop edge cases. This skill enforces the discipline that makes refactoring actually safe. ## Phase 1: Behavior Lock Before touching any structure, lock the current behavior with tests. 1. **Run the existing test suite.** Detect the project's test runner (check `package.json` scripts, `Makefile`, `pytest.ini`, `Cargo.toml`, etc.) and run it. Every test must pass. If tests fail before you start, you're debugging, not refactoring — switch to `systematic-debugging`. 2. **Identify the refactoring surface** — which functions, modules, or files will be structurally changed. 3. **Audit test coverage on that surface.** For each function/module in scope: - Is there a test that exercises its public API or observable behavior? - If yes: verify it passes. That test is now your behavior lock. - If no: write a characterization test that captures current behavior. This test doesn't assert "correct" behavior — it asserts "current" behavior. The point is to detect unintended changes, not to validate design. **Writing characterization tests:** Call the function with representative inputs and assert on the exact output. For side-effectful code (writes files, sends requests, modifies state