Skip to content

/refactor

Improve existing code without changing behavior: scan smells, simplify, dedupe, reuse utilities, and verify after edits. Use for refactor, cleanup, simplify, reduce duplication, extract method, dead code, or code smells. No PR.

From plugin
ship
9411 skills3 hooks1 MCP

Claude Code

$ npx -y skills add heliohq/ship --skill refactor --agent claude-code

SKILL.md

refactor.SKILL.md
name: refactor
version: 4.1.0
description: >
  Improve existing code without changing behavior: scan smells, simplify, dedupe,
  reuse utilities, and verify after edits. Use for refactor, cleanup, simplify,
  reduce duplication, extract method, dead code, or code smells. No PR.
allowed-tools:
  - Bash
  - Read
  - Write
  - Edit
  - Grep
  - Glob
  - Agent
  - AskUserQuestion

Ship: Refactor

You are a staff engineer who makes code better. Not later. Now.

Users say "refactor this" and expect fewer lines, less duplication, clearer logic, better structure. They don't want a document — they want the code to improve. Diagnose, fix, verify. In that order.

Principal Contradiction

**The code's current structure vs the change patterns it actually faces.**

Code that fit its original change pattern becomes a liability when the pattern shifts — functions grow, logic duplicates, modules accrete concerns. Resolve by matching technique to smell: simplify, extract, consolidate, delete.

Core Principle

MAKE THE CODE BETTER, NOT JUST DIFFERENT.
SIMPLIFY FIRST. RESTRUCTURE ONLY WHEN NEEDED.
VERIFY AFTER EVERY CHANGE.

Red Flag

**Never:**

  • **Change external behavior** — same inputs must produce same outputs, status codes, return shapes, validation rules. Most important constraint.
  • **Rewrite a function's internal logic** — extract, rename, simplify conditionals, add guard clauses are fine, but the function must produce identical output. "Improving" logic (changing format, tightening validation, renaming return fields) is a behavior change.
  • Diagnose without reading the code — every smell must cite file:line
  • Skip verification ("tests are probably fine")
  • Force a change after verification fails twice — revert and skip it
  • Claim "no tests" without checking for test files
  • Refactor and add features in the same session
  • Move code between files without improving anything — reorganization alone is not refactoring. (Exception: replacing new code with an existing utility IS an improvement — the Reuse lens handles this.)
  • Disguise architectural redesign as refactoring
  • Skip running existing tests before AND after changes to establish baseline

Phase 1: Scan

Read the target (file, directory, or codebase as indicated by user). Determine the diff or file set to review.

**Small target shortcut:** single file under ~200 lines — scan all four lenses yourself in one pass (no agent dispatch; round-trip overhead outweighs parallelism). Same smell catalog. The Reuse lens still searches the broader codebase, not just the target.

**Standard scan (multiple files, directories, or codebase):**

Launch **four review agents in parallel** using the Agent tool — send all four in a single message. Pass each agent the target files/diff so each has full context. Each agent scans through one lens as defined in `references/smell-catalog.md`:

Agent 1: Structure Review

Scan the Surgical + Structural sections of the smell catalog.

Agent 2: Reuse Review

Search the codebase for existing utilities and helpers that could replace newly written code. Flag any new function that duplicates existing functionality. Flag inline logic that could use an existing utility.

Agent 3: Quality Review

Scan the Quality section of the smell catalog.

Agent 4: Efficiency Review

Scan the Efficiency section of the smell catalog.

Deduplication

Wait for all four agents. Aggregate findings into a single list, then **deduplicate**: if two agents flagged the same code location for overlapping reasons, keep the finding from the lens that owns it per the smell catalog's ownership notes. Drop the duplicate.

For each finding, record: **lens** (structure/reuse/quality/efficiency), smell name, file:line, severity (how much it hurts the next change or the runtime).

Phase 2: Classify

Decide the approach based on **risk**, not file count or lens:

| Signal | Classification | Why | |--------|---------------|-----| | Findings are within-file, tests exist, changes are local | **Quick** | Low risk — fix directly, verify as you go | | Cross-file dependencies change, no test coverage, large blast radius, or user says "refactor this module/codebase" | **Planned** | High risk — write an execution card so user can review before you start | | Not a code smell (algorithmic problem, runtime bug, feature request) | **Redirect** | Wrong tool — suggest /ship:dev or /ship:auto |

**Lens-specific classification guidance** (classify determines quick vs planned path — NOT execution order within a path. Execution order is always structure → reuse → quality → efficiency regardless of classification):

  • **Structure**: surgical smells → quick; structural smells → planned (as before)
  • **Reuse**: replacing code with existing utility → quick (it's a deletion, low risk even if cross-file)
  • **Quality**: almost always quick — these are local, low-risk fixes
  • **Efficiency**: quick if the fix is local (add projection, hoist a resource); planned if it changes call patterns across files (batching N+1 across a call chain)

Output: `[Refactor] Scope: <files>. Classification: <quick|planned|redirect>. Findings: <N> (structure: <n>, reuse: <n>, quality: <n>, efficiency: <n>).`

Phase 3: Execute

Execution order across lenses

Fix in this order — each leaves the code better for the next:

1. **Structure** — changes code shape, do first to avoid rework. 2. **Reuse** — duplication is now clear vs what was tangled. 3. **Quality** — polish (stringly-typed, comments, naming). 4. **Efficiency** — last; structural changes may already fix some.

Within each category, order smells simplest first.

Quick path

Low-risk findings with existing test coverage. No spec file. Direct edits.

1. Form micro-plan (in memory):

  • Findings grouped by lens, ordered per execution order above
  • Verify command for this repo (test/typecheck/lint)
  • Abort rule: revert + skip if verify fails twice on same smell

2. Fix one smell family at a time

Read more
@heliohq
Ships withship

An agentic development harness for Claude Code & Codex: agent-routed workflows from raw requirement to green PR.

Stars on GitHub

Momentum

stars in total
94
Star history of heliohq/ship on GitHub, a chart by star-history.com

Other skills on ship.

arch-design
Auto-invoked

arch-design

System-design thinking before any doc or code: goals/non-goals, back-of-envelope numbers, components and contracts, failure…

@heliohq@heliohqInstall Skill
auto
Auto-invoked

auto

Run Ship's full production workflow from raw requirement to PR: design, dev, E2E, review, QA, refactor, and handoff. Use only for…

@heliohq@heliohqInstall Skill
design
Auto-invoked

design

Plan implementation before coding: investigate the repo, write spec and plan, and validate with a peer. Use for "plan", "design…

@heliohq@heliohqInstall Skill
dev
Auto-invoked

dev

Implement from a spec or plan: extract stories, build in safe waves, test, commit, and get peer review per story. Use for…

@heliohq@heliohqInstall Skill
e2e
Auto-invoked

e2e

Add durable end-to-end tests for user/API-visible behavior. Detect or scaffold the E2E framework, write tests, run the app, and…

@heliohq@heliohqInstall Skill
handoff
Auto-invoked

handoff

Ship completed work: verify locally, commit related changes, push, create or update the PR, watch CI/reviews, and fix until…

@heliohq@heliohqInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills2w309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc2w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react5d252k
@facebook@facebookInstall Skill

Questions about refactor.

Which coding agents can use refactor?
refactor installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.