Refactoring Expert
Restructures code to reduce complexity and duplication while preserving behavior exactly — verified, not assumed.
What It Does
- Never changes behavior while refactoring — verifies with existing tests
- Extracts duplicated logic only when it shares a real reason to change together
- Reduces nesting and branching without over-abstracting
- Names things for what they do, not how they're implemented
- Refactors in small, independently reviewable steps
When To Use It
- Simplifying a function that's grown too many responsibilities
- Removing duplication introduced by copy-paste feature work
- Reducing deep conditional nesting into guard clauses
- Preparing a module for a feature that current structure blocks
When Not To Use It
- Requires an existing test suite to verify behavior preservation confidently
- Will not merge two similar-looking functions if their reasons to change differ
How It Works
- Run existing tests to establish a behavior baseline
- Identify the specific complexity to reduce: nesting, duplication, responsibility
- Refactor in small steps, re-running tests after each
- Rename for clarity as structure settles
- Confirm the diff changes structure only, not behavior
Before & After
function handle(req) {
if (req.user) {
if (req.user.isActive) {
if (req.user.role === "admin") {
return doAdminThing(req);
} else {
return doUserThing(req);
}
} else {
return denyInactive();
}
} else {
return denyUnauthenticated();
}
}Four levels of nesting hide the actual decision tree: two early-exit denials followed by a role branch. The nesting adds no information, only reading effort.
Replace nested if/else with guard clauses so the happy path reads top-to-bottom, and the denial cases are visibly handled first.
function handle(req: Request) {
if (!req.user) return denyUnauthenticated();
if (!req.user.isActive) return denyInactive();
return req.user.role === "admin"
? doAdminThing(req)
: doUserThing(req);
}Install This Skill
npx simurai install refactoring-expert --client claudeWhat's Inside
File Tree
refactoring-expert/
SKILL.md
references/
guard-clauses.md
duplication-vs-coincidence.md--- name: refactoring-expert description: Reduce complexity and duplication while preserving behavior exactly. --- # Refactoring Expert Establish a test baseline before touching structure. Only merge duplicated code that shares a real reason to change together — coincidental similarity is not duplication. Refactor in small steps.
Changelog
- v3.6.02026-06-30
- — Adds guard-clause-first restructuring pass
- v3.2.02025-11-11
- — Improves duplication-vs-coincidence detection
- v3.0.02025-04-08
- — Initial public release
Bishoy Bishai
Software Engineer, AI Skill Builder
Related Skills
Code Review
Reviews diffs and pull requests for correctness bugs, unsafe patterns, and needless complexity before a human ever has to.
React Specialist
Builds and refactors React components with correct hooks usage, sane state boundaries, and no unnecessary re-renders.
Architecture Reviewer
Evaluates system design decisions for coupling, scalability, and long-term maintainability before they're set in stone.