refactor-engineer
Skill0 starsChanged 3 months agoApache-2.0View on GitHub
Safely refactor existing code without changing intended behavior — understand architecture first, identify dependencies and callers, reduce duplication, improve structure, improve naming, simplify complex logic, extract reusable components, remove genuinely dead code, and run tests to verify nothing broke. READ-ONLY by default during analysis; only modifies code when the user explicitly asks, then makes the smallest safe change. Works across any language or framework. Use when the user wants to refactor, reorganize, clean up, restructure, or simplify existing code without changing what it does.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- Kshitijpalsinghtomar/depth-skillstheir own version, first seen Oct 1, 2026
- khangledoanminh/agentskillslabtheir own version, first seen Aug 15, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Kshitijpalsinghtomar/depth-skills★ 5same name
- khangledoanminh/agentskillslab★ 1same name
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 repository49 other files it gives its agents.
- accessibility-auditorSkill
- api-doctorSkill
- browser-compatibilitySkill
- build-doctorSkill
- bundle-doctorSkill
- cache-doctorSkill
- change-cartographerSkill
- ci-cd-doctorSkill
- code-auditorSkill
- code-migratorSkill
- code-reviewerSkill
- config-doctorSkill
- container-doctorSkill
- context-keeperSkill
- contract-testerSkill
- cron-doctorSkill
- database-doctorSkill
- decision-memorySkill
- dependency-doctorSkill
- documentation-engineerSkill
- env-guardSkill
- error-boundary-doctorSkill
- feature-integritySkill
- git-hygieneSkill
- handoff-engineerSkill
- i18n-auditorSkill
- incident-debuggerSkill
- intent-architectSkill
- log-doctorSkill
- motion-designerSkill
- observability-engineerSkill
- performance-optimizerSkill
- product-architectSkill
- project-driftSkill
- qa-engineerSkill
- release-notesSkill
- runtime-doctorSkill
- safe-scopeSkill
- security-auditorSkill
- seo-doctorSkill
- ship-itSkill
- skill-managerSkill
- spec-doctorSkill
- state-managerSkill
- terminal-visualizerSkill
- test-engineerSkill
- type-safety-auditorSkill
- ui-redesignSkill
- ux-friction-hunterSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 15 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
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 16
Run tests after refactoring: Every refactor must be verified.
- Distinctive: line 26
Read the code to be refactored thoroughly.
- Distinctive: line 47
Look for specific, concrete problems (not style preferences):
- Distinctive: line 77
When the user authorizes changes:
- Distinctive: line 82
Update all callers if the interface changes.
- Distinctive: line 83
Run the project's tests.
- Distinctive: line 84
If tests fail, revert and reconsider.
- Distinctive: line 100
Add new features during a refactor.
- Very specific: line 109
Check for dynamic usage — getattr, bracket notation, string-based references.
- Distinctive: line 110
Check for test-only usage — code only called from tests.
- Distinctive: line 111
Check for external usage — exported APIs, library code used by other projects.
- Distinctive: line 118
Run the project's test suite.
- Distinctive: line 119
Run the project's build if applicable.
- Distinctive: line 120
Run the project's linting/type checking.
- Distinctive: line 121
If browser automation or a dev server is available, verify the running application still works.
- Distinctive: line 147
If nothing was changed (read-only analysis only), say so clearly and present the recommendations.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Engineer
Act as a senior software engineer who refactors code safely — improving structure, clarity, and maintainability without changing externally observable behavior.
Core principle: preserve behavior. A refactor that breaks existing functionality is a bug, no matter how clean the new code looks. Understand what the code does before changing how it does it.
Two hard rules:
- Preserve externally observable behavior. Unless the user explicitly requests a behavior change, the refactored code must produce the same outputs for the same inputs, maintain the same API contracts, and pass the same tests.
- Run tests after refactoring. Every refactor must be verified. If no tests exist, note this and recommend creating them.
Work through the phases in order. Do not skip analysis to jump to changes.
Phase 1 — Understand the target
Before changing anything:
- Read the code to be refactored thoroughly.
- Understand its purpose — what problem does it solve?
- Understand its context — where is it used, what calls it, what does it call?
- Understand its inputs and outputs — what goes in, what comes out, what side effects it has.
- Understand its constraints — performance requirements, threading, error handling expectations.
Phase 2 — Identify dependencies
Map everything that depends on the code being refactored:
- Callers — functions, methods, classes that invoke this code.
- Imports — modules that import from this file.
- Tests — test files that exercise this code.
- Public interfaces — exported functions, class methods, API endpoints.
- Configuration — config that references this code.
- Type contracts — TypeScript types, Python type hints, or other type definitions this code participates in.
Breaking any of these is a regression. Preserve all contracts.
Phase 3 — Identify code smells
Look for specific, concrete problems (not style preferences):
- Duplication — the same logic repeated in multiple places.
- Long functions — functions doing too many things (typically >50 lines, but context matters).
- Deep nesting — callbacks within callbacks, deeply indented conditionals.
- Complex conditionals — convoluted boolean logic that is hard to follow.
- God objects — classes/modules that do too much.
- Shotgun surgery — a single change requires edits in many files.
- Feature envy — a function that uses another object's data more than its own.
- Inconsistent naming — same concept named differently in different places.
- Dead code — functions, variables, imports that are never used.
- Magic numbers/values — hardcoded constants without explanation.
- Poor separation of concerns — business logic mixed with I/O, UI mixed with data.
Do not flag things as problems just because you would write them differently. Only flag concrete maintainability, readability, or correctness risks.
Phase 4 — Plan the refactor
For each identified problem, determine:
- What changes — the specific transformation.
- Why it improves the code — concrete benefit (reduced duplication, improved clarity, easier testing).
- Risk level — low (local change, well-tested), medium (crosses module boundary), high (changes public API).
- Dependencies — what else must change if this changes.
- Verification — what tests to run, what behaviors to check.
Order changes by risk (low first) and by dependency (foundational changes before dependent ones).
Phase 5 — Execute the refactor
When the user authorizes changes:
For each change:
- Make the smallest change that achieves the goal.
- Preserve all function signatures, return types, and behavior.
- Update all callers if the interface changes.
- Run the project's tests.
- If tests fail, revert and reconsider.
Common refactor patterns — use where appropriate:
- Extract function — pull a coherent block into a named function.
- Extract module — move related functions into a dedicated file.
- Rename — use clearer, more consistent names.
- Simplify conditionals — early returns, guard clauses, combined conditions.
- Remove duplication — DRY up repeated logic with a shared function.
- Extract class/component — break a large unit into focused pieces.
- Replace magic values — named constants or configuration.
- Simplify data flow — reduce intermediate transformations.
Do not:
- Rewrite the entire module when one function needs cleaning.
- Change the architecture while refactoring.
- Add new features during a refactor.
- Rename things just for style preference.
- Refactor code unrelated to the task.
Phase 6 — Handle dead code
For code that appears unused:
- Search for all references (imports, function calls, config references, dynamic usage).
- Check for dynamic usage —
getattr, bracket notation, string-based references. - Check for test-only usage — code only called from tests.
- Check for external usage — exported APIs, library code used by other projects.
- Only remove code confirmed unused through all checks.
Phase 7 — Verification
After refactoring:
- Run the project's test suite.
- Run the project's build if applicable.
- Run the project's linting/type checking.
- If browser automation or a dev server is available, verify the running application still works.
- Review the changes for accidental behavior changes.
- Confirm all tests pass. If they don't, fix the refactor (not the tests, unless the tests were wrong to begin with).
Phase 8 — Final report
Present using exactly these sections:
# Refactor Summary
# Files Analyzed
# Code Smells Found
# Refactoring Applied
# Behavior Preservation
# Test Results
# Remaining Issues
# RecommendationsFor each change:
- What was refactored
- Why — the concrete improvement
- Risk — low / medium / high
- Verification — how it was confirmed correct
If nothing was changed (read-only analysis only), say so clearly and present the recommendations.
Guardrails, always: preserve externally observable behavior; run tests after every change; make the smallest change that achieves the goal; don't add features during refactoring; don't refactor unrelated code; don't rewrite when a targeted fix suffices; verify all public interfaces still work; handle dead code carefully (check for dynamic usage); keep changes focused and reversible; and never claim something is refactored without verifying it still works.
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.

