refactor
Skill1 starsChanged 55 days agoMITView on GitHub
Guide safe, disciplined code refactoring. Always use this skill when asked to refactor, restructure, reorganize, clean up, or improve the design of existing code. Use when the user says "this code is messy", "help me clean this up", "this function does too much", "extract this", "break this apart", "this is hard to read", "the codebase is tangled", or any time code structure needs to change without changing behavior. Read this skill before making any structural code changes.
111 other projects use a version of this.
Adopted by
Most recently taken up by
- GUOJIE-HONG/skillstheir own version, first seen Oct 5, 2026
- morodomi/dev-crewtheir own version, first seen Oct 5, 2026
- gilsmt/skillstheir own version, first seen Oct 4, 2026
- Integralist/agent-skillstheir own version, first seen Oct 4, 2026
- AlvaroVFon/skillstheir own version, first seen Oct 3, 2026
- devantler-tech/ksailtheir own version, first seen Oct 3, 2026
Used with
Projects with it also use modern-go, to-design and 7 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
jidechaoSkillmodern-go
Modernize Go code by applying version-appropriate idioms and APIs (gofix-style transformations). Scans go.mod for the Go version, then transforms Go source files to use modern patterns—from Go 1.0 through 1.26+. Use when the user says "现代化","现代Go语言", "地道的", "idiomatic", "modernize", "modern-go", "update Go code", "gofix", or wants to upgrade Go idioms.
Also in 3 projects that use this
jidechaoSkillto-design
Generate a design document (design proposal) from a PRD, in the style of Go's official design proposals — Abstract / Background / Design / Rationale / Compatibility / Implementation, heavy on the 'why' and tradeoffs. Triggers on: to-design, prd-to-design, prd转设计文档, 生成设计文档, 写设计文档, design doc, design proposal, 设计提案, 技术设计文档.
Also in 3 projects that use this
platformplatformSkilldb-query
Query the local Postgres database of the active Aspire worktree via psql.
Also in 3 projects that use this
JetBrainsSkillfix-bug
End-to-end bug fix workflow for the Exposed project. Accepts a GitHub issue (#NUMBER), YouTrack issue (EXPOSED-NUMBER), or YouTrack URL (https://youtrack.jetbrains.com/issue/EXPOSED-NUMBER). Fetches the issue, creates a failing reproducer test, commits on a new branch, implements the fix, validates, and opens a PR. Use this skill whenever the user wants to fix a bug from an issue tracker, mentions a EXPOSED issue number, or references a GitHub issue to fix.
Also in 6 projects that use this
VercelSkillautomation
Automation and verification guide for running Native SDK apps. Use when the user asks to test a running app, inspect runtime state, list windows, wait for readiness, drive widgets, take deterministic screenshots, send bridge commands, debug why automation is not connected, create smoke tests, or verify a Native SDK example in a GUI-capable session.
Also in 3 projects that use this
MicrosoftSkillscaffold
Also in 6 projects that use this
- +2 more from jidechao
Other versions111 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 111
- github/awesome-copilot★ 40ksame name
- parcadei/Continuous-Claude-v3★ 3.9ksame name
- codeaholicguy/ai-devkit★ 1.6ksame name
- SethGammon/Citadel★ 922same name
- solatis/claude-config★ 909same name
- boshu2/agentops★ 447same name
- nwiizo/tfmcp★ 373same name
- smallnest/goal-workflow★ 287same name
- oasm-platform/open-asm★ 204same name
- sd0xdev/sd0x-harness★ 191same name
101 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository25 other files it gives its agents.
- api-designSkill
- arch-reviewSkill
- db-reviewSkill
- debugSkill
- dotnet-asyncSkill
- dotnet-opsSkill
- dotnet-testingSkill
- dotnet-typesSkill
- go-concurrencySkill
- go-opsSkill
- go-testingSkill
- go-typesSkill
- incidentSkill
- node-asyncSkill
- node-opsSkill
- perfSkill
- pr-prepSkill
- py-asyncSkill
- py-opsSkill
- py-testingSkill
- py-typesSkill
- securitySkill
- test-genSkill
- ts-testingSkill
- ts-typesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
20 rules. 0 are common, 20 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 94 edited versions we read keep these.
20
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
If the tests aren't passing before you refactor, you don't have a baseline.
- Distinctive: line 14
If there are no tests for the code you're about to refactor, write enough to cover the behavior you're going to disturb before touching …
- Distinctive: line 20
If the code you need to refactor has no obvious seam, your first task is to introduce one safely (often by extracting a function or class …
- Distinctive: line 26
Leave the tests green
- Distinctive: line 30
Don't do five things in one commit and call it a refactoring.
- Distinctive: line 36
Extract function/method: when a block of code has a single purpose and could be named:
- Distinctive: line 40
Verify the caller's behavior is identical before and after
- Distinctive: line 42
Rename: when a name is misleading, vague, or no longer accurate:
- Distinctive: line 45
Update documentation and comments at the same time
- Distinctive: line 47
Inline: when an abstraction is adding indirection without adding clarity:
- Distinctive: line 50
Don't inline just to reduce line count
- Distinctive: line 52
Move: when code belongs in a different module, class, or file:
- Distinctive: line 55
Update all call sites before committing
- Distinctive: line 57
Simplify conditionals: when nested ifs are hard to follow:
- Distinctive: line 63
Reduce coupling: when a module knows too much about another:
- Distinctive: line 70
Not a feature: Don't add new behavior while refactoring.
- Distinctive: line 84
Don't refactor code that's stable and rarely touched.
- Distinctive: line 88
When working on a refactoring:
- Distinctive: line 92
Call out any risks: "This change touches the auth middleware, which has no tests.
- Distinctive: line 93
Keep commits focused so the reviewer can tell what changed and why
“Common” is measured: kept by at least 6 in 10 of the 94 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor
Refactoring is changing code structure without changing behavior. The key word is without. Every technique here is designed to preserve correctness while improving the code's shape.
The cardinal rule: tests must be green before you start
If the tests aren't passing before you refactor, you don't have a baseline. You can't tell whether a broken test is the result of your change or was already broken. Fix failing tests first. That's a separate job from the refactoring.
If there are no tests for the code you're about to refactor, write enough to cover the behavior you're going to disturb before touching anything. You don't need 100% coverage: you need enough that a behavioral regression would show up.
Identify the seam before cutting
A seam is a place where behavior can change without editing the code that uses it, typically a function boundary, interface, or injection point. Find the seam before you start cutting. The seam defines the scope of your refactoring: you're rearranging what's inside it while keeping the seam's behavior the same from the outside.
If the code you need to refactor has no obvious seam, your first task is to introduce one safely (often by extracting a function or class around the region you want to change).
Work in small, reversible steps
Each step should:
- Leave the tests green
- Be a single logical change (rename, extract function, move, inline, etc.)
- Be independently reviewable
Don't do five things in one commit and call it a refactoring. If something goes wrong, you want to be able to bisect to the exact step that introduced the problem.
A useful rhythm: change → run tests → commit. If the tests go red, undo and understand why before proceeding.
Common refactoring moves
Extract function/method: when a block of code has a single purpose and could be named:
- Name it for what it does, not how it does it
- Pass in what it needs as parameters (avoid reaching for outer scope)
- Verify the caller's behavior is identical before and after
Rename: when a name is misleading, vague, or no longer accurate:
- Rename completely and immediately; don't leave both names alive unless there's a real API boundary requiring it
- Update documentation and comments at the same time
Inline: when an abstraction is adding indirection without adding clarity:
- Inline functions that are called in only one place and whose name doesn't add understanding
- Don't inline just to reduce line count
Move: when code belongs in a different module, class, or file:
- Move one thing at a time
- Update all call sites before committing
Simplify conditionals: when nested ifs are hard to follow:
- Early returns / guard clauses to eliminate nesting
- Pull boolean conditions into well-named variables
- Replace complex switch/if chains with a dispatch table or polymorphism when appropriate
Reduce coupling: when a module knows too much about another:
- Identify what information actually needs to cross the boundary
- Pass only what's needed, not the whole object
What refactoring is not
Not a feature: Don't add new behavior while refactoring. If you notice something missing, make a note and add it after the refactoring is done and reviewed.
Not cleanup: Fixing a bug while refactoring mixes two concerns. When a test reveals a bug during refactoring, stop, fix the bug separately, then continue the refactoring.
Not rewriting: Rewriting is starting over. Refactoring is incremental improvement of existing code. If you find yourself wanting to throw it all out and start fresh, that's a different conversation; it may be justified, but it's not refactoring.
When to stop
Refactoring is in service of a goal, not an end in itself. Stop when:
- The code is clear enough that a reader can understand it without your help
- The next feature would be straightforward to add
- The change you're making has diminishing returns
Don't refactor code that's stable and rarely touched. The cost of changing it (risk, review time) exceeds the benefit. Focus effort on code that's actively worked on.
Communicate what you're doing
When working on a refactoring:
- State the goal up front: "I'm going to extract the validation logic into a separate function so the handler is easier to read."
- Note the technique: "This is an extract-and-replace. I'm not changing behavior."
- Call out any risks: "This change touches the auth middleware, which has no tests; I'll add coverage before moving it."
- Keep commits focused so the reviewer can tell what changed and why
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

