refactoring-patterns

refactoring-patterns is a skill for Claude Code, Codex from Everyone-Needs-A-Copilot/claude-copilot. It costs 111 tokens per session (2,100 once invoked), scanned A, original, MIT.

Code smell detection, refactoring triggers, and safe transformation patterns for extract, inline, and rename operations. Includes deterministic code-structure metrics analyzer (refactormetrics.py) for long functions, deep nesting, long parameter lists, large files, and function count — covers TypeScript, JavaScript…

Skill for Claude CodeCodex

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/everyone-needs-a-copilot/claude-copilot/refactoring-patterns
Any agent
npx skills add Everyone-Needs-A-Copilot/claude-copilot --skill refactoring-patterns
Clone the repo
git clone --depth 1 https://github.com/Everyone-Needs-A-Copilot/claude-copilot

Made for: Claude Code, Codex.

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 refactoring-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/everyone-needs-a-copilot/claude-copilot/refactoring-patterns.svg)](https://agentmods.dev/skills/everyone-needs-a-copilot/claude-copilot/refactoring-patterns)
Your own site
<a href="https://agentmods.dev/skills/everyone-needs-a-copilot/claude-copilot/refactoring-patterns"><img src="https://agentmods.dev/badge/skills/everyone-needs-a-copilot/claude-copilot/refactoring-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 111 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,100 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.00111 $0.02100
Opus 5 $0.00056 $0.01050
Sonnet 5 $0.00022 $0.00420
Haiku 4.5 $0.00011 $0.00210

Measured today against content hash c4ed599cafd3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactoring-patterns 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 today.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/refactor_metrics.py, scripts/test_refactor_metrics.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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/code/refactoring-patterns/SKILL.md · 222 lines

How it starts

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

Refactoring Patterns

Code smell detection, refactoring triggers, and safe transformation patterns for improving existing code without changing behaviour.

refactor_metrics.py detects deterministic complexity signals (long functions, deep nesting, etc.). The prose sections below cover judgment-level smells that the script cannot evaluate (Feature Envy, Primitive Obsession, etc.). Run the script first to get a structural baseline; apply judgment from the prose sections to interpret findings in context.

Purpose

  • Identify code smells systematically before refactoring
  • Apply the right refactoring technique for each smell
  • Refactor safely with tests as the safety net
  • Avoid common refactoring anti-patterns that create new problems

Code Smell Catalog

Smell Detection Signal Refactoring Technique
Long Method Method body > 20 lines Extract Method
Feature Envy Method uses another class's data more than its own Move Method to the class it envies
Shotgun Surgery One change requires touching many unrelated classes Move Field/Method to consolidate responsibility
Long Parameter List Function signature has > 3 parameters Introduce Parameter Object
Primitive Obsession Using string, number, boolean for domain concepts (e.g., email, money, status) Replace with Value Object
Data Clump Same group of fields appears together across multiple classes or function signatures Extract Class
Divergent Change One class is changed for multiple unrelated reasons Extract Class per single responsibility
Middle Man Class does nothing but delegate every method call to another Remove Middle Man or Inline Delegation

Detection Examples

// SMELL: Long Parameter List (>3 params)
function createOrder(userId: string, productId: string, quantity: number, discount: number, shippingAddress: string) {}

// BETTER: Parameter Object
interface OrderRequest {
  userId: string;
  productId: string;
  quantity: number;
  discount: number;
  shippingAddress: string;
}
function createOrder(request: OrderRequest) {}

// SMELL: Primitive Obsession — email as raw string
function sendWelcome(email: string) {
  if (!email.includes('@')) throw new Error('invalid');
}

// BETTER: Value Object with self-validation
class Email {
  constructor(private readonly value: string) {
    if (!value.includes('@')) throw new Error('Invalid email');
  }
  toString() { return this.value; }
}
function sendWelcome(email: Email) {}

Read the full file on GitHub · 222 lines

Files

What ships with it

2 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. today First seen · 222 lines · 111 tokens per session scan A c4ed599cafd3

Subscribe to this mod's changes

refactoring-patterns is a skill published in the GitHub repository Everyone-Needs-A-Copilot/claude-copilot (13 stars, last pushed 10d ago), licensed MIT. It adds 111 tokens to every session and 2,100 once invoked, about $0.0006 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-04.