dev-refactor

dev-refactor is a skill for Claude Code from christopherlouet/claude-base. It costs 27 tokens per session (925 once invoked), scanned A, original, MIT.

A guide to restructuring existing code into smaller, clearer pieces while keeping its behaviour unchanged.

In plain words
What is it for?
Use it to split long functions, simplify conditions, replace large switches with clearer designs, and identify common code smells.
Why use it?
It reduces tangled code and makes future changes safer by encouraging tests, small steps, and focused edits.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

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/christopherlouet/claude-base/dev-refactor
Any agent
npx skills add christopherlouet/claude-base --skill dev-refactor
Clone the repo
git clone --depth 1 https://github.com/christopherlouet/claude-base

Made for: Claude Code.

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 dev-refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/christopherlouet/claude-base/dev-refactor.svg)](https://agentmods.dev/skills/christopherlouet/claude-base/dev-refactor)
Your own site
<a href="https://agentmods.dev/skills/christopherlouet/claude-base/dev-refactor"><img src="https://agentmods.dev/badge/skills/christopherlouet/claude-base/dev-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 27 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 925 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.1 $0.00027 $0.00925
Opus 5 $0.00014 $0.00463
Sonnet 5 $0.00005 $0.00185
Haiku 4.5 $0.00003 $0.00093

Measured 2d ago against content hash b17a680b9633, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

dev-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 2d 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.

.claude/skills/dev-refactor/SKILL.md · 168 lines

How it starts

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

Code Refactoring

Principles

  1. Tests pass BEFORE and AFTER
  2. Small incremental changes
  3. One type of change at a time
  4. Commit after each refactoring

Common techniques

Extract Function

// Before
function processOrder(order) {
  // 20 lines of validation
  // 30 lines of calculation
  // 10 lines of sending
}

// After
function processOrder(order) {
  validateOrder(order);
  const total = calculateTotal(order);
  sendConfirmation(order, total);
}

Extract Variable

// Before
if (user.age >= 18 && user.country === 'FR' && !user.banned) { }

// After
const isAdult = user.age >= 18;
const isFrench = user.country === 'FR';
const isActive = !user.banned;
if (isAdult && isFrench && isActive) { }

Replace Conditional with Polymorphism

// Before
function getPrice(type) {
  switch(type) {
    case 'basic': return 10;
    case 'premium': return 20;
  }
}

// After
interface Plan { getPrice(): number }
class BasicPlan implements Plan { getPrice() { return 10; } }
class PremiumPlan implements Plan { getPrice() { return 20; } }

Code Smells to detect

Smell Refactoring
Long method Extract Method
Large class Extract Class
Duplicate code Extract + Reuse
Long parameter list Parameter Object
Feature envy Move Method
Primitive obsession Value Object

Reducing Entropy (Complexity reduction)

Complexity metrics

Metric Alert threshold How to measure
Cyclomatic complexity > 10 per function Number of branches (if/else/switch)
Nesting depth > 3 levels Nesting of if/for/while
Function length > 50 lines Number of lines
Number of parameters > 4 Function parameters
Afferent/efferent coupling Unstable ratio Incoming/outgoing dependencies
File size > 300 lines Lines of code

Reduction techniques

Read the full file on GitHub · 168 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. 2d ago First seen · 168 lines · 27 tokens per session scan A b17a680b9633

Subscribe to this mod's changes

dev-refactor is a skill published in the GitHub repository christopherlouet/claude-base (5 stars, last pushed yesterday), licensed MIT. It adds 27 tokens to every session and 925 once invoked, about $0.0001 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-09-03.