refactor
하는 일
동작을 바꾸지 않고 작은 테스트된 단계로 기존 코드의 구조를 개선하도록 에이전트를 안내합니다. 레거시 코드를 정리하거나 기술 부채를 안전하게 줄이려는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓동작을 바꾸지 않고 지저분하거나 오래된 코드를 정리하고 싶을 때.
- ✓중복되거나 지나치게 긴 함수 같은 코드 냄새를 없애고 싶을 때.
- ✓어떤 변경을 하기 전에 승인받은 리팩터링 계획을 원하는 경우.
스킬 링크
https://github.com/luongnv89/claude-howto/blob/main/03-skills/refactor/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“이 레거시 청구 모듈을 안전하게 리팩터링하도록 도와주세요. 먼저 제가 승인할 수 있는 계획부터 세워 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 코드를 조사하고, 테스트 범위를 확인하며, 코드 냄새를 찾아 계획을 씁니다. 그다음 작은 변경을 하나씩 하며 각 단계마다 승인을 요청합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Code Refactoring Skill
A systematic approach to refactoring code based on Martin Fowler's Refactoring: Improving the Design of Existing Code (2nd Edition). This skill emphasizes safe, incremental changes backed by tests.
"Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure." — Martin Fowler
Core Principles
- Behavior Preservation: External behavior must remain unchanged
- Small Steps: Make tiny, testable changes
- Test-Driven: Tests are the safety net
- Continuous: Refactoring is ongoing, not a one-time event
- Collaborative: User approval required at each phase
Workflow Overview
Phase 1: Research & Analysis
↓
Phase 2: Test Coverage Assessment
↓
Phase 3: Code Smell Identification
↓
Phase 4: Refactoring Plan Creation
↓
Phase 5: Incremental Implementation
↓
Phase 6: Review & Iteration
Phase 1: Research & Analysis
Objectives
- Understand the codebase structure and purpose
- Identify the scope of refactoring
- Gather context about business requirements
Questions to Ask User
Before starting, clarify:
- Scope: Which files/modules/functions need refactoring?
- Goals: What problems are you trying to solve? (readability, performance, maintainability)
- Constraints: Are there any areas that should NOT be changed?
- Timeline pressure: Is this blocking other work?
- Test status: Do tests exist? Are they passing?
Actions
- Read and understand the target code
- Identify dependencies and integrations
- Document current architecture
- Note any existing technical debt markers (TODOs, FIXMEs)
Output
Present findings to user:
- Code structure summary
- Identified problem areas
- Initial recommendations
- Request approval to proceed
Phase 2: Test Coverage Assessment
Why Tests Matter
"Refactoring without tests is like driving without a seatbelt." — Martin Fowler
Tests are the key enabler of safe refactoring. Without them, you risk introducing bugs.
Assessment Steps
Check for existing tests
# Look for test files find . -name "*test*" -o -name "*spec*" | head -20Run existing tests
# JavaScript/TypeScript npm test # Python pytest -v # Java mvn testCheck coverage (if available)
# JavaScript npm run test:coverage # Python pytest --cov=.
Decision Point: Ask User
If tests exist and pass:
- Proceed to Phase 3
If tests are missing or incomplete: Present options:
- Write tests first (recommended)
- Add tests incrementally during refactoring
- Proceed without tests (risky - requires user acknowledgment)
If tests are failing:
- STOP. Fix failing tests before refactoring
- Ask user: Should we fix tests first?
Test Writing Guidelines (if needed)
For each function being refactored, ensure tests cover:
- Happy path (normal operation)
- Edge cases (empty inputs, null, boundaries)
- Error scenarios (invalid inputs, exceptions)
Use the "red-green-refactor" cycle:
- Write failing test (red)
- Make it pass (green)
- Refactor
Phase 3: Code Smell Identification
What Are Code Smells?
Symptoms of deeper problems in code. They're not bugs, but indicators that the code could be improved.
Common Code Smells to Check
See references/code-smells.md for the complete catalog.
Quick Reference
| Smell | Signs | Impact |
|---|---|---|
| Long Method | Methods > 30-50 lines | Hard to understand, test, maintain |
| Duplicated Code | Same logic in multiple places | Bug fixes needed in multiple places |
| Large Class | Class with too many responsibilities | Violates Single Responsibility |
| Feature Envy | Method uses another class's data more | Poor encapsulation |
| Primitive Obsession | Overuse of primitives instead of objects | Missing domain concepts |
| Long Parameter List | Methods with 4+ parameters | Hard to call correctly |
| Data Clumps | Same data items appearing together | Missing abstraction |
| Switch Statements | Complex switch/if-else chains | Hard to extend |
| Speculative Generality | Code "just in case" | Unnecessary complexity |
| Dead Code | Unused code | Confusion, maintenance burden |
Analysis Steps
- **Automated
자주 묻는 질문
동작이 바뀌나요?
스킬에 따르면 동작은 그대로 유지되어야 하므로, 리팩터링은 내부 구조만 바꿉니다.
테스트가 필요한가요?
스킬은 먼저 테스트 범위를 평가하고, 각 변경의 안전망으로 테스트를 사용합니다.
묻지 않고 코드를 바꾸나요?
아니요. 스킬은 각 단계마다 사용자의 승인이 필요하다고 말합니다.
상세 정보
작성자의 원본 설명
Systematic code refactoring based on Martin Fowler's methodology. Use when users ask to refactor code, improve code structure, reduce technical debt, clean up legacy code, eliminate code smells, or improve code maintainability. This skill guides through a phased approach with research, planning, and safe incremental implementation.
repo: luongnv89/claude-howto
인기도
- GitHub 스타
- 46k
- 순위
- #6324
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
lesson-quiz
46kClaude Code 튜토리얼의 강의 하나에 대해 10개 문항의 퀴즈를 내고, 답을 채점하며, 다시 볼 주제를 짚어 줍니다.
self-assessment
46kClaude Code의 10개 기능 영역에 대한 퀴즈를 내고, 주제별 점수와 다음에 공부할 학습 경로를 보여 줍니다.
blog-draft
46k아이디어와 자료를 바탕으로 블로그 글 초안을 단계별로 작성하도록 안내하며, 버전을 함께 추적합니다.
claude-md
46k에이전트가 프로젝트를 AI 에이전트에 소개하는 CLAUDE.md 파일을 만들거나 개선하도록 돕습니다.