safe-refactoringlisted
Install: claude install-skill varunk130/ai-workflow-playbooks
# Safe Refactoring
## What This Skill Enables
Agents with this skill can improve code structure -- readability, modularity, performance -- while guaranteeing that external behavior stays identical. Without it, agents tend to rewrite large sections at once, introduce subtle regressions, and produce diffs that are impossible for humans to review confidently. Safe refactoring turns a risky "big bang" rewrite into a chain of small, provably correct transformations.
## Core Competencies
### 1. Decide Whether to Refactor at All
Not every piece of ugly code needs attention right now. Before touching anything, answer these questions:
| Question | If "No", stop here |
|---|---|
| Is this code on the path of the current task? | Do not refactor drive-by style. |
| Do passing tests already cover the behavior? | Write tests first (see competency 2). |
| Is the improvement worth the review cost? | A rename across 200 files is noisy for little gain. |
| Is there a deadline within hours? | Ship first, refactor in a follow-up branch. |
Refactoring that is not motivated by a concrete upcoming change is speculative. Avoid it.
### 2. Lock Behavior with Tests Before Changing Structure
The "lock then change" pattern is non-negotiable:
```
Step 1 -- Write or confirm tests that cover the code you are about to move.
Step 2 -- Run the full relevant test suite. It must pass.
Step 3 -- Perform ONE refactoring move (see competency 3).
Step 4 -- Run the suite again. It must still pass.
Step 5 --