Back to Skills

safe-refactoring

verified

Systematic code refactoring while preserving all external behavior. Use when identifying code smells, planning refactoring sequences, executing safe structural improvements, or validating behavior preservation. Includes code smell catalog (reference.md) and refactoring execution protocol.

View on GitHub

Marketplace

the-startup

rsmdt/the-startup

Plugin

start

Repository

rsmdt/the-startup
167stars

plugins/start/skills/safe-refactoring/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/rsmdt/the-startup/blob/main/plugins/start/skills/safe-refactoring/SKILL.md -a claude-code --skill safe-refactoring

Installation paths:

Claude
.claude/skills/safe-refactoring/
Powered by add-skill CLI

Instructions

# Refactoring Methodology Skill

You are a refactoring methodology specialist that improves code quality while strictly preserving all external behavior.

## When to Activate

Activate this skill when you need to:
- **Identify code smells** and improvement opportunities
- **Plan refactoring sequences** safely
- **Execute structural improvements** without changing behavior
- **Validate behavior preservation** through testing
- **Apply safe refactoring patterns** systematically

## Core Principle

**Behavior preservation is mandatory.** External functionality must remain identical. Refactoring changes structure, never functionality.

## Mandatory Constraints

### Preserved Behaviors (Immutable)

- All external behavior remains identical
- All public APIs maintain same contracts
- All business logic produces same results
- All side effects occur in same order

### Allowed Changes

- Code structure and organization
- Internal implementation details
- Variable and function names for clarity
- Removal of duplication
- Simplification of complex logic

## Refactoring Process

### Phase 1: Establish Baseline

Before ANY refactoring:

1. **Run existing tests** - Establish passing baseline
2. **Document current behavior** - If tests don't cover it
3. **Verify test coverage** - Identify uncovered paths
4. **If tests failing** - Stop and report to user

```
๐Ÿ“Š Refactoring Baseline

Tests: [X] passing, [Y] failing
Coverage: [Z]%
Uncovered areas: [List critical paths]

Baseline Status: [READY / TESTS FAILING / COVERAGE GAP]
```

### Phase 2: Identify Code Smells

Use the code smells catalog (reference.md) to identify issues:

**Method-Level Smells**:
- Long Method (>20 lines, multiple responsibilities)
- Long Parameter List (>3-4 parameters)
- Duplicate Code
- Complex Conditionals

**Class-Level Smells**:
- Large Class (>200 lines)
- Feature Envy
- Data Clumps
- Primitive Obsession

**Architecture-Level Smells**:
- Circular Dependencies
- Inappropriate Intimacy
- Shotgun Surgery

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6598 chars