# Refactoring

> Restructure code safely while preserving behavior, reducing duplication, clarifying ownership, and maintaining compatibility.

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

---


# Refactoring

1. Establish a behavior baseline with tests or reproducible commands.
2. Identify the ownership boundary and dependency direction the code should follow.
3. Move in small compilable steps; avoid simultaneous semantic changes unless explicitly required.
4. Preserve public APIs or provide an intentional migration path.
5. Delete replaced code and update imports, docs, tests, and generated artifacts.
6. Compare behavior and performance before and after.

