refactor-safely

Guides code refactoring through small verified steps that preserve external behavior.

96|8|Updated Aug 13, 2026
One-click install
npx skills add https://github.com/pingfanfan/hello-dsh --skill refactor-safely-pingfanfan
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor-safely
Source: https://github.com/pingfanfan/hello-dsh/tree/main/examples/skills/refactor-safely
Command: npx skills add https://github.com/pingfanfan/hello-dsh --skill refactor-safely-pingfanfan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring often goes wrong when developers mix behavior changes with structural changes, take steps too large to verify, or lack a way to confirm nothing broke. This Skill enforces a disciplined refactoring workflow so every change stays reversible and behavior-preserving. ## Core Features & Use Cases - Pre-flight checks: Requires a verification method (tests, snapshots, or comparison scripts), a clean working tree, and a concrete reason before touching any code. - Small-step discipline: Defines what a valid single step looks like (extract a function, rename a symbol, move a function) and mandates verification after each step instead of batching. - Ordered playbooks: Provides step-by-step sequences for extracting functions, splitting large files, eliminating duplication, and changing interfaces with old/new coexistence. - Stop and rollback rules: Specifies when to revert (verification failing over ten minutes, scope creep, needing a behavior change) and requires separate refactor: commits. - Use Case: When asked to split a 500-line module, the Skill moves code blocks first and verifies, then adjusts naming and interfaces as separate verified steps, committing each with a refactor: message explaining the motivation. ## Quick Start Ask the AI to refactor this module by splitting the large function into smaller ones, verifying behavior after each step and keeping refactoring in separate commits.

Frequently Asked Questions about refactor-safely

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

FAQPage Schema
How do I refactor code without breaking existing behavior?▼

Refactor in small steps where each step is immediately verifiable, such as extracting one function or renaming one symbol. Run your tests or snapshot comparisons after every step, and keep refactoring commits separate from any behavior changes.

How to split a large function or file safely?▼

Move the code block to its new location first, fix imports, and verify before adjusting names or interfaces. Separating the move from the redesign keeps each change small enough to verify and revert independently.

Should refactoring and bug fixes be in the same commit?▼

No, refactoring and behavior changes must be separate commits. The test is whether each part can be reverted independently; if not, they are mixed and should be split, with refactoring commits using a refactor: prefix.

When should I stop and roll back a refactoring step?▼

Roll back when verification fails and you cannot locate the cause within about ten minutes, when continuing requires a behavior change, or when the change scope starts expanding. Rolling back is cheap; being stuck mid-refactor is expensive.

What should I prepare before starting a code refactoring?▼

You need three things: a way to verify behavior is unchanged (tests, snapshots, or comparison scripts), a clean working tree, and a concrete reason for the change such as a feature that cannot be added or duplication that already caused bugs.