skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
bsene/skills92 installs

refactoring

Detect code smells and apply *in-place* refactoring techniques (Extract Method/Class, Replace Conditional, Introduce Parameter Object, Rename, Move) to improve clarity, testability, and maintainability of a single function, class, or file. TRIGGER when: user mentions refactoring opportunities, code smell, long method, large class, primitive obsession, long parameter list, data clumps, feature envy, shotgun surgery, switch statement smell, extract method, extract class, replace conditional with polymorphism, introduce parameter object, simplify single file, improve readability, tidying, tidy first, "clean up this function", "refactor this class". DO NOT USE when: no tests exist (unsafe to refactor blind — add tests first), the change is behavior-altering rather than structure-only (use `tcrdd` instead), or the user needs to safely untangle a *cross-file* dependency graph where one change ripples to many call sites (use `mikado-method` instead).

How do I install this agent skill?

npx skills add https://github.com/bsene/skills --skill clean-code
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    The clean-code skill is a purely instructional knowledge base for code review and refactoring. It contains no executable scripts, network logic, or credential handling, and poses no security risks.

  • Socketpass

    No alerts

  • Snykpass

    Risk: LOW · No issues

What does this agent skill do?

Refactoring: Smells & Techniques

A comprehensive guide to detecting code smells and applying refactoring techniques to improve design, clarity, and maintainability.


Read On Demand

Read WhenFile
Identifying code smells or reviewing a diff/PR for bloatersCode Smell Catalog
Deciding which refactoring technique to useRefactoring Techniques
Choosing the right pattern, scenario-based decisions, or review workflowDecision Guide
Only when user asks where a pattern applies in a specific languageLanguage Idioms

Always-On Guardrails

  • Never auto-remove TODO comments. TODOs require manual human decision — surface them, don't delete them.
  • Tidy just in time. Tidy immediately before or after a known behavior change: before, the exact work is clear; after, the design friction is fresh. Avoid fixed technical-debt quotas, which invite speculative cleanup at the wrong time and place. If leadership reserves capacity, treat it as permission and slack, not a quota; fix the incentive that prevents timely tidying. Timebox standalone tidying only for deliberate practice, recovery from a conscious shortcut, or mapping an unfamiliar, unhealthy codebase.
  • Rule of Three before extracting. Wait for the third duplication before Extract Method / Extract Class. Two points don't reliably reveal the right abstraction.
  • No tests, no refactor. Don't refactor blind — add a safety net first.
  • Extraction needs no new tests. Helpers extracted during refactoring stay covered by the existing public-API behavior tests; writing unit tests against them re-couples the suite to structure (see testing's mock-fragility guidance).
  • Pair comment tidyings. When deleting redundant comments, also scan for missing why comments worth adding.

Smells → Techniques (Quick Reference)

SmellDetection SignalTechnique(s)
Long Method>10 lines, multiple responsibilitiesExtract Method (Rule of Three)
Large Class>10 methods, multiple concerns, hard to testExtract Class (Rule of Three)
Primitive ObsessionString/int constants for domain conceptsCreate Type/Object
Long Parameter List>3-4 parameters, related paramsIntroduce Parameter Object
Data ClumpsSame variables in multiple placesExtract Class
CommentsCode needs a comment to be understood (see smells.md for subtypes)Extract Method/Variable, Rename, Introduce Assertion, Write Tests
Uncommunicative NameName needs a comment, single letters, generic placeholders, missing unitsRename / Introduce Variable

For the full Techniques → When to Use table, see techniques.md.


Techniques by Goal

  • Testability: Extract Method → Extract Class → Replace Conditional
  • Reduce duplication: Extract Method → Replace Conditional → Introduce Variable
  • Readability: Rename → Introduce Variable → Simplify Conditional → Extract Method
  • Better design/coupling: Extract Class → Move Method/Field → Replace Conditional

When NOT to Refactor

Sometimes code size, complexity, or structure is justified:

  • Complex algorithms that genuinely need many lines (with clear comments explaining why)
  • Declarative structures like configuration objects or test data (accept longer parameter lists)
  • Temporary code that will be replaced soon (refactoring cost > benefit)
  • One-off utilities where extracting adds more boilerplate than it saves
  • Unstable code that's still in flux — wait until requirements stabilize
  • Performance-critical paths where refactoring would harm speed (profile first)
  • Code without tests — refactor only with a safety net (see Always-On Guardrails)
  • Only two occurrences of similar code — Rule of Three (see Always-On Guardrails); premature DRY tends to produce the wrong abstraction

Always ask: "Does this complexity serve the code's purpose, or does it obscure it?"


External References

  • Refactoring Guru: Code Smells - Bloaters
  • Martin Fowler: Refactoring Catalog — 72+ techniques organized by operation
  • Principles: SRP, OCP, DRY
  • Attribution: Tim Ottinger (comments); Fowler Refactoring; Martin Clean Code

Benchmark

Scenario: .benchmarks/scenarios/refactoring-001-long-method.md · Run: 2026-06-14

ModelWithoutWithDelta
claude-opus-4-883%100%+17%
claude-sonnet-4-633%100%+67%
claude-haiku-4-50%100%+100%

PASS (strongest signal). Decisive on weak models (haiku 0→100%): enforces smell-naming, Extract-Method-first, in-place scope, rule-of-three. Keep as-is. Gate per .agents/skills/skill-optimizer/rules/release-gates.md.

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/bsene/skills/clean-code">View refactoring on skillZs</a>