duplication-sweep
Skill1 starsChanged 4 months agoMITView on GitHub
Use for a scheduled or on-demand sweep of an existing codebase to find accumulated duplication, redundant utility modules, and dead code. Produces a ranked report for a human to act on rather than a pull request. Trigger on "what's duplicated in this repo", "find dead code", "weekly cleanup sweep", or as a recurring routine.
In this repository2 other files it gives its agents.
- duplication-reviewSkill
- reuse-firstSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Do not sweep the whole repo.
- Distinctive: line 39
Lines removed: if consolidated
- Distinctive: line 46
Keep "safe, do it now" separate from "real duplication, but risky to merge and needs a decision." Collapsing those two into one list is …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Duplication Sweep
The periodic pass. The codebase has already accumulated duplication, and the job is to find the parts worth consolidating and rank them so a human can choose.
Produce a report. Do not open a pull request. Consolidation touches shared code, which means blast radius. The finding is cheap and safe; the change is neither. A human decides.
Scope one run
Do not sweep the whole repo. A report on everything gets read by nobody. Pick one of these per run and state which you picked:
- One directory or package
- One category: date handling, HTTP clients, validation, error construction, config access, logging, retries
- Everything touched in the last N weeks, which is the code most likely to have been recently duplicated
Rotate the scope between runs so coverage accumulates instead of repeating.
What to look for
Near-duplicate functions. Same behavior, different name or location. The main prize. Search by behavior vocabulary and by shared magic constants, not by name.
Copy-paste blocks. Runs of similar lines differing only in a literal or a field name. Concentrate on large files and on siblings within one directory.
Redundant utility modules. Two files that are both "the string helpers." A utils/ and a helpers/ with overlapping contents. Three different date formatters.
Reimplemented builtins. Hand-rolled versions of what the standard library or an installed dependency already provides.
Dead code. Exported functions with zero callers, unreachable branches, permanently-enabled feature flags, commented-out blocks. Before calling anything dead, check for dynamic references: reflection, string-based dispatch, dependency injection, config-driven registration, and test-only usage.
Rank by payoff, not by count
Finding a hundred duplicates is not useful. Ranking six of them is. For each candidate, estimate:
- Lines removed if consolidated
- Call sites affected, which is the risk side of the trade
- Blast radius: private to one module, or exported across packages
- Confidence that these are genuinely the same thing
The best items are high lines removed, few call sites, high confidence. Those are the safe wins and they go at the top.
Keep "safe, do it now" separate from "real duplication, but risky to merge and needs a decision." Collapsing those two into one list is what makes cleanup reports unusable.
Report format
## Sweep: <scope> — <date>
**Verdict:** <one line>
### Safe wins
1. <what> — <files> — removes ~N lines, M call sites, confidence: high
Recommendation: <specific action>
### Needs a decision
1. <what> — <why it is not obviously safe> — <the actual question for the human>
### Dead code candidates
1. <what> — <how you checked for dynamic usage>
### Checked, found clean
<so the next run does not redo this>Track it over time
Append each run's headline numbers to a log in the repo, for example docs/sweeps/: scope, candidates found, lines identified, what actually got actioned.
One sweep is a chore. A trend line answers the question you actually care about, which is whether the codebase is getting better or worse. It also makes the cost of skipping cleanup visible to people who do not read diffs.
Honest limits
State plainly what you could not check. Static search misses dynamic dispatch. Cross-language duplication is invisible to most searches. If the scope turned out too large to cover properly, say what you skipped rather than implying full coverage. A sweep that overstates its coverage is worse than no sweep, because it retires the question.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

