refactor-clean

refactor-clean is a skill for Claude Code, Codex from dzhng/duet-agent. It costs 59 tokens per session (2,158 once invoked), scanned A, a copy of refactor-clean, Apache-2.0.

A code-refactoring workflow for giving each idea one clear home in a codebase. Refactoring means changing internal structure without changing the intended behavior.

In plain words
What is it for?
For consolidating duplicate owners, splitting overloaded modules, moving concepts to the right place, and removing stale compatibility paths.
Why use it?
It removes duplicated concepts, obsolete wrappers, parallel abstractions, and modules that have accumulated too many responsibilities.

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/dzhng/duet-agent/refactor-clean
Any agent
npx skills add dzhng/duet-agent --skill refactor-clean
Clone the repo
git clone --depth 1 https://github.com/dzhng/duet-agent

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/dzhng/duet-agent/refactor-clean.svg)](https://agentmods.dev/skills/dzhng/duet-agent/refactor-clean)
Your own site
<a href="https://agentmods.dev/skills/dzhng/duet-agent/refactor-clean"><img src="https://agentmods.dev/badge/skills/dzhng/duet-agent/refactor-clean.svg" alt="Measured on agentmods" height="20"></a>
Per session 59 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,158 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 88% copy Near-identical to another mod 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.00059 $0.02158
Opus 5 $0.00030 $0.01079
Sonnet 5 $0.00012 $0.00432
Haiku 4.5 $0.00006 $0.00216

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

Security

Grade A, and why

refactor-clean 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 5d 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.

Origin

This is a copy

88% identical to refactor-clean — 11 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.agents/skills/refactor-clean/SKILL.md · 148 lines

How it starts

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

Clean Refactoring

Replace the old shape with the simpler shape the codebase would want if it were designed today. Refactoring is not adding a compatibility layer beside the problem; it is moving ownership until every concept has exactly one clear home. That cuts both ways: merging N duplicated owners into one, and splitting one over-loaded module into the several owners it was hiding.

Workflow

  1. Name the concept that lacks one clear owner — duplicated across several owners, or several concepts fused into one over-loaded module. Identify the thing(s) that should each have one owner: environment, pricing rule, geometry source, state machine, data contract, renderer phase, API shape, UI state, or test oracle.
  2. Find every current owner and consumer. Treat wrappers, aliases, pass-local constants, copied structs, and "temporary" branches as sediment until proven otherwise.
  3. Promote the concept to its natural home. Pick the module that would own it from scratch, then make old call sites consume that owner directly.
  4. Delete or collapse the stale path in the same pass when feasible. If a bridge must remain, make it tiny, named as compatibility, and give it a removal condition.
  5. Verify behavior through consumers, not just the new module. A clean refactor is only proven when the surfaces that used to diverge now report or exercise the same source of truth.

Rules

  • Every line is debt — the best mechanism is the one you don't write. Before building any guard, validator, convergence protocol, or cleanup path, two checks gate it:
    1. Does the platform already do this? Read the component/framework you are working around before coding around it — its crons, retries, defaults, and lifecycles. A hand-built janitor beside a component that already vacuums itself is pure debt, and it will be debugged by someone who doesn't know the component made it unnecessary.
    2. Does the failure it guards change any real outcome? Trace the guarded condition to its consumer. If the consumer is indifferent — an ordering check feeding a consumer that doesn't care about order, a validation on data only our own code produces — the guard tests nothing and must not be written. A common shape: an invariant re-checked at read time that the single write path already establishes, so the branch can only fire on hand-corrupted rows. Ask which caller could produce the bad state; if the honest answer is "none, short of someone editing the database", delete the branch. "It could be inconsistent" is not a reason; "the consumer would then do the wrong thing" is. The bar is not "is this correct?" — defensive code is usually correct. The bar is "what breaks, for whom, if this line doesn't exist?" No concrete answer → no line.
  • Measure the change, and treat a bad size-to-behaviour ratio as a shape defect. Before accepting a change, count what it actually cost — production code apart from tests and docs, and comments apart from logic, because a diff dominated by explanation is not the same as one dominated by machinery:

Read the full file on GitHub · 148 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. 5d ago First seen · 148 lines · 59 tokens per session scan A ace3b796545e

Subscribe to this mod's changes

refactor-clean is a skill published in the GitHub repository dzhng/duet-agent (42 stars, last pushed 3d ago), licensed Apache-2.0. It adds 59 tokens to every session and 2,158 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. It is 88% identical to refactor-clean, differing in 11 lines, and is treated as a copy.

Related

Other skills, from other repositories