Sandbox
@kucherenko/jscpd

Copy/paste detector for source code and AI agents

jscpd scans source trees for duplicated code blocks across 220+ formats and reports what it finds in multiple output styles. It can run as a CLI, a GitHub Action, or an MCP server, so builders can use it in local checks, CI, or agent workflows.

6,183 stars262 forksRustUpdated 7d ago
Who it's for

Builders who want their agent, CLI, or CI to spot duplicated code and report it clearly.

What it delivers

You can catch duplicate code early and review it in a format that fits your workflow.

What it does

Clone detection across many formats

Finds exact, renamed, and near-miss clones across 220+ language formats, including cross-format matches.

Rust CLI engine

Ships as a self-contained Rust binary with no runtime requirement at run time.

Multiple reporters

Outputs results in console, JSON, XML, HTML, SARIF, Code Climate, badge, markdown, Xcode, OpenMetrics, and AI-friendly formats.

Baseline mode for CI

Lets you fail on new duplication only, while tolerating existing clones with a saved baseline or branch reference.

GitHub Action

Runs as `kucherenko/jscpd@v5` and uploads SARIF to GitHub Code Scanning by default.

MCP server

Runs with `jscpd --mcp /path/to/project` so an agent can query duplication for snippets, files, and similarity checks.

Agent skills

Includes installable skills for the tool itself and a dry-refactoring workflow.

Summary and blame views

Adds codebase summary output and git blame-aware reporting for review and refactoring.

How to get it

  1. 1Run
    # macOS / Linux
    curl -fsSL https://jscpd.dev/install.sh | bash
    
    # Windows (PowerShell)
    irm https://jscpd.dev/install.ps1 | iex
    
    # No install — run once with npx (Node.js)
    npx jscpd .
  2. 2Then scan a project
    jscpd /path/to/code

README

jscpd

npm version npm downloads Crates.io Version NPM License jscpd CI Socket Badge OpenSSF Scorecard OpenSSF Best Practices

Copy/paste detector for programming source code. 220+ formats, exact, renamed and near-miss clones, Rust engine, self-contained binary, AI-ready with MCP server and token-efficient reporter.

Documentation: https://jscpd.dev

jscpd implements the Rabin-Karp algorithm to find duplicated code blocks across files. Opt-in passes extend it to blocks that differ only in names or values (Type-2) and to copies with a few edited lines or the same function structure (Type-3), each reported with its kind and a similarity score.

Quick Start

# macOS / Linux
curl -fsSL https://jscpd.dev/install.sh | bash

# Windows (PowerShell)
irm https://jscpd.dev/install.ps1 | iex

# No install — run once with npx (Node.js)
npx jscpd .

Then scan a project:

jscpd /path/to/code

Other install methods

MethodCommandNotes
npmnpm install -g jscpdInstalls the jscpd command; prebuilt binary, no Node.js at runtime
npm (cpd command)npm install -g cpdSame binary, exposed as cpd
PyPIpip install jscpdPlatform wheels with both commands; also pipx install jscpd, uv tool install jscpd, or uvx jscpd . to run without installing
Cargocargo install jscpdBuilds from crates.io; installs both jscpd and cpd
Homebrewbrew install jscpdmacOS / Linux
Nixnix run github:kucherenko/jscpd -- /path/to/codeOr nix profile install github:kucherenko/jscpd
Dockerdocker run --rm -v "$PWD:/src" ghcr.io/kucherenko/jscpd .Multi-arch image built from the release binaries

GitHub Action

- uses: kucherenko/jscpd@v5
  with:
    threshold: 5

Uploads SARIF results to GitHub Code Scanning by default. See CI & Pre-Commit Hooks for all inputs and outputs.

Documentation

DocumentDescription
Rust engineInstallation, CLI reference, reporters, baseline, summary, blame, config file
AI-ReadyAI reporter, agent skills, MCP server
Programming APIRust API (cpd-finder crate)
CI & Pre-Commit HooksGitHub Action, Docker image, pre-commit hooks
Packagesnpm packages and crates that make up a release
Supported formatsAll 224 formats with their file extensions
Runnable demosOne fixtures/<feature>-demo/ directory per feature, each README lists the commands with their expected output

Features

jscpd v5 is a Rust engine that ships as a self-contained binary — no runtime required — under two npm names (jscpd installs the jscpd command, cpd installs cpd), on PyPI, crates.io, Homebrew, Nix, Docker, and as a GitHub Action.

  • 224 language formats with cross-format detection (Vue SFC, Svelte, Astro, Markdown) and --cross-formats groups to match clones across JavaScript and TypeScript
  • Prebuilt for 8 platforms — macOS arm64/x64, Linux arm64/x64 (glibc and musl), Windows arm64/x64
  • Type-2 clones--ignore-identifiers, --ignore-literals and --ignore-annotations find blocks that differ only in names, literal values or annotations, reported as renamed (see docs)
  • Type-3 near-miss clones--max-gap-lines N merges a copy with a few inserted or changed lines into one similar clone with a similarity score; --similarity 0.85 compares whole JavaScript/TypeScript functions by syntax-tree structure, so renames and scattered edits are still caught (see docs)
  • Clone kinds in every reporterexact, renamed or similar in the console, JSON (kind, similarity, method), XML, HTML, Xcode, SARIF (jscpd/duplicate-code, jscpd/renamed-code, jscpd/similar-code) and Code Climate output; default runs report only exact clones and are unchanged
  • 15 reporters: console, console-full, json, xml, csv, html, markdown, badge, sarif, codeclimate, openmetrics, ai, xcode, threshold, silent
  • Clone baseline — gate CI on new duplication only. --baseline .jscpd-baseline.json with --fail-on-new-clones[=N] tolerates legacy clones and fails the build on regressions; --baseline-from-ref origin/main does the same without a committed file (see docs)
  • GitLab-ready reporterscodeclimate (gl-code-quality-report.json) and openmetrics (jscpd-metrics.txt) plug into artifacts:reports
  • Git blame with side-by-side author comparison (--blame --reporters console-full)
  • --summary — codebase summary: top files and folders by tokens, lines, size, and a complexity estimate — refactoring hotspots straight from the scan (see docs)
  • --mcp — built-in MCP server over stdio with fully described tools: point your AI assistant at the binary and it can check snippets for duplication against your codebase, or find structurally similar functions with a similarity argument (see docs)
  • AI reporter — token-efficient output for LLM pipelines (~79% fewer tokens than console)
  • --skip-local — report only clones that cross the scan roots: with jscpd packages/api packages/web --skip-local, pairs inside one of the two trees are dropped and only api-to-web duplication remains
  • --skip-isolated — ignore duplication between monorepo folders owned by different teams (--skip-isolated "packages/team-a|packages/team-b")
  • --workers — control parallelism for file tokenization and detection (default: all CPU cores)
  • Config discovery.jscpd.json, .config/jscpd.json, or the jscpd key in package.json
  • Quiet in pipelines — tips and sponsor lines print only on an interactive terminal; --no-tips, CI or JSCPD_NO_TIPS switch them off everywhere

See the Rust docs for the full CLI reference and rust/CHANGELOG.md for release notes.

Looking for v4?

jscpd v4 (TypeScript engine, Node.js API, LevelDB/Redis stores) is maintained on the master-v4 branch and published as jscpd@4 / the latest-4 dist-tag. README-v4.md describes it in one page (install, CLI, API, packages, maintenance policy); the same content is at https://jscpd.dev/getting-started/v4.

Packages

PackageRegistryDescription
jscpdnpmInstalls the jscpd command (prebuilt binary via platform packages)
cpdnpmInstalls the cpd command (same binary)
jscpd-<platform>npmPlatform binary packages pulled in as optional dependencies: jscpd-darwin-arm64, jscpd-darwin-x64, jscpd-linux-x64-gnu, jscpd-linux-arm64-gnu, jscpd-linux-x64-musl, jscpd-linux-arm64-musl, jscpd-windows-x64-msvc, jscpd-windows-arm64-msvc
jscpdPyPIPlatform wheels repacked from the release binaries; installs both jscpd and cpd commands
jscpdcrates.ioCLI crate; installs both jscpd and cpd binaries
cpd-corecrates.ioDetection algorithm (Rabin-Karp rolling hash), data models
cpd-tokenizercrates.ioSource code tokenization (224 formats)
cpd-findercrates.ioFile walking, orchestration, git blame — the library entry point
cpd-reportercrates.ioOutput formatting (15 reporters)

Who Uses jscpd

The jscpd npm package is downloaded 10M+ times per month, and ~5,000 repositories declare it on GitHub's dependents graph.

Bundled by analysis platforms:

  • GitHub Super Linter — official GitHub linter aggregator, bundles jscpd as its copy/paste detector and runs it by default; 15,500+ workflow files on GitHub reference Super Linter (as of Sep 2026)
  • MegaLinter — open-source linter aggregator for CI, ships jscpd in every flavor including ci_light
  • Codacy — automated code analysis platform, jscpd powers the duplication engine

Explicitly enabled in Super Linter (VALIDATE_JSCPD: true) by dozens of public repositories, including:

  • A2A — Google's Agent2Agent protocol (25k+ stars)
  • RimSort — mod manager for RimWorld (1.2k+ stars); also runs jscpd directly with its own .jscpd.json
  • Contact Center AI samples — official Google Cloud samples, with a dedicated jscpd config
  • Drifty — open-source download manager

Used in notable projects:

Benchmark

Compared against other copy/paste detectors on the fixtures/ corpus (547 files, 150+ formats), default thresholds, wall-clock time on Apple Silicon:

ToolTimeFilesClonesDup Lines
jscpd84ms3472129,133
jscpd-rs111ms36022210,317
Duplo162ms31951813,049
Fallow dupes164ms34103,137
Simian964ms54742415,351
PMD CPD35.980s71562,267

Methodology, cross-format detection and AI-token-efficiency comparisons: benchmark/BENCHMARK.md. Re-run with benchmark/benchmark.sh.

AI-Ready Features

jscpd integrates into AI-powered workflows through three mechanisms:

AI Reporter

Token-efficient output for LLM pipelines (~79% fewer tokens than the default console reporter):

jscpd --reporters ai /path/to/source              # compact clone list
jscpd --reporters ai --summary /path/to/source    # + compact codebase summary

Agent Skills

Two installable skills that teach AI coding assistants how to use jscpd and refactor detected duplications:

SkillPurposeInstall
jscpdTool reference — CLI options, AI reporter format, config syntaxnpx skills add kucherenko/jscpd --skill jscpd
dry-refactoringGuided refactoring workflow — read clones, choose strategy, apply, verifynpx skills add kucherenko/jscpd --skill dry-refactoring

After installation, ask your agent to "find and fix code duplication" and it will invoke jscpd with the right options and act on the results.

MCP Server

jscpd --mcp /path/to/project scans once and serves the Model Context Protocol over stdio, so an assistant can check any snippet for duplication against the codebase on demand, list a file's clones, re-scan the working directory, and look for structurally similar functions by passing similarity.

See AI-Ready docs for full details.

Contributing

See CONTRIBUTING.md for the development setup, test policy, and pull request requirements. In short:

cd rust
cargo nextest run --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all --check

Security issues go through the security policy, not public issues.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

MIT © Andrey Kucherenko

Files in the repo

Repository payload26 top-level entries
  • .github
  • assets
  • benchmark
  • docs
  • examples
  • fixtures
  • rust
  • skills
  • .editorconfig
  • .gitignore
  • .jscpd.json
  • .pre-commit-hooks.yaml
  • .prettierignore
  • action.yml
  • CODE_OF_CONDUCT.md
  • CONTRIBUTING.md
  • Dockerfile
  • flake.lock
  • flake.nix
  • FORMATS.md
  • glama.json
  • LICENSE
  • pyproject.toml
  • README-v4.md
  • README.md
  • SECURITY.md

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More tools

JuliusBrussee/
caveman

🪨 why use many token when few token do trick — Claude Code skill that cuts 65% of tokens by talking like caveman

105k
1 add
MemPalace/
mempalace

The best-benchmarked open-source AI memory system. And it's free.

59k
stablyai/
orca

Orca is the ADE for working with a fleet of parallel agents. Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

66k

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

132k

Never stop coding. Free MIT AI gateway: one endpoint, 352 providers (150+ free), 1200+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 550+ contributors

64k
headroomlabs-ai/
headroom

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

71k