refactoring-patterns

refactoring-patterns is a skill for Claude Code, Codex from ApexIQ/skillsmith. It costs 27 tokens per session (548 once invoked), scanned A, original, MIT.

A guide to changing existing code while keeping its behavior the same. It describes patterns such as extracting functions or components, naming important values, and grouping related parameters.

In plain words
What is it for?
Use it to split large functions or files, remove repeated code, simplify confusing code, improve React components, and replace unexplained numbers with named values.
Why use it?
It helps make code easier to understand and maintain while reducing the risk of accidental behavior changes.

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/apexiq/skillsmith/refactoring_patterns
Any agent
npx skills add ApexIQ/skillsmith --skill refactoring_patterns
Clone the repo
git clone --depth 1 https://github.com/ApexIQ/skillsmith

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/apexiq/skillsmith/refactoring_patterns.svg)](https://agentmods.dev/skills/apexiq/skillsmith/refactoring_patterns)
Your own site
<a href="https://agentmods.dev/skills/apexiq/skillsmith/refactoring_patterns"><img src="https://agentmods.dev/badge/skills/apexiq/skillsmith/refactoring_patterns.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 548 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.00027 $0.00548
Opus 5 $0.00014 $0.00274
Sonnet 5 $0.00005 $0.00110
Haiku 4.5 $0.00003 $0.00055

Measured 3d ago against content hash 77658d59be41, 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 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.

.agent/skills/refactoring_patterns/SKILL.md · 87 lines

What it actually says

♻️ Refactoring Patterns

Rule: Refactor with tests. No tests = No refactor.

1. When to Refactor

Signal Action
Same code in 3+ places Extract to function/component.
Function >50 lines Split into smaller functions.
File >500 lines Split into modules.
"I don't understand this" Add comments, then simplify.

When NOT to Refactor:

  • No tests covering the code.
  • Deadline pressure (ship first, refactor later).
  • "Just because" - there must be a clear benefit.

2. Common Refactoring Patterns

Extract Function

# Before
def process_email(email):
    # 50 lines of validation
    # 50 lines of processing

# After
def process_email(email):
    validate_email(email)
    transform_email(email)

Extract Component (React)

// Before: 200-line component
// After: Split into <EmailList />, <EmailRow />, <EmailActions />

Replace Magic Numbers

# Before
if priority > 7:

# After
HIGH_PRIORITY_THRESHOLD = 7
if priority > HIGH_PRIORITY_THRESHOLD:

Introduce Parameter Object

# Before
def send_email(to, subject, body, cc, bcc, attachments): ...

# After
def send_email(request: SendEmailRequest): ...

3. Safe Refactoring Workflow

  1. Write tests (if they don't exist).
  2. Run tests - they should pass.
  3. Refactor in small steps.
  4. Run tests after each step.
  5. Commit when green.

Examples

  • Good refactor: Extract calculatePriority() from a 100-line function. Tests pass before and after.
  • Bad refactor: "Cleaned up" a file with no tests. Shipped a bug.

Guidelines

  • One refactor per commit. Don't mix refactors with features.
  • Use IDE refactoring tools (Rename, Extract) - they're safer.
  • If refactor is risky, create a feature flag to roll back.
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 · 87 lines · 27 tokens per session scan A 77658d59be41

Subscribe to this mod's changes

refactoring-patterns is a skill published in the GitHub repository ApexIQ/skillsmith (5 stars, last pushed 5mo ago), licensed MIT. It adds 27 tokens to every session and 548 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-08-31.

Related

Other skills, from other repositories

refactor-agent

Safe, systematic code refactoring — extract functions, reduce complexity, eliminate duplication, improve naming. Use when improving code structure without changing behavior.

chandrudp29/skillhub · 32 tokens

agent-discussion-panel

Use when rendering a multi-agent discussion as a TUI panel. Defines terminal panel layout, component architecture, real-time streaming behavior, and integration points for displaying AgentOpinion data with bordered boxes, severity badges, and consensus indicators.

JeremyDev87/codingbuddy · 50 tokens

cost-budget

Use when managing AI session costs, setting budget limits, or preventing cost overruns in autonomous workflows like taskMaestro, autopilot, ralph loops, and parallel agent execution. Defines cost tracking protocol, threshold alerts, and auto-pause mechanism.

JeremyDev87/codingbuddy · 53 tokens

agent-design

Use when creating new specialist agent definitions for codingbuddy. Covers JSON schema design, expertise definition, system prompt authoring, and differentiation from existing agents.

JeremyDev87/codingbuddy · 33 tokens

refactoring

Improve code structure without changing behavior using proven refactoring patterns. Use when cleaning up code, reducing duplication, improving readability, or restructuring modules.

asgarovf/locusai · 31 tokens

code-refactoring-advisor

Enterprise code refactoring advisor that detects code smells, anti-patterns, and complexity issues with specific refactoring recommendations, test generation, and maintainability metrics.

XSpoonAi/spoon-awesome-skill · 36 tokens