ワンクリックで
deduplication
Find duplicated code and consolidate into shared utilities. Fixes all duplicates.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Find duplicated code and consolidate into shared utilities. Fixes all duplicates.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | deduplication |
| description | Find duplicated code and consolidate into shared utilities. Fixes all duplicates. |
Find duplicated code patterns and consolidate them into shared utilities.
No arguments? Describe this skill and stop. Do not execute.
mkdir -p .claude && echo '{"skill":"deduplication","started":"'$(date -Iseconds)'"}' > .claude/active-workflow.json
Consolidate toward code a master craftsperson would be proud of.
Duplication is a form of technical debt. The consolidated code must look like it was written by a skilled human engineer.
Test: Is the consolidated version clearer than having the code inline? If not, maybe duplication was acceptable.
Before starting, read these canon skills and apply their principles throughout:
Always load:
canon/composition/SKILL.mdcanon/clarity/SKILL.mdcanon/simplicity/SKILL.mdAuto-detect language canon (check files, load matches):
| Check | If found, also read |
|---|---|
*.ts or *.js files in target | canon/javascript/typescript/SUMMARY.md, canon/javascript/js-safety/SUMMARY.md, canon/javascript/js-perf/SUMMARY.md, canon/javascript/js-internals/SUMMARY.md, canon/javascript/functional/SUMMARY.md |
angular.json in project root | canon/angular/angular-arch/SUMMARY.md, canon/angular/angular-core/SUMMARY.md, canon/angular/angular-perf/SUMMARY.md, canon/angular/rxjs/SUMMARY.md |
package.json contains "react" | canon/javascript/react-state/SUMMARY.md, canon/javascript/react-test/SUMMARY.md, canon/javascript/reactivity/SUMMARY.md |
pom.xml or build.gradle in project | canon/java/SUMMARY.md |
*.py files in target | canon/python/python-advanced/SUMMARY.md, canon/python/python-idioms/SUMMARY.md, canon/python/python-patterns/SUMMARY.md, canon/python/python-protocols/SUMMARY.md |
*.cs files or *.csproj in project | canon/csharp/csharp-depth/SUMMARY.md, canon/csharp/type-systems/SUMMARY.md, canon/csharp/async/SUMMARY.md |
If a skill file doesn't exist (not installed in this project), skip it and continue. List loaded experts in EXPERTS_LOADED output.
Read both lessons files if they exist:
.claude/universal-lessons.md — universal patterns (ships with skills, applies to all projects).claude/lessons.md — project-specific patterns (accumulated from this project's runs)Use relevant lessons to guide your deduplication:
If a file doesn't exist, skip it and continue.
Search for duplicated patterns:
# Function definitions appearing in multiple files
grep -rn "function copy\|function hash\|execSync.*git" --include="*.ts" | grep -v test | grep -v node_modules
# Repeated utility patterns
grep -rn "createHash\|getGitCommit\|getGitRemote" --include="*.ts" | grep -v test | grep -v node_modules
For each pattern found in 2+ files:
For each TRUE duplicate:
Create shared utility in appropriate location:
src/utils/ for general utilitiessrc/shared/ for cross-module codehelpers.ts for module-specificExtract the function to shared location:
// src/utils/fs.ts
export function copyDirectoryRecursive(src: string, dest: string): void {
// consolidated implementation
}
Update all usages to import from shared:
import { copyDirectoryRecursive } from '../utils/fs.js';
Delete duplicate code from original locations
Verify - run build/tests:
npm run build
npm test
Document what was consolidated.
## Deduplication Fix: [path]
### Summary
| Metric | Value |
|--------|-------|
| Duplicates found | N |
| Consolidated | N |
| Kept separate | N |
### Consolidated
1. **copyDirectoryRecursive**
- Extracted to: `src/utils/fs.ts`
- Removed from: `src/canon/helpers.ts`, `src/workflow/index.ts`
- Usages updated: 5 files
2. **getGitCommit**
- Extracted to: `src/utils/git.ts`
- Removed from: `src/canon/index.ts`, `src/profiles/apply.ts`
- Usages updated: 3 files
### Kept Separate (with reason)
1. **hashDirectory** - Different algorithms for different manifest formats
### Verification
- Build: ✅ Pass
- Tests: ✅ Pass
EXPERTS_LOADED: [list of skill names actually read]
---
DUPLICATES_FOUND: N
CONSOLIDATED: N
KEPT_SEPARATE: N
DEDUPLICATION_COMPLETE: yes
When running as part of a pipeline (called by /build or /improve):
SCOPE CONSTRAINT: Only consolidate true duplicates. Do not refactor, rename, or restructure code that is not duplicated.
COMPLEXITY BUDGET: The consolidated version must be simpler than the duplicates it replaces. Net-zero or net-negative files, functions, and lines. EXCEPTION: Security fixes are exempt.
NO SILENT FAILURES: Do not change a throw/crash to a log-and-continue. Fail-fast on misconfiguration is always correct.
Only keep duplicates separate if:
"Might diverge in the future" is NOT a valid reason.
| Skill | Finds | Fixes |
|---|---|---|
/dedupe-scan | ✓ | ✗ (read-only) |
/deduplication | ✓ | ✓ (consolidates) |
Read-only quality scan of components. Reports problems without making changes. Uses software-base + domain profile skills.
Refactoring patterns - improving code design without changing behavior
Read-only quality scan of components. Reports problems without making changes. Uses software-base + domain profile skills.
Internal phase: independent Codex review + targeted fixes. Not user-facing.
Reference templates for Codex evaluation. Used by build/improve orchestrators — not executed directly.
Hard-ass code review via Gemini. ALL issues must be fixed. No exceptions.