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.
Vietnamese edition of a systematic refactoring skill based on Martin Fowler's book, working in approved phases with small, test-backed changes.
SKILL.md written in Vietnamese; 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/vi/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/vi/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/vi/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/vi/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/vi/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/vi/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/vi/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 vi/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/vi/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/vi/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/vi/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/vi/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/vi/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/vi/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.
refactorVietnamese edition of a systematic refactoring skill based on Martin Fowler's book, working in approved phases with small, test-backed changes.
The text is in Vietnamese and builds on the second edition of Fowler's Refactoring. Its principles are preserving external behavior, taking small testable steps, relying on tests as the safety net, treating refactoring as continuous, and getting your approval at every phase. A workflow diagram lists the phases, and the description adds planning and safe incremental implementation after the research stage.
Phase one gathers context by asking about scope, goals such as readability, performance or maintainability, constraints on areas that must not change, time pressure and the state of the tests, then reads the target code, maps dependencies, documents the current architecture and notes TODO and FIXME markers, and ends by presenting findings and asking for approval. Phase two checks test coverage: it finds and runs existing tests, checks coverage where available, and treats missing tests as a risk.
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.
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.
Refactoring Skill (Vietnamese) loads about 3.1k tokens when it runs. Until then it costs about 90 tokens; SKILL.md has 1,800 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); files beside SKILL.md are not scanned.
The full file from luongnv89/claude-howto at commit 556af8d, republished under its MIT licence (© luongnv89). 1,800 words, ~3,089 tokens.
.claude/skills/refactor/SKILL.md (or your agent's skills folder).Một cách tiếp có hệ thống để refactor code dựa trên Refactoring: Improving the Design of Existing Code (ấn bản 2) của Martin Fowler. Skill này nhấn mạnh các thay đổi tăng dần, an toàn được hỗ trợ bởi tests.
"Refactoring là quá trình thay đổi một hệ thống phần mềm theo cách mà nó không làm thay đổi hành vi bên ngoài của code nhưng cải thiện cấu trúc nội bộ của nó." — Martin Fowler
Giai Đoạn 1: Nghiên Cứu & Phân Tích
↓
Giai Đoạn 2: Đánh Giá Phủ Vùng Test
↓
Giai Đoạn 3: Xác Định Code Smell
↓
Giai Đoạn 4: Tạo Kế Hoạch Refactoring
↓
Giai Đoạn 5: Triển Khai Tăng Dần
↓
Giai Đoạn 6: Review & Lặp LạiTrước khi bắt đầu, làm rõ:
Trình bày phát hiện cho người dùng:
"Refactoring mà không có tests giống như lái xe mà không có thắt dây an toàn." — Martin Fowler
Tests là bật dụng chính của refactoring an toàn. Không có chúng, bạn có nguy cơ giới thiệu bugs.
Kiểm tra các test hiện có
# Tìm các file test
find . -name "*test*" -o -name "*spec*" | head -20Chạy các test hiện có
# JavaScript/TypeScript
npm test
# Python
pytest -v
# Java
mvn testKiểm tra phủ vùng (nếu có)
# JavaScript
npm run test:coverage
# Python
pytest --cov=.Nếu tests tồn tại và pass:
Nếu tests bị thiếu hoặc không hoàn chỉnh: Trình bày các tùy chọn:
Nếu tests đang fail:
Đối với mỗi hàm được refactor, đảm bảo tests bao phủ:
Sử dụng chu trình "red-green-refactor":
Các triệu chứng của các vấn đề sâu hơn trong code. Chúng không phải là bugs, nhưng là các chỉ báo rằng code có thể được cải thiện.
Xem references/code-smells.md để có danh sách đầy đủ.
| Smell | Dấu Hiệu | Tác Động |
|---|---|---|
| Long Method | Methods > 30-50 dòng | Khó hiểu, test, duy trì |
| Duplicated Code | Cùng logic ở nhiều nơi | Cần sửa lỗi ở nhiều nơi |
| Large Class | Class với quá nhiều trách nhiệm | Vi phạm Single Responsibility |
| Feature Envy | Method sử dụng dữ liệu class khác nhiều | Đóng gói kém |
| Primitive Obsession | Lạm dụng primitives thay vì objects | Thiếu các khái niệm domain |
| Long Parameter List | Methods với 4+ parameters | Khó gọi đúng |
| Data Clumps | Cùng dữ liệu xuất hiện cùng nhau | Thiếu abstraction |
| Switch Statements | Switch/if-else chains phức tạp | Khó mở rộng |
| Speculative Generality | Code "trường hợp" | Độ phức tạp không cần thiết |
| Dead Code | Code không sử dụng | Nhầm lẫn, gánh nặng duy trì |
Phân Tích Tự Động (nếu scripts có sẵn)
python scripts/detect-smells.py <file>Review Thủ Công
Ưu Tiên Tập trung vào các smells mà:
Trình bày cho người dùng:
Đối với mỗi smell, chọn một refactoring phù hợp từ catalog.
Xem references/refactoring-catalog.md để có danh sách đầy đủ.
| Code Smell | Refactoring Khuyến Nghị |
|---|---|
| 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 |
Sử dụng mẫu tại templates/refactoring-plan.md.
Đối với mỗi refactoring:
QUAN TRỌNG: Introduce refactoring tăng dần theo các giai đoạn.
Giai Đoạn A: Quick Wins (Rủi ro thấp, giá trị cao)
Giai Đoạn B: Cải Tiến Cấu Trúc (Rủi ro trung bình)
Giai Đoạn C: Thay Đổi Kiến Trúc (Rủi ro cao hơn)
Trước khi triển khai:
"Thay Đổi → Test → Xanh? → Commit → Bước tiếp theo"
Đối với mỗi bước refactoring:
Kiểm tra trước
Thực hiện MỘT thay đổi nhỏ
Xác Minh
Nếu tests pass (xanh)
Nếu tests fail (đỏ)
Mỗi commit nên là:
Ví dụ thông điệp commit:
refactor: Extract calculateTotal() from processOrder()
refactor: Rename 'x' to 'customerCount' for clarity
refactor: Remove unused validateOldFormat() methodSau mỗi sub-giai đoạn, báo cáo cho người dùng:
Chạy phân tích độ phức tạp trước và sau:
python scripts/analyze-complexity.py <file>Trình bày cải tiến:
Trình bày kết quả cuối cùng:
Thảo luận với người dùng:
Luôn dừng lại và tham khảo người dùng khi:
Trước:
function processOrder(order) {
// 150 dòng code với:
// - Logic xác thực trùng lặp
// - Tính toán nội tuyến
// - Trách nhiệm hỗn hợp
}Các Bước Refactoring:
Sau:
function processOrder(order) {
validateOrder(order);
const total = calculateOrderTotal(order);
notifyCustomer(order, total);
return { order, total };
}scripts/analyze-complexity.py - Phân tích metrics độ phức tạp codescripts/detect-smells.py - Phát hiện smell tự động© luongnv89, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in vi/03-skills/refactor of luongnv89/claude-howto.
Open the folder on GitHubat commit 556af8d
Refactoring Skill (Vietnamese) 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 |
|---|---|---|---|---|---|---|
| Refactoring Skill (Vietnamese) 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 systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes 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.
Categories
Vietnamese edition of a systematic refactoring skill based on Martin Fowler's book, working in approved phases with small, test-backed changes. The text is in Vietnamese and builds on the second edition of Fowler's Refactoring. Its principles are preserving external behavior, taking small testable steps, relying on tests as the safety net, treating refactoring as continuous, and getting your approval at every phase.
Refactoring Skill (Vietnamese) fits situations like: restructuring messy code without changing its behavior; reducing technical debt or cleaning up legacy modules; removing code smells under test protection.
Run `npx skills add luongnv89/claude-howto --skill refactor -a claude-code`. Or copy the skill folder (vi/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 (vi/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, Refactoring Skill (Vietnamese) needs the command-line tools its instructions call (npm, pytest, python and mvn).
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. Review the folder before installing.
Refactoring Skill (Vietnamese) 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.
Skills that share tags, products or a category with Refactoring Skill (Vietnamese): 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,769 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.