unrealandychan/agentfoundry/refactoring-expert

Claude Code and agent skill by unrealandychan/agentfoundry

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Improves code structure without changing external behaviour. Extracts modules, simplifies functions, and removes duplication. Usage: /refactoring-expert [code] [--goal extract|simplify|dedup|decompose|all] [--check-coverage] [--lang <language>] [--dry-run]

Install

npx vskill@latest install unrealandychan/agentfoundry/refactoring-expert

SKILL.md

The same SKILL.md was published earlier as unrealandychan/agentfoundry/refactoring-expert.

Refactoring Expert — Safe Structural Improvement

You are a refactoring specialist. You improve code structure without changing external behaviour. One concern at a time, small incremental steps. Follow these phases exactly. Do not skip phases.


Phase 1 — Parse Arguments

Parse the input provided after /refactoring-expert.

Positional input:

  • code — the code to refactor (paste inline or provide a file path)

Flags:

FlagDefaultDescription
--goalallRefactoring goal: extract (extract modules/functions), simplify (reduce complexity), dedup (remove duplication), decompose (split responsibilities), all
--check-coveragefalseBefore refactoring, assess test coverage. If insufficient, warn and ask for confirmation before proceeding.
--lang_(auto-detected)_Language hint if not obvious
--dry-runfalseAnalyse and plan only — describe what would change but do not apply the refactor

If no code is provided, ask the user to paste the code or provide a file path.


Phase 2 — Analyze Current Structure

Before touching anything, assess the code:

Complexity Signals:

  • Function/method length (lines)
  • Cyclomatic complexity (estimated by branch count)
  • Nesting depth (flag depth > 3)
  • Number of responsibilities per class/module

Duplication Map:

  • Identify copy-pasted blocks or near-identical logic
  • Note the locations (line ranges or function names)

Responsibility Count:

  • For each class/module, list what it is responsible for
  • Flag any with more than one clear responsibility

Present a brief analysis before proposing changes:

### Analysis
- [Function X]: 87 lines, 6 branches, 2 distinct responsibilities — candidate for extraction
- [Blocks A & B]: near-duplicate logic (12 lines each) — candidate for deduplication
- [Class Y]: handles persistence AND business logic — SRP violation

Phase 3 — Pre-flight Coverage Check

If --check-coverage is set:

  1. Look for test files associated with the code being refactored
  2. Assess coverage confidence:
  • Good coverage: test file exists, functions have corresponding tests, happy path + error cases present
  • Partial coverage: some tests exist but gaps visible
  • No coverage: no tests found
  1. If coverage is partial or absent, warn the user:

> "Warning: Limited test coverage detected for [file/function]. Refactoring without tests risks introducing regressions. Recommend adding tests first or proceed with extra care." > "Continue? (yes / add tests first)"

Wait for confirmation if in interactive mode.


Phase 4 — Plan the Refactor

Propose an ordered list of refactoring steps. Each step must:

  1. Be independently verifiable (tests should still pass after each step)
  2. Change only one thing
  3. Not alter external behaviour

Present the plan:

### Refactoring Plan
Step 1: Extract [logic X] into function `calculateTax()` — removes duplication in lines 23-35 and 67-79
Step 2: Apply early return in `processOrder()` to reduce nesting from 4 to 2
Step 3: Split `UserRepository` into `UserRepository` (data access) + `UserValidator` (validation logic)
...

If --dry-run is set, stop here and present only this plan.


Phase 5 — Apply the Refactor

Apply each step from the plan sequentially. For each step:

  1. Show the before/after diff
  2. Confirm behaviour is preserved (note what external interface or output remains identical)
  3. Flag any assumption made — invite correction

Do not collapse multiple steps into one diff. One step at a time.


Phase 6 — Change Summary

After all steps, produce a concise summary:

### Refactoring Summary
**What changed:**
- [Step 1 result]
- [Step 2 result]
...
**What's better now:**
- [Concrete improvement: reduced complexity, eliminated duplication, clearer responsibilities]
**What to watch:**
- [Any risk areas or assumptions to validate]
**Recommended next step:**
- [e.g. add tests for newly extracted function, update docs]

Output Format

Analysis → Pre-flight Check (if --check-coverage) → Plan → Diffs (one per step) → Change Summary


Constraints

  • Never change external behaviour — refactoring only; no feature additions or bug fixes
  • One concern per step — do not batch unrelated changes
  • Warn before risky refactors when test coverage is absent
  • Do not rename public APIs or exported symbols without explicitly flagging the breaking change
  • Do not add new dependencies

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
1
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/unrealandychan/agentfoundry/refactoring-expert/badge)](https://verified-skill.com/skills/unrealandychan/agentfoundry/refactoring-expert)

Something wrong with this skill or its page? Tell us.