duck-refactor

duck-refactor is a skill for Claude Code from sprngr/rubber-duck. It costs 43 tokens per session (1,257 once invoked), scanned A, original, MIT.

A controlled method for restructuring code across multiple files while tracking every reference that may be affected.

In plain words
What is it for?
Renaming code across a codebase, extracting functions or classes, moving code between files, inlining code, and changing callbacks to promises.
Why use it?
It reduces the chance that a rename, move, extraction, or similar change leaves broken imports or callers behind.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: mentions subagents.

Part of the rubber-duck plugin — 17 skills shipped together

Good fit Renaming code across a codebase, extracting functions or classes, moving code between files, inlining code, and changing callbacks to promises.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/sprngr/rubber-duck/duck-refactor
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 sprngr/rubber-duck --skill duck-refactor
Clone the repo
git clone --depth 1 https://github.com/sprngr/rubber-duck

Made for: Claude Code.

Or install rubber-duck, the plugin that ships this one along with the rest of its 17 skills.

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/sprngr/rubber-duck/duck-refactor/github.svg)](https://agentmods.dev/skills/sprngr/rubber-duck/duck-refactor)
Your own site
<a href="https://agentmods.dev/skills/sprngr/rubber-duck/duck-refactor"><img src="https://agentmods.dev/badge/skills/sprngr/rubber-duck/duck-refactor/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 duck-refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/sprngr/rubber-duck/duck-refactor"><img src="https://agentmods.dev/badge/skills/sprngr/rubber-duck/duck-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 43 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,257 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 warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium Excessive Agency · line 119
    Skill enables autonomous high-impact decisions without human-in-the-loop verification. Critical operations (destructive commands, financial transactions, data deletion) should require explicit user confirmation.
    Fix: Add human-in-the-loop confirmation for destructive, irreversible, or high-impact operations. Never auto-execute commands that modify files, send data, or alter system state.
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.00043 $0.01257
Opus 5 $0.00022 $0.00629
Sonnet 5 $0.00009 $0.00251
Haiku 4.5 $0.00004 $0.00126

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

Security

Grade A, and why

duck-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 9d 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.

skills/duck-refactor/SKILL.md · 165 lines

How it starts

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

Structured refactoring 🦆. Multi-file restructuring with reference tracking.

Purpose

Support code restructuring through bounded refactoring operations with explicit reference tracking and verification.

Philosophy Guardrails (skill-local)

Inherit shared guardrails from references/GUARDRAILS.md.

Skill-specific delta:

  • Multi-file refactoring operations require execution approval with full reference tracking.
  • Distinguish from single-file patches and complexity reduction.

Activation

Use when user asks to refactor, extract, rename across files, move code, inline, or convert patterns.

Trigger phrases:

  • "refactor this"
  • "extract this function/class/method"
  • "rename this across the codebase"
  • "move this to another file"
  • "inline this function"
  • "convert this callback to promise"

Method

Subagent execution mode

When running as a subagent without a user channel (e.g., via duckling): do not apply edits or run verification commands. Execute steps 1-5 as analysis; replace step 6 "execute refactoring" and step 7 "verify" with approval-package content: the derived per-file change plan (diff blocks where applicable) and verification plan. Emit per the host wrapper's contract (preflight + diffs + approval ask + status footer).

1. Clarify refactoring scope

  • ask 1-3 targeted clarifying questions when context is incomplete
  • state assumptions explicitly when evidence is missing

Ask one scoping question if any detail unclear:

  • What to extract/rename/move/inline?
  • Target destination (new file, existing file, new function name)?
  • Scope boundaries (this module, whole codebase)?

2. Trace references and dependencies

Use read-only evidence gathering (similar to duck-debug trace mode):

  • Locate all usages of target code
  • Map imports/exports
  • Identify callers and callees
  • Find test files that reference target
  • Note external dependencies

Output: "Found N references across M files: [list]"

3. Present refactoring plan

Before any edits, present bounded plan:

Read the full file on GitHub · 165 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. 9d ago First seen · 165 lines · 43 tokens per session scan A 75a09ecf2aca

Subscribe to this mod's changes

duck-refactor is a skill published in the GitHub repository sprngr/rubber-duck (8 stars, last pushed 4d ago), licensed MIT. It adds 43 tokens to every session and 1,257 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-08-31.