code-deduplicator
Skill3 starsChanged 6 months agoMITView on GitHub
Find duplicated code introduced or touched in the current session, then safely consolidate exact or low-risk duplicates while preserving behavior.
In this repository47 other files it gives its agents.
- agents-md-writerSkill
- ai-image-run-pacingSkill
- automation-state-reconcilerSkill
- backup-readiness-auditorSkill
- brand-voice-linterSkill
- case-study-writerSkill
- client-delivery-auditorSkill
- client-intake-builderSkill
- client-workspace-scaffolderSkill
- cold-outreach-writerSkill
- demo-animationSkill
- demo-animation-v2Skill
- discovery-briefSkill
- em-dash-removerSkill
- etsy-listing-optimizerSkill
- follow-up-radarSkill
- github-profile-proof-updaterSkill
- github-safe-publisherSkill
- idea-inboxSkill
- implement-client-feedbackSkill
- lead-scorerSkill
- llms-txt-generatorSkill
- local-app-public-demoSkill
- media-spec-checkerSkill
- obsidian-daily-noteSkill
- ops-status-reportSkill
- outreach-pipeline-designerSkill
- php-form-mailerSkill
- proposal-writerSkill
- release-announcement-writerSkill
- remove-ai-image-metadataSkill
- research-brief-curatorSkill
- research-to-articleSkill
- screen-recorderSkill
- session-handoffSkill
- skill-builderSkill
- skill-reviewerSkill
- social-campaign-proof-trackerSkill
- skill-nameSkill
- thumbnail-legibility-checkSkill
- thumbnail-set-designerSkill
- vault-janitorSkill
- verify-public-claimsSkill
- web-scraperSkill
- website-change-verifierSkill
- windows-reinstall-plannerSkill
- write-evidence-backed-profileSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
22 rules. About 0 are common, 16 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Do not rewrite unrelated code, change public APIs casually, or revert user work.
- Distinctive: line 14
Run git diff HEAD and git status to get the full picture of what was added or modified in this session.
- Very specific: line 20
If the diff is empty (everything is committed), run git diff HEAD~5..HEAD to cover recent session commits.
- Distinctive: line 25
Search for duplication in components and layouts:
- Very specific: line 28
Check for copy-pasted layout components (layout.tsx files with near-identical structure)
- Distinctive: line 29
Check for duplicated page-level patterns (similar data fetching, similar error boundaries, similar loading states)
- Distinctive: line 33
Search for duplication in functions and utilities:
- Very specific: line 36
Look for inline logic that duplicates existing utilities (e.g., hand-rolled formatDate when one exists in lib/)
- Distinctive: line 37
Check for duplicated fetch patterns, error handling wrappers, and auth checks
- Distinctive: line 41
Search for duplication in API routes and server logic:
- Distinctive: line 44
Check for duplicated middleware logic (auth, rate limiting, validation)
- Distinctive: line 55
If no duplication is found, say so and stop.
- Distinctive: line 61
Exact duplicates: Delete the new code, import the existing version, update all references.
- Distinctive: line 65
When extracting shared code:
- Very specific: line 66
Place utilities in lib/ or utils/ (whichever the project uses)
- Very specific: line 67
Place shared components in components/shared/ or components/ui/ (whichever exists)
- Very specific: line 68
Place shared hooks in hooks/
- Distinctive: line 69
Do not create new directories if equivalent ones already exist
- Distinctive: line 70
Do not refactor across ownership boundaries unless the existing codebase already has a shared location for that pattern
- Distinctive: line 71
If a deduplication would touch many files or alter behavior, leave a finding instead of editing
- Distinctive: line 77
Run the relevant tests and lint/type checks for the changed area.
- Distinctive: line 79
If tests or lint fail, fix the issues.
≈ “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
Code Deduplicator
You are a careful deduplication agent. Find duplication introduced or touched in the current session, then consolidate only when the refactor is low-risk and preserves existing behavior.
Do not rewrite unrelated code, change public APIs casually, or revert user work. If a duplication finding is risky or broad, report it instead of forcing a refactor.
Step 1: Identify What Changed
Run git diff HEAD and git status to get the full picture of what was added or modified in this session. Parse the diff to extract:
- New functions, components, hooks, constants, types, and utilities
- New inline logic patterns (string manipulation, fetch calls, validation, type guards, env checks, path handling)
- New API route handlers and middleware
If the diff is empty (everything is committed), run git diff HEAD~5..HEAD to cover recent session commits.
Step 2: Scan for Duplication (Run 3 Tasks in Parallel)
Task 1: Component & Layout Duplication
Search for duplication in components and layouts:
- Glob for
**/*.tsx,**/*.jsxfiles - For each new component from the diff, Grep the codebase for components with similar names, similar prop signatures, or similar JSX structure
- Check for copy-pasted layout components (
layout.tsxfiles with near-identical structure) - Check for duplicated page-level patterns (similar data fetching, similar error boundaries, similar loading states)
- Flag components that wrap the same underlying element with minor style/prop differences
Task 2: Logic & Utility Duplication
Search for duplication in functions and utilities:
- Glob for
**/*.ts,**/*.tsx,**/*.jsfiles - For each new utility/hook/function from the diff, Grep the codebase for similar implementations
- Look for inline logic that duplicates existing utilities (e.g., hand-rolled
formatDatewhen one exists inlib/) - Check for duplicated fetch patterns, error handling wrappers, and auth checks
- Flag near-identical hooks that differ only in endpoint or return shape
Task 3: API & Server Duplication
Search for duplication in API routes and server logic:
- Glob for
**/api/**/*.ts,**/routes/**/*.ts,**/middleware/**/*.ts - For each new route handler from the diff, Grep for similar route patterns
- Check for duplicated middleware logic (auth, rate limiting, validation)
- Flag handlers that share identical request parsing or response shaping logic
Step 3: Aggregate Findings
Collect results from all three tasks. For each finding, categorize as:
- Exact duplicate - same logic exists elsewhere. Use the existing one when references can be updated safely.
- Near duplicate - similar logic with minor differences. Extract a shared version only if the abstraction is clear and local patterns support it.
- Inline reimplementation - hand-rolled logic that an existing utility already handles. Replace with the utility call when behavior matches.
If no duplication is found, say so and stop. Do not invent problems.
Step 4: Refactor Safely
For each safe finding, apply the fix directly:
- Exact duplicates: Delete the new code, import the existing version, update all references.
- Near duplicates: Extract a shared function/component/hook to the appropriate shared directory (
utils/,hooks/,components/shared/,lib/). Update all call sites to use the shared version. - Inline reimplementations: Replace inline code with calls to the existing utility. Add imports.
When extracting shared code:
- Place utilities in
lib/orutils/(whichever the project uses) - Place shared components in
components/shared/orcomponents/ui/(whichever exists) - Place shared hooks in
hooks/ - Do not create new directories if equivalent ones already exist
- Do not refactor across ownership boundaries unless the existing codebase already has a shared location for that pattern
- If a deduplication would touch many files or alter behavior, leave a finding instead of editing
Step 5: Verify
Detect the project's verification commands from package scripts, README, Makefile, pyproject, or equivalent local configuration. Prefer existing commands over inventing new ones.
Run the relevant tests and lint/type checks for the changed area. If no verification command is discoverable, say that clearly and list the manual checks performed.
If tests or lint fail, fix the issues. The codebase must be in a passing state when you are done.
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.

