Fast copy/paste detector for programming source code. Rust rewrite of jscpd, supports 224 language formats.
jscpd v5 is the Rust engine — a self-contained binary. The TypeScript engine (v4) is maintained on the
master-v4branch and published asjscpd@4.
| Package | Installs | When to use |
|---|---|---|
jscpd |
jscpd |
Default install; the jscpd command |
cpd |
cpd |
Shorter command name only |
basta |
basta |
Dead code, not duplication — a separate binary |
jscpd and cpd install the identical Rust binary. For both jscpd and cpd command names from a single install, use crates.io: cargo install jscpd.
# npm — installs the jscpd command
npm install -g jscpd
# npm — installs only the cpd command
npm install -g cpd
# crates.io — installs both jscpd and cpd binaries
cargo install jscpd
# dead code detection — a separate binary and a separate npm package
npm install -g basta
cargo install basta
# Nix — run without installing
nix run github:kucherenko/jscpd -- /path/to/code
# Nix — install permanently
nix profile install github:kucherenko/jscpd
# Homebrew (macOS/Linux)
brew install jscpdPrebuilt binaries for 8 platforms (macOS arm64/x64, Linux arm64/x64 with glibc or musl, Windows arm64/x64) — no Node.js runtime required.
# Scan current directory
cpd .
# Scan specific paths
cpd ./src ./lib
# Minimum tokens/lines for a clone
cpd . --min-tokens 30 --min-lines 3
# Git blame with side-by-side author comparison
cpd . --blame --reporters console-full
# Output to JSON + HTML
cpd . --reporters json,html
# Fail CI if duplication exceeds threshold
cpd . --threshold 10
# List all supported formats
cpd --list| Flag | Short | Default | Description |
|---|---|---|---|
--min-tokens |
-k |
50 | Minimum tokens to consider a duplicate |
--min-lines |
-l |
5 | Minimum lines to consider a duplicate |
--max-lines |
-x |
— | Maximum lines per duplicate block |
--mode |
-m |
mild | Detection mode: mild, weak, strict |
--skip-comments |
— | — | Alias for --mode weak |
--format |
-f |
all | Comma-separated formats to check |
--ignore-pattern |
-i |
— | Glob patterns to ignore |
--reporters |
-r |
console | Comma-separated reporters |
--output |
-o |
report | Output directory for file reporters |
--config |
-c |
— | Path to config file (.jscpd.json) |
--threshold |
-t |
— | Max duplication % before exit 1 |
--blame |
-b |
— | Enrich clones with git blame data |
--skip-local |
— | — | Skip clones within the same directory |
--skip-isolated |
— | — | Skip clones between isolated monorepo folders (e.g. packages/a|packages/b) |
--silent |
-s |
— | Suppress console output |
--list |
— | — | List all supported formats and exit |
For the full options list, see docs/rust.md.
| Reporter | Output |
|---|---|
console |
Clone list + statistics table (default) |
console-full |
Source snippets + blame comparison |
json |
report/jscpd-report.json |
html |
report/jscpd-report.html |
sarif |
report/jscpd-report.sarif (GitHub Code Scanning) |
ai |
Token-efficient output for LLM pipelines |
badge |
report/jscpd-badge.svg + report/jscpd-lines-badge.svg |
Plus: xml, csv, markdown, xcode, threshold, silent.
Create .jscpd.json in your project root:
{
"minTokens": 30,
"minLines": 3,
"format": ["javascript", "typescript", "python"],
"ignorePattern": ["node_modules", "dist", "*.min.js"],
"reporters": ["console", "json"],
"output": "report",
"threshold": 5,
"blame": false
}Vue SFC (.vue), Svelte (.svelte), Astro (.astro), and Markdown files are tokenized per-block, enabling duplicate detection across file types.
use cpd_finder::orchestrate::{RunConfig, run};
let config = RunConfig {
paths: vec!["./src".into()],
min_tokens: 50,
..Default::default()
};
let result = run(&config).unwrap();
println!("Found {} clones", result.clones.len());
println!("Analyzed {} files", result.statistics.total.sources);cpd (CLI binary)
├── cpd-core — Detection algorithm (Rabin-Karp rolling hash)
├── cpd-tokenizer — Language tokenization (224 formats)
├── cpd-finder — File walking, orchestration, git blame
└── cpd-reporter — Output formatting (15 reporters)
See docs/rust.md for detailed documentation and the v4 migration table, and docs/api.md for the Rust API.
MIT