safe-refactoring

Plan incremental refactoring of legacy code using Tidy First? and Branch by Abstraction.

Updated Feb 21, 2026
One-click install
npx skills add https://github.com/togswr/agent-skills --skill safe-refactoring-togswr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-refactoring
Source: https://github.com/togswr/agent-skills/tree/main/skills/safe-refactoring
Command: npx skills add https://github.com/togswr/agent-skills --skill safe-refactoring-togswr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and templates (resource) components.

What problem does it solve?

This Skill provides a comprehensive framework and set of techniques for safely refactoring code, improving its structure and maintainability without altering its external behavior. It addresses challenges in dealing with legacy code, identifying code smells, and planning large-scale structural changes.

Core Features & Use Cases

  • Code Smell Detection: Identify and address common code smells using a catalog of indicators.
  • Safe Refactoring Techniques: Apply proven methods for small and large-scale refactoring, including Tidy First? and Branch by Abstraction.
  • Legacy Code Improvement: Utilize specific algorithms and patterns to safely modify code lacking tests.
  • Use Case: You need to refactor a complex, legacy module that lacks tests. This Skill guides you through identifying test points, breaking dependencies, writing characterization tests, and applying safe refactoring patterns to improve the code incrementally.

Quick Start

Use the safe-refactoring skill to propose a plan for refactoring legacy code that lacks tests.

Frequently Asked Questions about safe-refactoring

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

FAQPage Schema
How do I refactor legacy code that lacks tests without breaking existing behavior?

Refactoring legacy code without tests requires identifying test points, breaking dependencies, and writing characterization tests. You can then apply safe incremental patterns to improve the code structure without altering external behavior.

What is the best way to handle large-scale structural changes during code refactoring?

Handling large-scale structural changes is best achieved using Branch by Abstraction. This technique isolates changes behind an abstraction layer, allowing incremental refactoring while keeping the system functional throughout the transition.

How do I identify and address code smells before refactoring?

Identifying code smells involves checking a catalog of structural indicators like duplicated logic or long methods. Addressing these smells early clarifies the specific structural improvements needed for safe refactoring.

Can I apply test-driven development to make small structural improvements safely?

Yes, test-driven development facilitates small structural improvements by ensuring tests validate each incremental change. Techniques like Tidy First? help sequence these micro-refactorings safely before deeper logic changes.

When should I use the Legacy Code Change Algorithm for software maintenance?

Use the Legacy Code Change Algorithm when modifying untested or difficult-to-test code. It provides a structured sequence for breaking dependencies and adding tests, enabling safe incremental modifications to legacy systems.