Agent skill

Deduplicate Code

by rajbos in rajbos/ai-engineering-fluency

Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group…

MITAuto-check passedDevelopment

Install Deduplicate Code

skills CLI
$ npx skills add rajbos/ai-engineering-fluency --skill deduplicate-code -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rajbos/ai-engineering-fluency deduplicate-code --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rajbos/ai-engineering-fluency.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/deduplicate-code .claude/skills/deduplicate-code && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
deduplicate-code
GitHub stars
116
Token cost
~2.4k tokens
SKILL.md length
1,179 words
Files
1
Skills in repo
21
Repo updated
First seen
Licence
MIT

At a glance

Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group…

  • Works in 10 steps: List the duplicate groups → Read the instructions file → Understand the duplicate → …
  • A PR review notes duplication
  • SKILL.md covers What the detector does, Step 1 - List the duplicate…, Step 2 - Read the instructions… and Step 3 - Understand the…, plus 9 more sections
  • Calls npm, node and tsc

What it does

Deduplicate Code is an agent skill from rajbos/ai-engineering-fluency. Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group and extract a shared helper to eliminate it, keeping all tests green. Use when a PR review notes duplication, when the CI step summary's "Code Duplication Analysis" grows, or when asked to reduce code duplication / DRY up the codebase.

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Pull requests. It works with Visual Studio Code. The repository describes itself as: Extension that shows information about the estimated token usage and more of AI in editors/CLI's. The licence is MIT.

When your agent uses it

  • A PR review notes duplication
  • The CI step summarys Code Duplication Analysis grows
  • Asked to reduce code duplication / DRY up the codebase

Example prompts

  • “Code Duplication Analysis”
  • “/deduplicate-code”

Workflow steps

10 steps, taken from the step headings in SKILL.md.

  1. List the duplicate groups
  2. Read the instructions file
  3. Understand the duplicate
  4. Run the baseline tests
  5. Extract the shared helper
  6. Lint the changed files
  7. Re-run the detector on the changed files
  8. Run the full test suite and build
  9. Commit
  10. Open a PR

What it can do on your machine

Read from SKILL.md and the folder at commit 64b51e6. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npm
    • node
    • tsc
    • eslint

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Deduplicate Code loads about 2.4k tokens when it runs. Until then it costs about 113 tokens; SKILL.md has 1,179 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~113
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rajbos/ai-engineering-fluency at commit 64b51e6, republished under its MIT licence (© rajbos). 1,179 words, ~2,386 tokens.

Download SKILL.mdSave it as .claude/skills/deduplicate-code/SKILL.md (or your agent's skills folder).
name
deduplicate-code
description
Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group and extract a shared helper to eliminate it, keeping all tests green. Use when a PR review notes duplication, when the CI step summary's "Code Duplication Analysis" grows, or when asked to reduce code duplication / DRY up the codebase.

Deduplicate Code

The CI step summary runs check-code-duplication.js and reports copy-pasted blocks across the three TypeScript source trees every PR. A growing "Code Duplication Analysis" section (or a review finding of "this is duplicated") is the signal this skill remediates: it finds the duplicate groups, picks one, extracts a single shared helper in their place, and verifies nothing broke. Like refactor-large-function, it changes one group per pass so the diff stays reviewable and a regression points at a single extraction.

What the detector does

scripts/check-code-duplication.js (run as npm run check:duplicates from vscode-extension/) normalizes source lines (whitespace collapsed, comment-only and blank lines dropped so re-indented or re-commented copies are still caught), hashes sliding windows of a minimum length, groups identical windows, and extends each group to its maximal shared block. It reports clone groups as Markdown (for the step summary) or --json. It is report-only by default; this skill does the remediation the report asks for.

A "duplicate group" is a normalized sequence of >= --min-lines lines that occurs in two or more places (cross-file, or non-overlapping within one file).

Step 1 - List the duplicate groups

Get the current clone groups in machine-readable form so you can pick a target:

bash
node scripts/check-code-duplication.js --json --min-lines 14

Or, scoped to one area if the full scan is large:

bash
node scripts/check-code-duplication.js --json --min-lines 14 --include 'src/**/*.ts'

Read the groups array: each entry has lines (maximal block length), occurrences ({ file, startLine, endLine }), and a preview (first 3 lines). Pick the single group to remediate following these priorities:

  1. Skip auto-generated or intentionally-mirrored files. The shared editor adapters under src/adapters/*.ts and the per-editor CLI store modules (src/kilo.ts, src/opencode.ts, src/copilotCliStore.ts, src/devinCli.ts, src/hermes.ts) deliberately mirror each other's SQLite/stat helpers because each editor's session layout differs. A pure structural clone between two of these is usually NOT a safe extraction \u2014 only consolidate when the exact same logic (not just the same shape) is being copied.
  2. Prefer groups where every occurrence is genuinely identical behavior (same inputs, same outputs, same side effects) \u2014 those extract cleanly.
  3. Among those, prefer groups with the most occurrences (one helper replaces many copies) and the most lines (biggest payoff), all else equal.
  4. Prefer files that already have unit tests (check vscode-extension/test/unit/ for a matching test file) so the extraction is covered.

Step 2 - Read the instructions file

Before touching code, read the relevant sub-project instructions file for the area you are changing \u2014 .github/instructions/vscode-extension.instructions.md for vscode-extension/ work, .github/instructions/cli.instructions.md for cli/, and the root AGENTS.md for shared src/ (notably the "CLI Must Reuse Shared Functions" rule: never reimplement session parsing or cost attribution in a place the shared module already covers).

Step 3 - Understand the duplicate

Open every occurrence the detector reported and read the full block plus a few lines of surrounding context. Confirm it is a true behavioral duplicate and not two blocks that merely look the same but read different inputs or have different error handling. If the occurrences are only structurally similar (condemn both, then act), stop and pick a different group \u2014 forcing a shared helper onto divergent logic is the failure mode this skill exists to avoid.

Decide where the extracted helper lives:

  • Same file, used by two places in that file \u2192 a private helper (_ prefix) at the top of the file, like refactor-large-function.
  • Same package, multiple files \u2192 a private helper in the most natural existing module of that package (do not create a new file just to host the helper unless it is independently reusable \u2014 keep new files to a minimum).
  • Cross-package (e.g. shared src/ and vscode-extension/src) \u2192 the helper must live in the shared src/ module and be imported by the consumer, never copied. This is the canonical split documented in AGENTS.md.

Step 4 - Run the baseline tests

Establish a green baseline before changing anything:

bash
cd vscode-extension
npm ci --ignore-scripts
node_modules/.bin/tsc --noEmit        # type-check
npm run test:node                     # unit tests

Record which tests cover the target files so you know what to watch.

Show full SKILL.md (544 more words)Show less

Step 5 - Extract the shared helper

Apply the extraction. Rules:

  • The public/exported API must not change \u2014 only internal structure changes.
  • The helper takes the differences between the occurrences as parameters (the parts that were not actually identical) and encapsulates the common logic. If the occurrences have no meaningful differences, the helper has no parameters beyond the data it operates on.
  • Name the helper for what it does, not where it was copied from.
  • Use a leading _ prefix for private helpers in the same file.
  • Return null (not undefined) from a helper to signal an unrecoverable error or "nothing to do"; the caller guards with an early if (!result).
  • Do not add comments unless the code is genuinely non-obvious after extraction.
  • Replace every occurrence the detector reported for the chosen group with a call to the helper \u2014 leaving one copy behind defeats the point and the detector will still flag the group on the next run.

Step 6 - Lint the changed files

bash
cd vscode-extension && node_modules/.bin/eslint src ../src <changed-files>

All new warnings introduced by your changes must be resolved before proceeding. Pre-existing warnings on other functions in the same files are acceptable \u2014 do not fix unrelated code.

Step 7 - Re-run the detector on the changed files

Confirm the chosen group is gone and you did not introduce a new one:

bash
node scripts/check-code-duplication.js --json --min-lines 14

The group you remediated must no longer appear. If a new group appeared because your helper is itself now duplicated, that means the helper was placed in the wrong module \u2014 move it to the shared location and import it instead of copying.

Step 8 - Run the full test suite and build

bash
cd vscode-extension
node_modules/.bin/tsc --noEmit        # type-check
npm run test:node                     # unit tests
node esbuild.js --production          # production bundle

All tests must pass and the build must succeed. If a test fails, fix the extraction \u2014 do not modify the tests unless the test itself was wrong before your change.

Step 9 - Commit

refactor: extract shared helper to eliminate duplicate block in <area>

<Which group was chosen, where the helper lives, and how many copies it
replaced. Note that the duplication detector no longer flags the group.>

Step 10 - Open a PR

Open a pull request to main. The PR description should:

  • Lead with the motivation (duplication detector flagged the group, or a review noted the copy-paste).
  • List the occurrences that were consolidated (file:line for each) and the single helper that replaced them.
  • Confirm check-code-duplication.js no longer reports the group, all unit tests pass, and the production build succeeds.
  • Note any pre-existing warnings that were not introduced by this change.

Constraints

  • Remediate one duplicate group per pass \u2014 a second group is a separate PR. This keeps the diff reviewable and a regression attributable.
  • Do not consolidate editor adapter / per-editor store modules that are intentionally mirrored (see Step 1) unless the logic is behaviorally identical.
  • Do not change any exported function signatures or public class method signatures.
  • Do not create a new file solely to host the helper unless it is independently reusable across packages.
  • Do not fix pre-existing ESLint warnings on unrelated code.
  • If tsc or unit tests fail after your change, revert and choose a different extraction (or a different group) rather than patching around the failure.
  • scripts/check-code-duplication.js \u2014 the detector this skill drives.
  • vscode-extension/package.json \u2014 npm run check:duplicates script.
  • .github/workflows/ci.yml \u2014 the CI step that publishes the "Code Duplication Analysis" report to the step summary.
  • .github/skills/refactor-large-function/SKILL.md \u2014 the companion skill for functions that are too long rather than duplicated.
  • .github/instructions/vscode-extension.instructions.md, .github/instructions/cli.instructions.md, AGENTS.md \u2014 the area rules to read before editing (notably the shared-src/ reuse contract).

© rajbos, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/deduplicate-code of rajbos/ai-engineering-fluency.

Open the folder on GitHubat commit 64b51e6

Compare with similar skills

Deduplicate Code next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Deduplicate Code compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Deduplicate Code this skillrajbos/ai-engineering-fluency116—~2.4kAutomated safety check: PassMIT
Review PRmicrosoft/vscode-containers141—~900Automated safety check: PassCustom licence
Stewardyschimke/compose-ai-tools117—~2kAutomated safety check: PassApache-2.0
Code Reviewmicrosoft/vscode-containers141—~415Automated safety check: PassCustom licence
Promotion Brancheshardisgroupcom/sfdx-hardis401—~8.9kAutomated safety check: NotesAGPL-3.0
Render Evidenceyschimke/compose-ai-tools117—~1.4kAutomated safety check: PassApache-2.0

Similar skills

  • Review PR

    microsoft/vscode-containers

    Official

    Review a specific vscode-containers pull request on demand from the CLI (or any interactive agent), the way a Container Tools maintainer would.

    141 GitHub stars~900 tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Steward

    yschimke/compose-ai-tools

    Drive a pull request on this repository to green — which fast checks to run before pushing, how to read a red check, and what to do about a review comment.

    117 GitHub stars~2k tokensUpdated today
    DevelopmentAuto-check passed
  • Code Review

    microsoft/vscode-containers

    Official

    Review a pull request in this repository (the vscode-containers / Container Tools extension) when the automated reviewer has already supplied the diff and changed files.

    141 GitHub stars~415 tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Promotion Branches

    hardisgroupcom/sfdx-hardis

    How the promotion branches feature works (enablePromotionBranches, sf hardis:project:promotion:create) across sfdx-hardis and vscode-sfdx-hardis, and every file to touch when changing it.

    401 GitHub stars~8.9k tokensUpdated today
    DevelopmentAuto-check: notes
  • Render Evidence

    yschimke/compose-ai-tools

    Capture the before/after rendered PNGs a UI-affecting PR in this repository needs as visual evidence, including bringing an Android SDK up in a fresh sandbox.

    117 GitHub stars~1.4k tokensUpdated today
    MobileAuto-check passed
  • Walks the last step of a branch: confirm tests pass, detect the git environment, ask how to integrate, carry out your choice and clean up the worktree.

    296k GitHub starsUsed in 5 repos~1.9k tokens
    DevelopmentAuto-check passed

More from rajbos/ai-engineering-fluency

All 21 skills in this repo
  • Check Urls

    rajbos/ai-engineering-fluency

    Find all hardcoded URLs in TypeScript source files and verify they resolve (return HTTP 2xx/3xx).

    116 GitHub stars~662 tokensUpdated today
    Auto-check passed
  • Create Issue

    rajbos/ai-engineering-fluency

    Create a well-scoped GitHub issue in this repo. An agent skill from rajbos/ai-engineering-fluency.

    116 GitHub stars~2k tokensUpdated today
    Auto-check passed
  • Improve Tool Families

    rajbos/ai-engineering-fluency

    Analyze coverage of the vscode-extension's tool-family definitions (DEFAULTTOOLFAMILIES in vscode-extension/src/toolFamilies.ts) against the canonical tool-name list in src/toolNames.json and/or a…

    116 GitHub stars~1.3k tokensUpdated today
    Auto-check passed
  • Load Cache Data

    rajbos/ai-engineering-fluency

    Load and display the last 10 cache entries as raw JSON output.

    116 GitHub stars~3.2k tokensUpdated today
    Auto-check passed
  • PR Risk Review

    rajbos/ai-engineering-fluency

    Assess the risk of a changeset (a PR, a branch, or the working tree) and classify it as low, medium, or high with a written rationale.

    116 GitHub stars~2.6k tokensUpdated today
    Auto-check passed
  • Session Log Data

    rajbos/ai-engineering-fluency

    Describes the data files available in the coding agent environment after copilot-setup-steps runs.

    116 GitHub stars~1.7k tokensUpdated today
    Auto-check passed

Categories

Questions about Deduplicate Code

What does Deduplicate Code do?

Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group…. Deduplicate Code is an agent skill from rajbos/ai-engineering-fluency.js detector, then pick one duplicate group and extract a shared helper to eliminate it, keeping all tests green.

When should I use Deduplicate Code?

Deduplicate Code fits situations like: A PR review notes duplication; the CI step summarys Code Duplication Analysis grows; asked to reduce code duplication / DRY up the codebase.

How do I install Deduplicate Code in Claude Code?

Run `npx skills add rajbos/ai-engineering-fluency --skill deduplicate-code -a claude-code`. Or copy the skill folder (.claude/skills/deduplicate-code in rajbos/ai-engineering-fluency) into .claude/skills/deduplicate-code in your project. Claude Code loads it when a task matches its description.

How do I install Deduplicate Code in Codex?

Run `npx skills add rajbos/ai-engineering-fluency --skill deduplicate-code -a codex`. Or copy the skill folder (.claude/skills/deduplicate-code in rajbos/ai-engineering-fluency) into .agents/skills/deduplicate-code in your project. Codex loads it when a task matches its description.

Can I use Deduplicate Code in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rajbos/ai-engineering-fluency --skill deduplicate-code -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/deduplicate-code, .gemini/skills/deduplicate-code, .github/skills/deduplicate-code and .opencode/skills/deduplicate-code in your project.

What does Deduplicate Code need to run?

Going by SKILL.md and its folder, Deduplicate Code needs the command-line tools its instructions call (npm, node, tsc and eslint).

Does Deduplicate Code access the network?

SKILL.md contains no URLs. Its commands use npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Deduplicate Code safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Deduplicate Code use?

Deduplicate Code is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Deduplicate Code use?

About 2.4k tokens (SKILL.md is roughly 9.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Deduplicate Code?

Skills that share tags, products or a category with Deduplicate Code: Review PR (microsoft/vscode-containers, 141 stars), Steward (yschimke/compose-ai-tools, 117 stars), Code Review (microsoft/vscode-containers, 141 stars) and Promotion Branches (hardisgroupcom/sfdx-hardis, 401 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Deduplicate Code?

rajbos (a GitHub user) maintains it in rajbos/ai-engineering-fluency, which has 116 GitHub stars. The repository holds 21 skills in this directory. The repository was last updated on October 8, 2026.

Source: rajbos/ai-engineering-fluency on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.