# Refactoring Patterns Skill

> Safe transformations — same behavior, better structure.

- Skill: `fabioc-aloha/refactoring-patterns-skill` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add fabioc-aloha/refactoring-patterns-skill`
- Raw SKILL.md: https://api.skillmd.com/api/skills/fabioc-aloha/refactoring-patterns-skill/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: fabioc-aloha (https://skillmd.com/u/fabioc-aloha)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/fabioc-aloha/refactoring-patterns-skill

---


# Refactoring Patterns Skill

> Safe transformations — same behavior, better structure.

## Golden Rule

Tests pass before AND after.

## When to Refactor

| Trigger | Action |
| ------- | ------ |
| Feature is hard to add | Refactor first |
| Same bug twice | Refactor to prevent |
| "I don't understand" | Refactor for clarity |

## When NOT to Refactor

- No tests + time pressure
- Code won't change
- Right before release
- Should rewrite instead

## Core Moves

| Move | When |
| ---- | ---- |
| Extract Function | Does too many things |
| Inline Function | Body clear as name |
| Extract Variable | Complex expression |
| Rename | Name doesn't reveal intent |
| Move Function | Uses other class's data |

## Code Smells → Fix

| Smell | Refactoring |
| ----- | ----------- |
| Long function | Extract Function |
| Long param list | Parameter Object |
| Duplicate code | Extract Function |
| Feature envy | Move Function |
| Large class | Extract Class |

## Refactor vs Rewrite

| Refactor | Rewrite |
| -------- | ------- |
| Core logic sound | Design is wrong |
| Tests exist | Untestable |
| <30% changes | >70% changes |

## Safe Workflow

Commit → Test → Small change → Test → Commit → Repeat

## Synapses

See [synapses.json](synapses.json) for connections.

