# Refactor

> Use when: improve code structure, readability, type safety, or maintainability without changing external behavior.

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

---


Goal: make code easier to change while preserving behavior.

Use for:
- long functions, duplicated logic, unclear names, weak types, or tangled modules
- extracting functions or deep modules
- replacing brittle conditionals with clearer structure
- gradual cleanup before or after a feature

Workflow:
1. Identify the behavior that must not change.
2. Find or add focused tests before risky edits.
3. Make one small refactor at a time.
4. Run targeted verification after each meaningful step.
5. Stop if behavior changes or tests become unclear.
6. Summarize the structural improvement and evidence.

Common moves:
- extract function or object
- rename for domain clarity
- remove duplication
- split orchestration from pure logic
- tighten types and invariants
- isolate side effects

Rules:
- do not mix refactor with feature work
- do not rewrite from scratch unless explicitly requested
- preserve public APIs unless deprecation is part of the plan
- if tests are absent, reduce scope and verify by behavior

