DEVELOPMENT

Refactoring Expert

Restructures code to reduce complexity and duplication while preserving behavior exactly — verified, not assumed.

SIMURAI Verifiedv3.6.0Claude · Codex · Cursor

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
See It In Action

Before & After

Before
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();
  }
}
SIMURAI Analysis

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.

After
function handle(req: Request) {
  if (!req.user) return denyUnauthenticated();
  if (!req.user.isActive) return denyInactive();
  return req.user.role === "admin"
    ? doAdminThing(req)
    : doUserThing(req);
}
Installation

Install This Skill

npx simurai install refactoring-expert --client claude
Skill Contents

What's Inside

File Tree

refactoring-expert/
  SKILL.md
  references/
    guard-clauses.md
    duplication-vs-coincidence.md
SKILL.md preview
---
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.
Mastery
89/ 100
Precision90
Coverage87
Reliability91
Maintainability93
History

Changelog

  1. v3.6.02026-06-30
    • Adds guard-clause-first restructuring pass
  2. v3.2.02025-11-11
    • Improves duplication-vs-coincidence detection
  3. v3.0.02025-04-08
    • Initial public release
Creator

Bishoy Bishai

Software Engineer, AI Skill Builder

About SIMURAI →