Skip to content
Back to skills

Safe Refactoring

ASecurity

Use when restructuring, renaming, moving, or extracting code that already works — before making the first edit

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 6, 2026
ai-agentsrustsqlrefactoringapi

Works with

  • api

Security analysis

A100/100

Scanned September 6, 2026

npx -y skills add yuchi-chang/no-cape --skill safe-refactoring --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Safe Refactoring?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Safe Refactoring
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/yuchi-chang-safe-refactoring/badge)](https://www.skillsdirectory.com/skills/yuchi-chang-safe-refactoring)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: safe-refactoring
description: Use when restructuring, renaming, moving, or extracting code that already works — before making the first edit
---

# Safe Refactoring

A refactor changes structure, never behavior. The moment behavior changes, it's not a refactor — split it out.

## Rules

- **Never mix restructure and behavior change.** Behavior-preserving moves in one commit; behavior changes in another. A reviewer must be able to skim the refactor commit and trust it's mechanical.
- **Green before, green between, green after.** Run tests before starting (know the baseline), after each mechanical step, and at the end. If tests were already red, stop and report — new breakage and old breakage become indistinguishable.
- **Find every reference before renaming or removing.** Grep beyond what the compiler sees: string references, reflection, config files, serialized field names, SQL, API routes, environment variables, docs. The compiler only checks the typed half.
- **Public surface needs a transition.** Anything external callers depend on (API endpoint, exported function, published schema) gets a deprecation period or an adapter, not an in-place break.
- **Small steps that each leave the build working.** If you must hold five files in your head to know it still compiles, the step is too big.

## Stop rules

- A "rename" starts requiring logic edits → behavior is changing; stop and separate the two.
- Tests fail mid-refactor in a way you didn't predict → you misunderstood a dependency; investigate before continuing, don't patch around it.

## Smell test

Could someone review the diff and verify it's behavior-preserving *without running it*? If not, the steps are too large or the concerns are mixed.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…