dry-refactoring

dry-refactoring is a skill for Claude Code, Codex from YYH211/Claude-meta-skill. It costs 70 tokens per session (7,186 once invoked), scanned A, original, MIT.

A four-step guide for finding and removing repeated code using the DRY (“Don’t Repeat Yourself”) principle, which keeps each piece of knowledge in one clear place.

In plain words
What is it for?
Use it when extracting shared functions or reusable code, replacing repeated numbers or strings, and improving code maintainability.
Why use it?
Repeated code makes fixes harder because the same change may be needed in several places. It also helps identify copy-pasted logic, repeated values, and other common code smells.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when extracting shared functions or reusable code, replacing repeated numbers or strings, and improving code maintainability.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/yyh211/claude-meta-skill/dry-refactoring
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 YYH211/Claude-meta-skill --skill dry-refactoring
Clone the repo
git clone --depth 1 https://github.com/YYH211/Claude-meta-skill

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/yyh211/claude-meta-skill/dry-refactoring/github.svg)](https://agentmods.dev/skills/yyh211/claude-meta-skill/dry-refactoring)
Your own site
<a href="https://agentmods.dev/skills/yyh211/claude-meta-skill/dry-refactoring"><img src="https://agentmods.dev/badge/skills/yyh211/claude-meta-skill/dry-refactoring/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for dry-refactoring

Your own site · 80×15
<a href="https://agentmods.dev/skills/yyh211/claude-meta-skill/dry-refactoring"><img src="https://agentmods.dev/badge/skills/yyh211/claude-meta-skill/dry-refactoring.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 70 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 7,186 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00070 $0.07186
Opus 5 $0.00035 $0.03593
Sonnet 5 $0.00014 $0.01437
Haiku 4.5 $0.00007 $0.00719

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

Security

Grade A, and why

dry-refactoring 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 10d 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.

dry-refactoring/SKILL.md · 965 lines

How it starts

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

DRY 标准化流程:从识别到重构

这个技能指导你系统性地应用 DRY (Don't Repeat Yourself) 原则,通过四步标准化流程消除代码重复,提升代码质量和可维护性。

When to Use This Skill

使用此技能当用户请求:

  • 消除代码重复或冗余
  • 重构有明显复制粘贴痕迹的代码
  • 应用 DRY 原则优化代码库
  • 识别并修复"代码坏味道"(如魔术数字、重复逻辑)
  • 提取公共逻辑为可复用单元
  • 改善代码的可维护性

关键触发词: DRY, 重复代码, 代码重复, 重构, 消除重复, 复制粘贴, 魔术数字, 代码坏味道, 抽象, 提取函数

核心思想

系统中的每一处知识都必须拥有一个单一、明确、权威的表示。

这意味着:

  • 任何业务逻辑、算法或配置信息都应该只存在于代码库的一个地方
  • 如果需要修改,你只需改这一个地方
  • 修改会自动反映到所有使用该逻辑的地方

两次法则 (Rule of Two): 当你第二次写下几乎相同的代码块时,警钟就应该敲响。这是开始重构的信号。

四步标准化流程

这是一个可在编码任何阶段应用的微循环。严格按照步骤执行,确保重构的安全性和有效性。


第一步:识别重复 (Identify Repetition)

目标: 像侦探一样,对代码中的"坏味道"保持警惕,找出所有重复。

1.1 明显的重复

直接复制粘贴

  • 两块或多块代码长得几乎一模一样
  • 只有变量名或少数值不同
  • 这是最明显、最需要被消除的重复

示例

// 重复 1
function calculateOrderDiscount(orderTotal) {
  if (orderTotal > 100) {
    return orderTotal * 0.1;
  }
  return 0;
}

// 重复 2
function calculateCouponDiscount(couponTotal) {
  if (couponTotal > 100) {
    return couponTotal * 0.1;
  }
  return 0;
}

"魔术数字"或字符串

  • 同一个配置值或字符串在多处以字面量形式出现
  • 例如:0.08"http://api.example.com"100

示例

# 魔术数字重复
def calculate_tax_1(amount):
    return amount * 0.08  # ❌ 魔术数字

def calculate_tax_2(amount):
    return amount * 0.08  # ❌ 再次出现

def calculate_total(amount):
    tax = amount * 0.08   # ❌ 第三次
    return amount + tax
1.2 语义上的重复

结构性重复

  • 代码结构相似,但具体变量名或值不同
  • 多个 if-else 结构都在做类似的条件判断和赋值

示例

// 结构性重复
function processUserData(user: User) {
  if (user.age >= 18) {
    user.status = 'adult';
  } else {
    user.status = 'minor';
  }
}

function processProductData(product: Product) {
  if (product.price >= 100) {
    product.category = 'premium';
  } else {
    product.category = 'standard';
  }
}

逻辑重复

  • 两个不同的函数,代码看起来不一样
  • 但它们在业务逻辑层面实现的是同一个目标

示例

// 逻辑重复:都在计算折扣,只是来源不同
function applyMembershipDiscount(price, memberLevel) {
  const discountRates = { gold: 0.2, silver: 0.1, bronze: 0.05 };
  return price * (1 - (discountRates[memberLevel] || 0));
}

function applySeasonalDiscount(price, season) {
  const discountRates = { winter: 0.2, spring: 0.1, summer: 0.05 };
  return price * (1 - (discountRates[season] || 0));
}

Read the full file on GitHub · 965 lines

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. 10d ago First seen · 965 lines · 70 tokens per session scan A c81091c2d9b2

Subscribe to this mod's changes

dry-refactoring is a skill published in the GitHub repository YYH211/Claude-meta-skill (277 stars, last pushed 3mo ago), licensed MIT. It adds 70 tokens to every session and 7,186 once invoked, about $0.0003 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.