refactoring-patterns

refactoring-patterns is a skill for Claude Code, Codex from summarybotng/summarybot-ng. It costs 33 tokens per session (1,266 once invoked), scanned A, original, MIT.

A guide for changing code structure while keeping its behaviour the same. It uses small changes, tests, and commits to make the work safer.

In plain words
What is it for?
Use it to simplify long methods, large classes, duplicated code, complex conditions, magic numbers, and nested loops.
Why use it?
It helps reduce technical debt and code smells without accidentally introducing new bugs.

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/summarybotng/summarybot-ng/refactoring-patterns
Any agent
npx skills add summarybotng/summarybot-ng --skill refactoring-patterns
Clone the repo
git clone --depth 1 https://github.com/summarybotng/summarybot-ng

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/summarybotng/summarybot-ng/refactoring-patterns.svg)](https://agentmods.dev/skills/summarybotng/summarybot-ng/refactoring-patterns)
Your own site
<a href="https://agentmods.dev/skills/summarybotng/summarybot-ng/refactoring-patterns"><img src="https://agentmods.dev/badge/skills/summarybotng/summarybot-ng/refactoring-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,266 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.00033 $0.01266
Opus 5 $0.00016 $0.00633
Sonnet 5 $0.00007 $0.00253
Haiku 4.5 $0.00003 $0.00127

Measured yesterday against content hash 040fd074f369, 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 yesterday.

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

How it starts

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

Refactoring Patterns

<default_to_action> When refactoring:

  1. ENSURE tests pass (never refactor without tests)
  2. MAKE small change (one refactoring at a time)
  3. RUN tests (must stay green)
  4. COMMIT (save progress)
  5. REPEAT

Safe Refactoring Cycle:

npm test               # Green ✅
# Make ONE small change
npm test               # Still green ✅
git commit -m "refactor: extract calculateTotal"
# Repeat

Code Smells → Refactoring:

Smell Refactoring
Long method (>20 lines) Extract Method
Large class Extract Class
Long parameter list (>3) Introduce Parameter Object
Duplicated code Extract Method/Class
Complex conditional Decompose Conditional
Magic numbers Named Constants
Nested loops Replace Loop with Pipeline

NEVER REFACTOR:

  • Without tests (write tests first)
  • When deadline is tomorrow
  • Code you don't understand
  • Code that works and won't be touched </default_to_action>

Quick Reference Card

Common Refactorings

Pattern Before After
Extract Method 50-line function 5 small functions
Extract Class Class doing 5 things 5 single-purpose classes
Parameter Object fn(a,b,c,d,e,f) fn(options)
Replace Conditional if (type === 'a') {...} Polymorphism
Pipeline Nested loops .filter().map().reduce()

The Rule of Three

  1. First time → Just do it
  2. Second time → Wince and duplicate
  3. Third time → Refactor

Key Patterns

Extract Method

// Before: Long method
function processOrder(order) {
  // 50 lines of validation, calculation, saving, emailing...
}

// After: Clear responsibilities
function processOrder(order) {
  validateOrder(order);
  const pricing = calculatePricing(order);
  const saved = saveOrder(order, pricing);
  sendConfirmationEmail(saved);
  return saved;
}

Replace Loop with Pipeline

// Before
let results = [];
for (let item of items) {
  if (item.inStock) {
    results.push(item.name.toUpperCase());
  }
}

// After
const results = items
  .filter(item => item.inStock)
  .map(item => item.name.toUpperCase());

Read the full file on GitHub · 211 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. yesterday First seen · 211 lines · 33 tokens per session scan A 040fd074f369

Subscribe to this mod's changes

refactoring-patterns is a skill published in the GitHub repository summarybotng/summarybot-ng (2 stars, last pushed 2mo ago), licensed MIT. It adds 33 tokens to every session and 1,266 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-09-03.

Related

Other skills, from other repositories

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-quality-review

Run a maintainability and structure review focused on abstraction quality, branching complexity, file growth, canonical ownership, duplication, and refactoring opportunities. Use when the user asks for code quality review, maintainability review, 代码质量审查, 可维护性审查, or comments about whether the change stays easy to…

bahayonghang/my-ai-cli-toolkit · 149 tokens

code-refactor

Implement safe, behavior-preserving code refactors after inspecting the existing project. Use when the user asks to refactor, split large files, extract methods, reduce duplication, rename, clean dead code, or says 重构代码, 拆分模块, 提取方法, 优化命名, 优化注释, 删除未调用代码. For broad requests, plan safe slices and wait for approval; for…

bahayonghang/my-ai-cli-toolkit · 97 tokens

arch-optimize

架构优化技能 v3.2:六大衰退风险扫描(R1-R6)、质量度量(MI/CC/健康分)、回归防护。五阶段工作流配 4 个零依赖本地脚本(archscan/depgraph/riskdiagnose/qualitymetrics/regressionguard),全部输出 JSON。在架构审查、技术债评估、代码重构、质量提升、工程结构评审时调用。.

bfxh/arch-optimize · 103 tokens

refactoring-patterns

Use this skill when improving existing code without changing its behavior. It defines when and how to refactor safely.

ApexIQ/skillsmith · 27 tokens

refactoring-workflow

Improve the structure of existing code without changing its behaviour, in small verified steps under a green test suite. Use when the user asks to refactor, clean up, restructure or simplify code, wants to reduce duplication or coupling, is preparing a codebase for a feature it cannot currently accommodate, or when…

personamanagmentlayer/pcl · 83 tokens