refactoring

Refactor existing code with characterization tests and small reviewable steps.

4|Updated May 16, 2026
One-click install
npx skills add https://github.com/machenjie/rd-skills --skill refactoring-machenjie
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactoring
Source: https://github.com/machenjie/rd-skills/tree/main/src/foundation/capabilities/refactoring
Command: npx skills add https://github.com/machenjie/rd-skills --skill refactoring-machenjie

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Refactoring guides behavior-preserving code reshaping so you can improve readability and structure without accidentally changing what the system does.

Core Features & Use Cases

  • Behavior-preservation discipline: preserves observable behavior while treating any intentional behavioral change as a separate, explicitly approved step.
  • Characterization-test safety net: helps you create Michael Feathers-style characterization tests before touching risky, poorly covered, or high-stakes code.
  • Small, reviewable steps: enforces logically independent steps so each commit can be reviewed, reverted, and bisected confidently.
  • Contract and boundary protection: treats public API contracts and persistence-visible boundaries (schemas, events, payload shapes) as non-negotiable constraints.
  • Risk-aware guidance: escalates when authorization, financial calculations, or data integrity logic is involved without sufficient test coverage.

Quick Start

Use the refactoring skill to refactor a fragile, hard-to-read module while preserving its observable behavior by adding characterization tests first and then applying small, independently verifiable restructuring steps.

Frequently Asked Questions about refactoring

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

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

To refactor legacy code safely, establish a characterization test safety net first to capture existing observable behavior, then apply small, logically independent restructuring steps that preserve public API contracts.

What is characterization testing and when do I need it for refactoring?▼

Characterization testing captures and locks in the current observable behavior of risky or poorly covered code before you refactor, ensuring your restructuring steps remain behavior-preserving and reviewable.

How do I reduce coupling and simplify methods while protecting API contracts?▼

Reduce coupling and simplify methods by treating persistence-visible boundaries like schemas and payload shapes as non-negotiable constraints, ensuring public API contracts remain unchanged during behavior-preserving refactoring.

Can I refactor code that involves financial calculations or authorization logic?▼

Yes, but refactoring high-risk authorization or financial calculation logic requires sufficient test coverage first, as risk-aware guidance escalates and halts restructuring when safeguards are missing.

What is the best way to ensure refactoring commits can be easily reverted?▼

The best way to ensure commits are revertible is enforcing small, reviewable refactoring steps where each step is logically independent, allowing confident bisection and rollback of code reshaping changes.

When should I not attempt behavior-preserving refactoring?▼

Avoid behavior-preserving refactoring when high-risk data integrity logic lacks sufficient test coverage, or when you intend to change observable behavior, which must be treated as a separate explicitly approved step.