refactor

refactor is a skill for Claude Code, Codex from heliohq/ship. It costs 51 tokens per session (1,983 once invoked), scanned A, original, MIT.

A guide for improving existing code while keeping its behavior unchanged. It covers finding code smells, simplifying logic, removing duplication, reusing utilities, and checking the result.

In plain words
What is it for?
Use it to clean up duplicated or overly complex code, extract methods, remove dead code, and verify that the same behavior remains.
Why use it?
It helps make code clearer and easier to maintain without changing inputs, outputs, validation, or other externally visible behavior.

Skill for Claude CodeCodex

Part of the ship plugin — 11 skills, 3 hooks, 1 MCP server shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/heliohq/ship/refactor
Any agent
npx skills add heliohq/ship --skill refactor
Clone the repo
git clone --depth 1 https://github.com/heliohq/ship

Made for: Claude Code, Codex.

Or install ship, the plugin that ships this one along with the rest of its 11 skills, 3 hooks, 1 MCP server.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/heliohq/ship/refactor.svg)](https://agentmods.dev/skills/heliohq/ship/refactor)
Your own site
<a href="https://agentmods.dev/skills/heliohq/ship/refactor"><img src="https://agentmods.dev/badge/skills/heliohq/ship/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,983 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00051 $0.01983
Opus 5 $0.00026 $0.00992
Sonnet 5 $0.00010 $0.00397
Haiku 4.5 $0.00005 $0.00198

Measured 3d ago against content hash 5287df69fea0, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/refactor/SKILL.md · 199 lines

How it starts

The opening of the file, as written. The whole thing — 199 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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.

Read the full file on GitHub · 199 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 199 lines · 51 tokens per session scan A 5287df69fea0

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository heliohq/ship (92 stars, last pushed 2mo ago), licensed MIT. It adds 51 tokens to every session and 1,983 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

joedevflow

Development workflow. Use when building a feature, creating an MVP, refactoring code, fixing a bug, or any task that involves writing or changing implementation code.

JoeCardoso13/joedevflow · 36 tokens

casely

Intelligent QA assistant that automates writing test cases from project documentation. Use when the user wants to generate test cases from requirements, runs /init, /parse, /style, /plan, /generate, /export, or works with PDF/DOCX/XLSX requirement documents and TestRail-ready Excel export.

JohnWayneeee/casely-qa-skill · 67 tokens

auth-web-cloudbase

CloudBase Web Authentication Quick Guide for frontend integration after auth-tool has already been checked. Provides concise and practical Web authentication solutions with multiple login methods and complete user management.

TencentCloudBase/CloudBase-AI-Toolkit · 38 tokens

browse-and-evaluate

Use when exploring the ai-agent-skills catalog to find, compare, and evaluate skills before installing. Always use --fields to limit output size and --dry-run before committing to an install.

MoizIbnYousaf/Ai-Agent-Skills · 43 tokens

loop-engineering

Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns. Invoke when designing or debugging a skill that iterates (search-verify-retry, scan-until-dry, fetch-retry-gate).

huytieu/COG-second-brain · 63 tokens

telnyx-messaging-hosted-curl

Set up hosted SMS numbers, toll-free verification, and RCS messaging. Use when migrating numbers or enabling rich messaging features. This skill provides REST API (curl) examples.

team-telnyx/ai · 45 tokens