refactor

refactor is a skill for Claude Code from chrisallenlane/claude-swe-workflows. It costs 47 tokens per session (3,275 once invoked), scanned A, original, MIT.

An iterative workflow for improving code quality within the existing architecture.

In plain words
What is it for?
Use it to refactor a codebase in small cycles, with specialist review, quality checks, and separate commits for each change.
Why use it?
It helps find and remove duplicated code, unused code, unclear names, and unnecessary complexity while checking that changes still work.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter.

Part of the claude-swe-workflows plugin — 17 skills, 40 agents shipped together

Good fit Use it to refactor a codebase in small cycles, with specialist review, quality checks, and separate commits for each change.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/chrisallenlane/claude-swe-workflows/refactor
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.

Any agent
npx skills add chrisallenlane/claude-swe-workflows --skill refactor
Clone the repo
git clone --depth 1 https://github.com/chrisallenlane/claude-swe-workflows

Made for: Claude Code.

Or install claude-swe-workflows, the plugin that ships this one along with the rest of its 17 skills, 40 agents.

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/chrisallenlane/claude-swe-workflows/refactor.svg)](https://agentmods.dev/skills/chrisallenlane/claude-swe-workflows/refactor)
Your own site
<a href="https://agentmods.dev/skills/chrisallenlane/claude-swe-workflows/refactor"><img src="https://agentmods.dev/badge/skills/chrisallenlane/claude-swe-workflows/refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 47 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,275 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00047 $0.03275
Opus 5 $0.00023 $0.01638
Sonnet 5 $0.00009 $0.00655
Haiku 4.5 $0.00005 $0.00328

Measured 8d ago against content hash af882f84d245, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, 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 8d 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 · 387 lines

How it starts

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

Refactor - Iterative Code Quality Improvement

Autonomous refactoring workflow that iteratively improves code quality within the existing architecture, always preferring the least aggressive change available, until no further opportunities exist.

Philosophy

Clarity is the goal. Every iteration should make the codebase easier to form a correct mental model of. Red diffs are the strongest signal - less code almost always means clearer code, and every iteration should delete more than it adds. But when reducing lines would hurt comprehensibility, clarity wins.

Err on the side of trying. When uncertain whether a refactoring is worthwhile, attempt it anyway. Git makes failed experiments free - the workflow will revert changes that don't pass QA. Missed opportunities are invisible; failed attempts teach you something. Be bold, knowing that version control provides the safety net.

Work within the existing architecture. This workflow improves code quality - DRY, dead code, naming, complexity - without questioning module boundaries or reorganizing the system. For architectural analysis (noun extraction, module dissolution, blueprint-driven restructuring), use /review-arch instead.

Workflow Overview

┌─────────────────────────────────────────────────────┐
│                  REFACTORING LOOP                   │
├─────────────────────────────────────────────────────┤
│  1. Determine scope                                 │
│  2. Select aggression ceiling                       │
│  3. Gather QA instructions                          │
│  4. Spawn fresh swe-code-reviewer agent (full scan)      │
│  5. Select least aggressive changes available       │
│  6. If none remain → exit to summary                │
│  7. Spawn SME agent (implement batch)               │
│  8. Spawn QA agent (verify)                         │
│     ├─ PASS → commit, goto 4                        │
│     └─ FAIL → retry (max 3), then abort batch       │
│  9. Completion summary                              │
│ 10. Update documentation (/tidy-docs)              │
└─────────────────────────────────────────────────────┘

Read the full file on GitHub · 387 lines

Files

What ships with it

1 file 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. 8d ago First seen · 387 lines · 47 tokens per session scan A af882f84d245

Subscribe to this mod's changes

refactor is a skill published in the GitHub repository chrisallenlane/claude-swe-workflows (18 stars, last pushed 3mo ago), licensed MIT. It adds 47 tokens to every session and 3,275 once invoked, about $0.0002 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.