safe-refactoring

Restructure code in small verified steps while preserving external behavior.

Updated May 9, 2026
One-click install
npx skills add https://github.com/natelandau/cc-plugin --skill safe-refactoring-natelandau
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-refactoring
Source: https://github.com/natelandau/cc-plugin/tree/main/plugins/natelandau-toolkit/skills/safe-refactoring
Command: npx skills add https://github.com/natelandau/cc-plugin --skill safe-refactoring-natelandau

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring often drifts into uncontrolled editing: behavior changes sneak in, tests get "fixed" to match new output, and big-bang rewrites break working code. This Skill enforces a disciplined, behavior-preserving refactoring process so structural improvements never alter what the code does. ## Core Features & Use Cases - Golden rules enforcement: Preserves behavior, mandates small verifiable steps, requires a green test baseline, and forbids mixing refactoring with bug fixes or features. - Structured workflow: Guides you through understanding intent, establishing a test baseline (including characterization tests for uncovered code), batching coherent changes, and committing only green states. - Technique catalog: Provides a reference table of common techniques such as extract function, move class, rename, inline, and replace conditional with polymorphism, mapped to the problems they solve. - Use Case: When asked to "clean up" a tangled 300-line function, the Skill directs extracting methods in small batches, running the test suite after each batch, and committing only when green. ## Quick Start Ask the assistant to refactor a specific module or function to improve readability without changing its behavior, and it will apply this disciplined step-by-step process.

Frequently Asked Questions about safe-refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without changing its behavior?

Refactor in small verifiable steps: establish a green test baseline first, group changes into coherent batches like all renames together, run tests after each batch, and commit only when green. Never mix refactoring with bug fixes or new features.

How to refactor legacy code that has no tests?

Write characterization tests first that pin the current behavior of the target code, and commit them separately. These tests become the safety net that lets you verify each refactoring step preserves behavior.

What are the most common code refactoring techniques?

Common techniques include extract function or method, extract class, move function or class, rename, inline, replace conditional with polymorphism, introduce parameter object, split module, and consolidate duplicates. Each maps to a specific problem like long functions or unclear names.

When should I stop during a refactoring session?

Stop when you drift beyond the plan: changing more files than intended, modifying tests to match new behavior, or adding functionality. These signals mean you have left refactoring and should reassess scope before continuing.

Can refactoring include bug fixes or performance optimization?

No. Refactoring changes structure only, never behavior. If you find a bug, note it and fix it in a separate commit. Behavior-changing performance work needs its own verification outside the refactoring commits.