Fowler-Style Refactoring
lhfer/claude-howto-zh-cn
基于 Martin Fowler 方法论做系统化重构。Use when users ask to refactor code, improve structure, reduce technical debt, clean up legacy code, or improve maintainability.
Guides systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes with your approval at each phase.
SKILL.md written in Ukrainian; this summary is our English description.
$ npx skills add luongnv89/claude-howto --skill refactor -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install luongnv89/claude-howto refactor --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/luongnv89/claude-howto.git skills-src && mkdir -p .claude/skills && cp -r skills-src/uk/03-skills/refactor .claude/skills/refactor && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "refactor" agent skill from https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactor into .claude/skills/refactor/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactorType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add luongnv89/claude-howto --skill refactor -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install luongnv89/claude-howto refactor --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/luongnv89/claude-howto.git skills-src && mkdir -p .agents/skills && cp -r skills-src/uk/03-skills/refactor .agents/skills/refactor && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "refactor" agent skill from https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactor into .agents/skills/refactor/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add luongnv89/claude-howto --skill refactor -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install luongnv89/claude-howto refactor --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/luongnv89/claude-howto.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/uk/03-skills/refactor .cursor/skills/refactor && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "refactor" agent skill from https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactor into .cursor/skills/refactor/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/luongnv89/claude-howto.git --path uk/03-skills/refactor--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add luongnv89/claude-howto --skill refactor -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install luongnv89/claude-howto refactor --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/luongnv89/claude-howto.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/uk/03-skills/refactor .gemini/skills/refactor && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "refactor" agent skill from https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactor into .gemini/skills/refactor/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install luongnv89/claude-howto refactorInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add luongnv89/claude-howto --skill refactor -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/luongnv89/claude-howto.git skills-src && mkdir -p .github/skills && cp -r skills-src/uk/03-skills/refactor .github/skills/refactor && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "refactor" agent skill from https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactor into .github/skills/refactor/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add luongnv89/claude-howto --skill refactor -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install luongnv89/claude-howto refactor --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/luongnv89/claude-howto.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/uk/03-skills/refactor .opencode/skills/refactor && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "refactor" agent skill from https://github.com/luongnv89/claude-howto/tree/main/uk/03-skills/refactor into .opencode/skills/refactor/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
refactorGuides systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes with your approval at each phase.
The skill is written in Ukrainian and applies the approach from Fowler's book Refactoring: Improving the Design of Existing Code (second edition). Its principles are preserving external behavior, taking small steps, treating tests as a safety net, refactoring as a continuous process rather than a one-off event, and getting the user's approval at every phase.
The first phase is research and analysis. The agent asks about scope, goals, constraints, deadline pressure and test status, reads the target code, maps dependencies, documents the current architecture and notes technical-debt markers such as TODOs and FIXMEs, then presents its findings and asks for approval. The second phase assesses test coverage by finding and running the existing tests and checking coverage where it is available, and then asks you how to proceed depending on whether tests exist and pass.
The folder also ships code-smell and refactoring-catalog references, two Python scripts named analyze-complexity.py and detect-smells.py, and a refactoring-plan template.
5 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit 556af8d. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Ships 2 files in scripts/ (Python), which the agent can run.
Shell commands in SKILL.md call:
npmpytestpythonmvnFrom the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md. Its commands use npm, which can reach the network depending on how they are called.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Code Refactoring Workflow loads about 3.1k tokens when it runs, and up to ~17k if it reads all its reference files. Until then it costs about 99 tokens; SKILL.md has 1,200 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.
The full file from luongnv89/claude-howto at commit 556af8d, republished under its MIT licence (© luongnv89). 1,200 words, ~3,089 tokens.
.claude/skills/refactor/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.Систематичний підхід до рефакторингу коду на основі книги Мартіна Фаулера Refactoring: Improving the Design of Existing Code (2-ге видання). Ця навичка наголошує на безпечних, інкрементальних змінах, підкріплених тестами.
«Рефакторинг — це процес зміни програмної системи таким чином, що не змінює зовнішню поведінку коду, але покращує його внутрішню структуру.» — Мартін Фаулер
Фаза 1: Дослідження та аналіз
↓
Фаза 2: Оцінка покриття тестами
↓
Фаза 3: Виявлення запахів коду
↓
Фаза 4: Створення плану рефакторингу
↓
Фаза 5: Інкрементальна реалізація
↓
Фаза 6: Перегляд та ітераціяПеред початком уточніть:
Представити знахідки користувачу:
«Рефакторинг без тестів — як їзда без пасків безпеки.» — Мартін Фаулер
Тести — ключовий засіб безпечного рефакторингу. Без них ви ризикуєте внести помилки.
Перевірити наявні тести
# Пошук файлів тестів
find . -name "*test*" -o -name "*spec*" | head -20Запустити існуючі тести
# JavaScript/TypeScript
npm test
# Python
pytest -v
# Java
mvn testПеревірити покриття (якщо доступно)
# JavaScript
npm run test:coverage
# Python
pytest --cov=.Якщо тести існують та проходять:
Якщо тести відсутні або неповні: Представити варіанти:
Якщо тести не проходять:
Для кожної функції, що рефакториться, забезпечити тести для:
Використовуйте цикл «red-green-refactor»:
Симптоми глибших проблем у коді. Це не помилки, а індикатори того, що код можна покращити.
Див. references/code-smells.md для повного каталогу.
| Запах | Ознаки | Вплив |
|---|---|---|
| Довгий метод | Методи > 30-50 рядків | Важко зрозуміти, тестувати, супроводжувати |
| Дубльований код | Та сама логіка в кількох місцях | Виправлення помилок потрібне в кількох місцях |
| Великий клас | Клас з занадто багатьма відповідальностями | Порушує принцип єдиної відповідальності |
| Заздрість до функцій | Метод використовує дані іншого класу більше | Погана інкапсуляція |
| Одержимість примітивами | Надмірне використання примітивів замість обʼєктів | Відсутні доменні концепції |
| Довгий список параметрів | Методи з 4+ параметрами | Складно викликати правильно |
| Групи даних | Ті самі елементи даних зʼявляються разом | Відсутня абстракція |
| Оператори Switch | Складні ланцюжки switch/if-else | Важко розширювати |
| Спекулятивна загальність | Код «на всякий випадок» | Зайва складність |
| Мертвий код | Невикористаний код | Плутанина, тягар супровідності |
Автоматичний аналіз (якщо скрипти доступні)
python scripts/detect-smells.py <file>Ручний перегляд
Пріоритезація Зосередитися на запахах, які:
Представити користувачу:
Для кожного запаху обрати відповідний рефакторинг з каталогу.
Див. references/refactoring-catalog.md для повного списку.
| Запах коду | Рекомендований рефакторинг |
|---|---|
| Long Method | Extract Method, Replace Temp with Query |
| Duplicated Code | Extract Method, Pull Up Method, Form Template Method |
| Large Class | Extract Class, Extract Subclass |
| Feature Envy | Move Method, Move Field |
| Primitive Obsession | Replace Primitive with Object, Replace Type Code with Class |
| Long Parameter List | Introduce Parameter Object, Preserve Whole Object |
| Data Clumps | Extract Class, Introduce Parameter Object |
| Switch Statements | Replace Conditional with Polymorphism |
| Speculative Generality | Collapse Hierarchy, Inline Class, Remove Dead Code |
| Dead Code | Remove Dead Code |
Використовуйте шаблон templates/refactoring-plan.md.
Для кожного рефакторингу:
КРИТИЧНО: Впроваджуйте рефакторинг поступово, фазами.
Фаза A: Швидкі перемоги (Низький ризик, висока цінність)
Фаза B: Структурні покращення (Середній ризик)
Фаза C: Архітектурні зміни (Вищий ризик)
Перед реалізацією:
«Зміна → Тест → Зелений? → Коміт → Наступний крок»
Для кожного кроку рефакторингу:
Попередня перевірка
Зробити ОДНУ малу зміну
Верифікація
Якщо тести проходять (зелені)
Якщо тести не проходять (червоні)
Кожен коміт має бути:
Приклади повідомлень комітів:
refactor: Extract calculateTotal() from processOrder()
refactor: Rename 'x' to 'customerCount' for clarity
refactor: Remove unused validateOldFormat() methodПісля кожної підфази звітувати користувачу:
Запустити аналіз складності до і після:
python scripts/analyze-complexity.py <file>Представити покращення:
Представити фінальні результати:
Обговорити з користувачем:
Завжди паузу та консультацію з користувачем, коли:
До:
function processOrder(order) {
// 150 рядків коду з:
// - Дубльованою логікою валідації
// - Інлайн-обчисленнями
// - Змішаними відповідальностями
}Кроки рефакторингу:
Після:
function processOrder(order) {
validateOrder(order);
const total = calculateOrderTotal(order);
notifyCustomer(order, total);
return { order, total };
}scripts/analyze-complexity.py — аналіз метрик складності кодуscripts/detect-smells.py — автоматичне виявлення запахів© luongnv89, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
SKILL.md and 5 other files (scripts, references) in uk/03-skills/refactor of luongnv89/claude-howto.
Open the folder on GitHubat commit 556af8d
Code Refactoring Workflow next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Code Refactoring Workflow this skillluongnv89/claude-howto | 42k | — | ~3.1k | Automated safety check: Pass | MIT | |
| Fowler-Style Refactoringlhfer/claude-howto-zh-cn | 2.3k | — | ~156 | Automated safety check: Pass | MIT | |
| Architecture Optimizationwondelai/skills | 2.4k | — | ~7.4k | Automated safety check: Pass | MIT | |
| Improve Code Qualitywondelai/skills | 2.4k | — | ~6.2k | Automated safety check: Pass | MIT | |
| Tech Debt Analyzerailabs-393/ai-labs-claude-skills | 454 | 2 repos | ~3.9k | Automated safety check: Pass | MIT | |
| FIXME Resolvertailcallhq/forgecode | 7.6k | — | ~1.1k | Automated safety check: Pass | Apache-2.0 |
lhfer/claude-howto-zh-cn
基于 Martin Fowler 方法论做系统化重构。Use when users ask to refactor code, improve structure, reduce technical debt, clean up legacy code, or improve maintainability.
wondelai/skills
Guided journey from a working codebase grown slow and tangled to one measurably fast, cleanly bounded, and readable.
wondelai/skills
Guided journey from a working-but-untested vibe-coded prototype to a production-ready product with tests, clean structure, a business-rules boundary, and resilience at scale.
ailabs-393/ai-labs-claude-skills
This skill should be used when analyzing technical debt in a codebase, documenting code quality issues, creating technical debt registers, or assessing code maintainability.
tailcallhq/forgecode
Finds every FIXME comment in a codebase, groups related ones across files into one task, implements the work they describe and removes the comments once it is done.
Git-on-my-level/codex-autorunner
Codebase health scanner and technical debt tracker. An agent skill from Git-on-my-level/codex-autorunner.
luongnv89/claude-howto
Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.
luongnv89/claude-howto
Guides drafting a blog post from an idea and optional source material: research, brainstorming, outlining and version-tracked drafts, with user approval at each step.
luongnv89/claude-howto
Ensure all communication matches brand voice and tone guidelines. Use when creating marketing copy, customer communications, public-facing content, or when…
luongnv89/claude-howto
Reviews code for security, performance, quality and maintainability, using a checklist, a finding template and two metrics scripts.
luongnv89/claude-howto
Runs a quick or deep quiz on Claude Code skills, scores ten feature areas and generates a personalized learning path with prioritized next steps.
luongnv89/claude-howto
Quizzes a learner on one lesson of the Claude Code tutorial with ten questions, scores the answers and points out weak spots.
Categories
Guides systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes with your approval at each phase. The skill is written in Ukrainian and applies the approach from Fowler's book Refactoring: Improving the Design of Existing Code (second edition). Its principles are preserving external behavior, taking small steps, treating tests as a safety net, refactoring as a continuous process rather than a one-off event, and getting the user's approval at every phase.
Code Refactoring Workflow fits situations like: restructuring a messy module without changing its behavior; reducing technical debt or cleaning up legacy code; finding and removing code smells in a codebase.
Run `npx skills add luongnv89/claude-howto --skill refactor -a claude-code`. Or copy the skill folder (uk/03-skills/refactor in luongnv89/claude-howto) into .claude/skills/refactor in your project. Claude Code loads it when a task matches its description.
Run `npx skills add luongnv89/claude-howto --skill refactor -a codex`. Or copy the skill folder (uk/03-skills/refactor in luongnv89/claude-howto) into .agents/skills/refactor in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add luongnv89/claude-howto --skill refactor -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/refactor, .gemini/skills/refactor, .github/skills/refactor and .opencode/skills/refactor in your project.
Going by SKILL.md and its folder, Code Refactoring Workflow needs Python for the scripts in its folder and the command-line tools its instructions call (npm, pytest, python and mvn). Our summary lists: A way to run the project's tests, such as npm test; Python for the bundled analysis scripts.
SKILL.md contains no URLs. Its commands use npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.
Code Refactoring Workflow is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 3.1k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 14k tokens, read only when the agent opens those files.
Skills that share tags, products or a category with Code Refactoring Workflow: Fowler-Style Refactoring (lhfer/claude-howto-zh-cn, 2.3k stars), Architecture Optimization (wondelai/skills, 2.4k stars), Improve Code Quality (wondelai/skills, 2.4k stars) and Tech Debt Analyzer (ailabs-393/ai-labs-claude-skills, 454 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
luongnv89 (a GitHub user) maintains it in luongnv89/claude-howto, which has 41,764 GitHub stars. The repository holds 25 skills in this directory. The repository was last updated on September 30, 2026.
Source: luongnv89/claude-howto on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.