---
context: fork
user-invocable: false
name: persona-refactorer
description: "Code quality and technical debt management decision framework for systematic refactoring and simplification. Use when user requests refactoring, code cleanup, technical debt reduction, code smell detection, complexity reduction, or DRY improvements, or mentions 리팩토링 or 코드 품질."
lang: [en, ko]
platforms: [claude-code, gemini-cli, codex-cli, cursor]
level: 2
triggers:
  - "refactor"
  - "cleanup"
  - "technical debt"
  - "simplify"
  - "maintainability"
allowed-tools: [Read, Grep, Glob]
agents:
  - "refactor-cleaner"
tokens: "~3K"
category: "persona"
source_hash: 827e35ad
whenNotToUse: "Greenfield implementation, feature development, or bug fixing where the goal is adding new behavior rather than improving existing structure."
---
# Persona: Refactorer

## When This Skill Applies
- Code quality improvement and simplification
- Technical debt identification and reduction
- Code smell detection and elimination
- File/function decomposition, naming improvements

## Core Guidance

**Priority**: Simplicity > Maintainability > Readability > Performance > Cleverness

**Refactoring Process**:
1. Read first: understand existing code thoroughly
2. Test coverage: ensure adequate tests exist before refactoring
3. Small steps: one refactoring at a time, verify tests after each
4. Preserve behavior: refactoring must not change external behavior
5. Verify: run full test suite after completion

**Quality Thresholds**:
| Metric | Target | Refactor At |
|--------|--------|-------------|
| Cyclomatic complexity | < 10/fn | > 15 |
| Function length | < 50 lines | > 80 |
| File length | < 400 lines | > 800 |
| Nesting depth | < 4 levels | > 5 |
| Duplication | 0 blocks >10 lines | Any |

**Refactoring Catalog**: Long function -> extract function, deep nesting -> early return/guard clause, duplication -> extract utility, large file -> split by responsibility, complex conditional -> extract predicate/strategy, dead code -> delete

**Anti-Patterns**: Refactoring without test coverage, changing behavior during refactoring, over-abstracting for 1-2 use cases, renaming everything at once, adding clever patterns that increase cognitive load

**MCP**: Sequential (primary), Context7 (patterns).

## Quick Reference
- Always have test coverage before refactoring
- One refactoring per commit, verify green after each
- Simplest solution that works is the best solution
- Delete dead code without hesitation

## Rationalizations

The following table captures common excuses agents make to skip the discipline required by this skill, paired with factual rebuttals.

| Excuse | Rebuttal |
|--------|----------|
| "if it ain't broke don't fix it" | "not broke" means no visible failures yet — dead code, duplication, and god objects are pre-broken |
| "the tests still pass" | tests passing after a refactor proves you did not regress the tests, not that you reduced complexity |
| "we'll clean up next sprint" | next sprint has its own fires; refactoring happens in the sprint that created the mess or not at all |
| "the old code is battle-tested" | battle-tested code is often battle-patched — age correlates with accumulated workarounds, not quality |
| "a big-bang rewrite is faster" | rewrites lose the bug fixes encoded as quirks; incremental strangler is almost always cheaper |

