Code Refactoring Workflow
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.
A skill your agent uses when planning a multi-file refactor, code modernization, or technical debt resolution.
$ npx skills add WrongStack/WrongStack --skill refactor-planner -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install WrongStack/WrongStack refactor-planner --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/WrongStack/WrongStack.git skills-src && mkdir -p .claude/skills && cp -r skills-src/packages/core/skills/refactor-planner .claude/skills/refactor-planner && 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-planner" agent skill from https://github.com/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-planner into .claude/skills/refactor-planner/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor-planner", 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/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-plannerType 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 WrongStack/WrongStack --skill refactor-planner -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install WrongStack/WrongStack refactor-planner --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/WrongStack/WrongStack.git skills-src && mkdir -p .agents/skills && cp -r skills-src/packages/core/skills/refactor-planner .agents/skills/refactor-planner && 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-planner" agent skill from https://github.com/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-planner into .agents/skills/refactor-planner/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor-planner", 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 WrongStack/WrongStack --skill refactor-planner -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install WrongStack/WrongStack refactor-planner --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/WrongStack/WrongStack.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/packages/core/skills/refactor-planner .cursor/skills/refactor-planner && 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-planner" agent skill from https://github.com/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-planner into .cursor/skills/refactor-planner/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor-planner", 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/WrongStack/WrongStack.git --path packages/core/skills/refactor-planner--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 WrongStack/WrongStack --skill refactor-planner -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install WrongStack/WrongStack refactor-planner --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/WrongStack/WrongStack.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/packages/core/skills/refactor-planner .gemini/skills/refactor-planner && 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-planner" agent skill from https://github.com/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-planner into .gemini/skills/refactor-planner/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor-planner", 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 WrongStack/WrongStack refactor-plannerInstalls 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 WrongStack/WrongStack --skill refactor-planner -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/WrongStack/WrongStack.git skills-src && mkdir -p .github/skills && cp -r skills-src/packages/core/skills/refactor-planner .github/skills/refactor-planner && 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-planner" agent skill from https://github.com/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-planner into .github/skills/refactor-planner/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor-planner", 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 WrongStack/WrongStack --skill refactor-planner -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install WrongStack/WrongStack refactor-planner --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/WrongStack/WrongStack.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/packages/core/skills/refactor-planner .opencode/skills/refactor-planner && 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-planner" agent skill from https://github.com/WrongStack/WrongStack/tree/main/packages/core/skills/refactor-planner into .opencode/skills/refactor-planner/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "refactor-planner", 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.
refactor-plannerA skill your agent uses when planning a multi-file refactor, code modernization, or technical debt resolution.
Refactor Planner is an agent skill from WrongStack/WrongStack. Use this skill when planning a multi-file refactor, code modernization, or technical debt resolution. Trigger on the explicit vocabulary — "refactor", "technical debt", "modernize", "clean up", "restructure", "decompose" — and on the task shape, which is how it usually arrives: "this file is 2000 lines", "split this up", "extract X into its own module", "there's a circular dependency", "migrate from X to Y", "this is getting unmaintainable", "everything imports everything". This skill produces a phased PLAN with…
Its SKILL.md is about 3.3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 1 other file (for example `SKILL.save.md`).
It sits in Development, covering Refactoring, Technical debt and Legacy modernization. The repository describes itself as: An AI coding agent that reads your code, edits files, runs commands, and reasons through bugs — across a terminal REPL, a full-screen TUI, and a browser UI, while you keep your… The licence is MIT.
6 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit 57f6018. 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:
pnpmgitFrom the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md. Its commands use pnpm and git, 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.
Refactor Planner loads about 3.3k tokens when it runs. Until then it costs about 179 tokens; SKILL.md has 1,438 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 WrongStack/WrongStack at commit 57f6018, republished under its MIT licence (© WrongStack). 1,438 words, ~3,290 tokens.
.claude/skills/refactor-planner/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.Analyzes code structure and produces a phased refactoring plan with risk assessment, dependency ordering, and rollback strategy. Use for multi-file refactors, breaking up large modules, changing public APIs, addressing technical debt, or migrating to new patterns.
This skill plans; it does not execute. The deliverable is the phased plan. Do not start editing modules while planning — a half-done refactor with no graph behind it is the exact failure this skill exists to prevent. Hand the finished plan to the executing agent, phase by phase.
1. Analyze: Build dependency graph, identify coupling
2. Score: Rate each module by size, complexity, test coverage
3. Plan: Order tasks by risk, dependency, payoff
4. Document: Phased markdown plan with checkpointsRule 1 and the anti-pattern list both call this the most important part, so do it from evidence, not from intuition.
Derive it from the code. When the codebase index is available, the
codebase-impact-analysis tool returns a symbol's production callers and affected
tests, the codebase-incoming-calls and codebase-outgoing-calls tools give both
edge directions, and the codebase-repo-map tool shows which files are hubs.
Without the index, grep the actual import / require / from
statements across the target set. Directory layout, file naming, and the mental
model in someone's head all lie; the import statements don't.
Arrow convention: A → B means A depends on B. B is the leaf. This is the
one thing the graph must be unambiguous about, because it decides the entire
ordering.
Refactor leaves first, right to left. Changing a leaf ripples up to its dependents, so a leaf changed late invalidates everything already done above it. In this graph:
config.ts → logger.ts → path-resolver.ts
↓ ↓
secret-vault.ts session-store.ts
↓ ↓
└────────→ agent.ts ←←←path-resolver.ts is safe to touch first; config.ts is the most expensive.
Also record the reverse edges. Fan-out (what a module imports) drives its own risk; the dependents list (who imports it) drives blast radius. Both belong in the score — a 40-line file imported by twelve modules is riskier to change than a 600-line file nobody imports.
A cycle means there is no valid ordering, so every plan built over one is fictional. Find cycles during the analyze step and list them explicitly. Breaking them is Phase 1 work even when it looks like Phase 2 work, because nothing downstream can be sequenced until they're gone.
Typical breaks: extract the shared piece into a new leaf both sides import, invert one direction with an interface or callback, or move the coupling into a composition root that wires both.
| Factor | Low Risk | Medium Risk | High Risk |
|---|---|---|---|
| Cyclomatic complexity | <10 | 10-20 | >20 |
| Test coverage | >80% | 50-80% | <50% |
| Fan-out (imports) | <5 | 5-15 | >15 |
| Public API surface | unchanged | modified | removed |
Score every module in scope; the mix of factors, not any single one, sets the phase. A high-complexity module with 90% coverage is safer to change than a simple one with none — the tests are what tell you the refactor preserved behavior.
One record per module in scope:
{
"module": "src/auth/session.ts",
"size": 450,
"cyclomatic": 12,
"testCoverage": 65,
"fanOut": 8,
"publicAPI": true,
"dependencies": ["core", "providers"],
"dependents": ["cli", "tui", "webui"]
}A refactor is only safe to the degree that something can tell you behavior didn't change. When a module scores <50% coverage, its first Phase 1 task is writing characterization tests — tests that pin down what the code does today, bugs included, before anything moves. This isn't scope creep; without it every later phase is unverifiable and the rollback strategy is the only safety net left.
Good refactors have 3 phases:
Phase 1: Low Risk / High Payoff
- No behavior change
- Tests already pass
- Quick wins
Phase 2: Medium Risk (test heavily)
- Some behavior may change
- Significant test coverage needed
- May need rollback plan
Phase 3: High Risk (full regression)
- Behavior changes expected
- Integration tests required
- Coordinate with teamTwo notes on using this well:
Estimate from fan-out and coverage, not from line count — a small change in a
widely-imported module costs more than a large one in a leaf. Keep the <1h merge
rule (rule 4). Mark anything you're guessing at with a ? rather than inventing
false precision; an honest range beats a confident wrong number when someone
schedules against it.
// ✅ Good — graph derived from imports, direction stated, cycles named
// A → B means A imports B. Refactor right to left.
// CYCLE: config.ts ↔ logger.ts — break before sequencing anything else.// ✅ Good — phase boundary is a real checkpoint
// End of Phase 1: pnpm test green, no circular deps in src/core, mergeable.// ❌ Bad — no dependency graph
// "Refactor the auth layer" — with no graph, order is guessed
// ❌ Bad — no rollback strategy
// "We'll figure it out if something breaks" — plan for failure
// ❌ Bad — unverifiable exit criterion
// "Code is cleaner and easier to maintain" — nothing to checkEvery phase needs one, and it has to match the phase's risk:
git checkout if tests fail.The test of a rollback plan is whether someone who wasn't in the planning session could execute it under pressure. "Revert the commits" is a plan only if the commits are actually separable.
Make each one mechanically checkable — a command that exits zero, or a number that can be measured. "Code is cleaner" is not an exit criterion, and a phase without a checkable exit never formally ends.
✅ pnpm test passes; no circular deps in src/core; Context interface < 20 methods
❌ Code is more maintainable; the module is better factored; complexity reduced
## Refactor Plan — <target>
### Phase 1: Low Risk / High Payoff
| # | Task | Module | Risk | Est. Time |
|---|------|--------|------|-----------|
| 1 | Extract `ToolExecutor` interface | core/tool-executor.ts | low | 2h |
| 2 | Decouple `SessionStore` from Agent | core/session-store.ts | low | 4h |
### Phase 2: Medium Risk (test heavily)
| # | Task | Module | Risk | Est. Time |
|---|------|--------|------|-----------|
| 3 | Break circular dep: Config ↔ Logger | core/config.ts | medium | 6h |
### Dependency Graph
```
config.ts → logger.ts → path-resolver.ts
↓ ↓
secret-vault.ts session-store.ts
↓ ↓
└────────→ agent.ts ←←←
```
### Rollback Strategy
- Phase 1: `git checkout` if tests fail
- Phase 2: Feature flag, can disable
- Phase 3: Blue-green deployment
### Exit Criteria
- [ ] All Phase 1 tasks pass `pnpm test`
- [ ] No circular deps in `src/core`
- [ ] `Context` interface < 20 methods
<nextsteps>
1. Extract ToolExecutor interface in core/tool-executor.ts
2. Decouple SessionStore from Agent in core/session-store.ts
3. Break circular dep between Config and Logger in core/config.ts
</nextsteps>State the arrow convention alongside the graph, and if any cycles exist, list them directly under it — a reader who assumes the arrows point the other way will execute the plan backwards.
Above roughly 15 modules, scoring and graphing serially burns the session before
the plan exists. Hand the analysis to the multi-agent fan-out pattern: one
worker per chunk of 5–10 modules, each returning the same risk-assessment JSON
shape, leader merges them into one graph. Read that skill for sizing and
briefing rules first. The planning stays with the leader — only the measurement
parallelizes.
import statements, not from directory layout or someone's mental model.pnpm test passes is. If a phase has no checkable exit, it never formally ends.bug-hunter — for finding bugs exposed by the refactorgit-flow — for committing each phase properlymulti-agent — for parallel analysis of multiple modulesoutput-standards — for standardized <nextsteps> formatting© WrongStack, 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 1 other file in packages/core/skills/refactor-planner of WrongStack/WrongStack.
Open the folder on GitHubat commit 57f6018
Refactor Planner 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 |
|---|---|---|---|---|---|---|
| Refactor Planner this skillWrongStack/WrongStack | 370 | — | ~3.3k | Automated safety check: Pass | MIT | |
| Code Refactoring Workflowluongnv89/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 | |
| Refactoring Skill (Vietnamese)luongnv89/claude-howto | 42k | — | ~3.1k | Automated safety check: Pass | MIT | |
| Legacy ModernizerJeffallan/claude-skills | 12k | — | ~1.6k | Automated safety check: Pass | MIT | |
| Moai Workflow Dddmodu-ai/moai-adk | 1.2k | — | ~3.6k | Automated safety check: Pass | Apache-2.0 |
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.
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.
luongnv89/claude-howto
Vietnamese edition of a systematic refactoring skill based on Martin Fowler's book, working in approved phases with small, test-backed changes.
Jeffallan/claude-skills
Plans incremental migrations of aging systems with the strangler fig pattern, using dependency maps, rollback plans, characterization tests and gradual traffic shifts.
modu-ai/moai-adk
Domain-Driven Development workflow specialist using ANALYZE-PRESERVE-IMPROVE cycle for behavior-preserving code transformation.
wondelai/skills
Guided journey from a working codebase grown slow and tangled to one measurably fast, cleanly bounded, and readable.
WrongStack/WrongStack
Design or substantially improve user-facing interfaces with a product-specific visual direction, content hierarchy, and rendered critique.
WrongStack/WrongStack
A skill your agent uses to audit an interface that already exists and say precisely why it looks generated, templated, or unfinished — a scored rubric across composition, typography, color, states…
WrongStack/WrongStack
A skill your agent uses when external coding agents (Claude Code, Aider, custom scripts) need to participate in the project's shared WrongStack mailbox, or when a user asks to "expose the mailbox"…
WrongStack/WrongStack
A skill your agent uses whenever work can be split across multiple AI agents running in parallel, or when orchestrating leader/worker patterns in WrongStack.
WrongStack/WrongStack
Use this skill before asserting that a CSS, HTML or accessibility capability is available, unavailable, or the right tool — it carries dated, refreshable platform facts and refuses to let stale…
WrongStack/WrongStack
A skill your agent uses when the user wants to communicate with WrongStack's shared project mailbox from outside WrongStack — read messages sent by WrongStack agents, send replies, broadcast to all…
Categories
A skill your agent uses when planning a multi-file refactor, code modernization, or technical debt resolution. Refactor Planner is an agent skill from WrongStack/WrongStack. Use this skill when planning a multi-file refactor, code modernization, or technical debt resolution.
Refactor Planner fits situations like: planning a multi-file refactor; code modernization; technical debt resolution; the explicit vocabulary — refactor.
Run `npx skills add WrongStack/WrongStack --skill refactor-planner -a claude-code`. Or copy the skill folder (packages/core/skills/refactor-planner in WrongStack/WrongStack) into .claude/skills/refactor-planner in your project. Claude Code loads it when a task matches its description.
Run `npx skills add WrongStack/WrongStack --skill refactor-planner -a codex`. Or copy the skill folder (packages/core/skills/refactor-planner in WrongStack/WrongStack) into .agents/skills/refactor-planner 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 WrongStack/WrongStack --skill refactor-planner -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-planner, .gemini/skills/refactor-planner, .github/skills/refactor-planner and .opencode/skills/refactor-planner in your project.
Going by SKILL.md and its folder, Refactor Planner needs the command-line tools its instructions call (pnpm and git).
SKILL.md contains no URLs. Its commands use git, 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.
Refactor Planner 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.3k tokens (SKILL.md is roughly 13k 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 Refactor Planner: Code Refactoring Workflow (luongnv89/claude-howto, 42k stars), Fowler-Style Refactoring (lhfer/claude-howto-zh-cn, 2.3k stars), Refactoring Skill (Vietnamese) (luongnv89/claude-howto, 42k stars) and Legacy Modernizer (Jeffallan/claude-skills, 12k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
WrongStack (a GitHub organization) maintains it in WrongStack/WrongStack, which has 370 GitHub stars. The repository holds 38 skills in this directory. The repository was last updated on October 7, 2026.
Source: WrongStack/WrongStack on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.