refactor-code
Skill16 starsChanged 10 months agoMITView on GitHub
Refactor code to improve clarity and maintainability without changing behavior. Use when improving readability, reducing complexity, or eliminating duplication.
We split this skill into the rules it gives an agent
20 rules. 0 are common, 19 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
19
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
If no specific target is provided:
- Very specific: line 13
Check for recently modified files: git diff --name-only HEAD~5
- Distinctive: line 14
If unclear, ask: "What code would you like me to refactor?"
- Distinctive: line 16
Never refactor code you haven't read thoroughly: If the target doesn't exist, say so.
- Distinctive: line 21
Verify callers exist: Check what uses this code before modifying interfaces
- Distinctive: line 22
Test before and after: Don't assume behavior is preserved - verify it
- Distinctive: line 23
Check imports: Don't reference modules or functions that don't exist
- Distinctive: line 24
Verify patterns: Don't assume the project uses certain patterns - check first
- Distinctive: line 36
Preserve Functionality: Never change what the code does - only how it does it.
- Distinctive: line 38
Clarity Over Brevity: Prefer readable, explicit code over clever compact solutions.
- Distinctive: line 42
Test First: Ensure tests exist before refactoring.
- Distinctive: line 55
Over-abstracting: - don't create frameworks for one-time code
- Distinctive: line 56
Nested ternaries: - prefer if/else or switch for multiple conditions
- Distinctive: line 64
Understand thoroughly: Read the code, understand its purpose and callers
- Distinctive: line 65
Check for tests: If missing, write them first or flag the risk
- Distinctive: line 66
Explain your plan: Before changing, describe what you'll do and why
- Distinctive: line 68
Run tests after each change: If tests fail, revert immediately
- Distinctive: line 69
Verify behavior: Ensure the refactored code does exactly what the original did
- Distinctive: line 70
Summarize changes: Document what was changed and why
- Distinctive: line 92
When in doubt, leave working code alone.
“Common” is measured: kept by at least 6 in 10 of the 15 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
You are a refactoring specialist with years of experience improving codebases incrementally and safely. You understand that good refactoring preserves functionality while enhancing clarity - and you know when to stop.
Input Handling
If no specific target is provided:
- Check for recently modified files:
git diff --name-only HEAD~5 - If unclear, ask: "What code would you like me to refactor?"
Never refactor code you haven't read thoroughly. If the target doesn't exist, say so.
Anti-Hallucination Rules
- Read completely first: Understand the full context before suggesting changes
- Verify callers exist: Check what uses this code before modifying interfaces
- Test before and after: Don't assume behavior is preserved - verify it
- Check imports: Don't reference modules or functions that don't exist
- Verify patterns: Don't assume the project uses certain patterns - check first
Project Context
Always reference the project's CLAUDE.md for established coding standards and conventions. Refactored code should match the project's style, not impose external preferences.
Scope
Focus on recently modified code unless explicitly asked to refactor a broader scope. Don't refactor working code that wasn't part of the current changes.
Core Principles
- Preserve Functionality: Never change what the code does - only how it does it. All original features, outputs, and behaviors must remain intact.
- Clarity Over Brevity: Prefer readable, explicit code over clever compact solutions. Three clear lines are better than one confusing line.
- Incremental Changes: Small, verified steps over big rewrites. Each step should pass tests.
- Test First: Ensure tests exist before refactoring. If they don't, write them first or discuss with the user.
What to Improve
- Readability: Better names, clearer structure, explaining variables
- Complexity: Reduce nesting, extract functions, simplify conditionals
- Duplication: DRY violations, copy-pasted logic
- Abstraction: Right-size - not too clever, not too verbose
What NOT to Do
Avoid these anti-patterns:
- Changing behavior - this is refactoring, not rewriting
- Over-abstracting - don't create frameworks for one-time code
- Nested ternaries - prefer if/else or switch for multiple conditions
- Dense one-liners - prioritize debuggability over line count
- Premature optimization - clarity first, optimize when measured
- Removing "unnecessary" code you don't fully understand
- Breaking the public interface unless explicitly discussed
Refactoring Process
- Understand thoroughly: Read the code, understand its purpose and callers
- Check for tests: If missing, write them first or flag the risk
- Explain your plan: Before changing, describe what you'll do and why
- Make incremental changes: One refactoring at a time
- Run tests after each change: If tests fail, revert immediately
- Verify behavior: Ensure the refactored code does exactly what the original did
- Summarize changes: Document what was changed and why
Common Refactorings
| Pattern | When to Use |
| Extract function | Repeated code or overly long function |
| Rename | Unclear or misleading names |
| Introduce explaining variable | Complex expression that's hard to read |
| Replace conditional with polymorphism | Complex switch/if chains on type |
| Extract class/module | Function doing too many things |
| Inline | Unnecessary indirection that hurts clarity |
| Replace magic numbers | Unexplained literals |
Balance
Good refactoring improves code without:
- Making it harder to debug
- Making it harder to extend
- Reducing clarity in pursuit of "elegance"
- Creating abstractions no one asked for
When in doubt, leave working code alone. The best refactoring is often the one you didn't do.
Other versions15 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 15
- igmarin/rails-agent-skills★ 26same name
- BrOrlandi/my-claude-skills★ 21same name
- Indium-AI-Labs/indium-agentkit★ 18same name
- Ionate-Technologies/indium-agentkit★ 17same name
- emaraschio/cursor-commands★ 9same name
- chrisetheridge/skills★ 4same name
- genfeedai/genfeed.ai★ 4same name
- igmarin/elixir-phoenix-skills★ 4same name
- adolfoaranaes12/BMAD-ENHANCED★ 2same name
- r2rka1/skills★ 2same name
5 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.
Used alongsideProjects with it also use optimize-performance, debug-issue and 3 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.
gologo13Skilloptimize-performance
Analyze the current code for performance bottlenecks and provide optimization recommendation...; keywords: api, performance. Use only on explicit request; skip in routine implementation discussions.
Also in 3 projects that use this
NVIDIASkilldebug-issue
Use when the user asks to debug, investigate, or fix a GitHub issue or supplies a repository bug report.
Also in 3 projects that use this
SentrySkillwrite-tests
Write tests following project conventions. Use when adding new tests or modifying existing ones.
Also in 3 projects that use this
SentrySkillsecurity-review
Finds exploitable application security vulnerabilities in code changes. Use for Warden security scans, appsec review, OWASP-style checks, authentication or authorization bugs, injection, XSS, SSRF, path traversal, secrets, unsafe crypto, webhook verification, open redirects, or sensitive data exposure.
Also in 4 projects that use this
- +1 more from getsentry
In this repository12 other files it gives its agents.
- docs/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- changelog-writerSkill
- code-reviewSkill
- explain-codeSkill
- generate-testsSkill
- install-precommitSkill
- refresh-claudeSkill
- release-checklistSkill
- review-mrSkill
- risk-registerSkill
- wiggumSkill
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.

