jscpd v5 (Rust Engine)

July 23, 2026 · View on GitHub

The Rust engine is a ground-up rewrite of jscpd. It is a drop-in replacement for the Node.js CLI — same algorithm, same reporters, same .jscpd.json config — but 24-37x faster.

The Rust engine is distributed as two npm packages:

PackageInstalls commandsNotes
jscpd@5jscpdSame command name as v4; drop-in CLI replacement
cpdcpdLighter package, shorter command only
jscpd (crates.io)jscpd and cpdRust-native install; both binaries

All three install the identical Rust binary and accept the same CLI options. Only the crates.io install exposes both command names from a single package.

Performance

Benchmarks on macOS (Apple Silicon), 10 runs per target (3 for CopilotKit). v4 ran with --no-gitignore -i "node_modules" to ensure comparable file scanning. See performance-comparison.md for full methodology.

CodebaseFilesSizejscpd v4 (Node.js)cpd/jscpd v5 (Rust)Speedup
Multi-format fixtures5481.5 MB1.03s0.03s34.3x
Svelte source9K38 MB15.80s0.43s36.9x
CopilotKit17K159 MB82.89s3.44s24.1x

Installation

# npm — installs the jscpd command (same binary as v4 command name)
npm install -g jscpd@5
jscpd /path/to/code

# npm — installs only the cpd command (lighter)
npm install -g cpd
cpd /path/to/code

# crates.io — Rust-native install (exposes both jscpd and cpd commands)
cargo install jscpd
jscpd /path/to/code
cpd /path/to/code

# 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 jscpd

The npm packages ship prebuilt binaries for 6 platforms: macOS arm64/x64, Linux arm64/x64 (glibc/musl), Windows x64. No Node.js runtime is required — the binary is self-contained.

CLI Usage

The jscpd command is available after installing jscpd@5; the cpd command is available after installing either cpd (npm) or jscpd (crates.io). Both commands accept the same options and are identical:

jscpd [OPTIONS] [PATH]...
cpd [OPTIONS] [PATH]...

Options

OptionShortDescriptionDefault
--min-tokens-kMinimum tokens in a clone50
--min-lines-lMinimum lines in a clone5
--max-lines-xMaximum source file lines
--max-size-zSkip files larger than SIZE (e.g. 1kb, 1mb, 100kb)no limit
--mode-mDetection mode: mild, weak, strictmild
--workersNumber of worker threads for parallel tokenization/detectionauto (all CPU cores)
--no-colorsDisable ANSI color outputoff
--absolute-aUse absolute paths in reportsoff
--ignore-caseIgnore case of symbols in code (experimental)off
--formats-extsCustom format-to-extension mapping (e.g. javascript:es,es6;dart:dt)
--formats-namesCustom format-to-filename mapping
--cross-formatsDetect clones across formats: ;-separated groups of ,-separated formats (e.g. javascript,typescript). Preset js-ts = javascript,jsx,typescript,tsx
--listList all supported formats and exit
--skip-localSkip clones where both fragments are in the same directoryoff
--min-duplicated-linesMinimum percentage of duplication to report (0-100)0
--silent-sSuppress console outputoff
--no-tipsSuppress tips and promotional messagesoff
--version-VPrint version
--help-hPrint help

Reporters

13 built-in reporters:

ReporterOutput
consoleClone list + statistics table (default)
console-fullClone list with source snippets; with --blame shows side-by-side author comparison
jsonreport/jscpd-report.json
xmlreport/jscpd-report.xml
csvreport/jscpd-report.csv
htmlreport/jscpd-report.html
markdownreport/jscpd-report.md
badgereport/jscpd-badge.svg + report/jscpd-lines-badge.svg
sarifreport/jscpd-report.sarif (GitHub Code Scanning)
aiToken-efficient output for LLM pipelines
xcodeXcode-compatible warnings
thresholdExit 1 if duplication percentage exceeds --threshold
silentNo console output

Output file names differ from v4: v5 uses jscpd-report.* prefix (e.g. jscpd-report.json, jscpd-report.sarif) while v4 uses jscpd-report.json, html/ directory, etc.

Blame Output

With --blame --reporters console-full, clones are displayed with a side-by-side author comparison:

176 │ Andrii Kucherenko │ <= │ 196 │ Josh Soref │ ## TODO
177 │ Andrii Kucherenko │ <= │ 197 │ Josh Soref │
180 │ Andrii Kucherenko │ == │ 200 │ Andrii Kucherenko │ ## License

== means both lines were written by the same author; <= means different authors (potential copy).

Examples

# Drop-in replacement for jscpd v4
jscpd /path/to/source
# or
cpd /path/to/source

# Same flags as v4
cpd /path/to/source --min-tokens 30 --min-lines 3 --reporters console,json,html

# Git blame with side-by-side author comparison
cpd /path/to/source --blame --reporters console-full

# List supported formats
cpd --list

# Use multiple reporters with custom output
cpd ./src -r console,json,sarif -o ./reports

# Skip clones within the same directory
cpd --skip-local /path/to/source

Config File

v5 reads the same .jscpd.json config file format as v4:

{
  "path": ["./src"],
  "reporters": ["console", "json"],
  "minLines": 5,
  "minTokens": 50,
  "threshold": 0,
  "format": ["javascript", "typescript"],
  "ignore": ["**/node_modules/**"],
  "gitignore": true,
  "mode": "mild"
}

Format Support

v5 supports 223 formats (verified via --list). Use cpd --list to see the full list.

Cross-Format Detection

Vue SFC (.vue), Svelte (.svelte), Astro (.astro), and Markdown (.md) files are tokenized per-block/per-section, enabling duplicate detection across file types — same as v4.

Cross-Format Groups (--cross-formats)

By default every format is compared in its own isolated pool, so a TypeScript file never matches a near-identical JavaScript file. --cross-formats declares format equivalence groups that share one comparison pool — useful for finding leftover .js copies during a TypeScript migration:

cpd --cross-formats "javascript,typescript" ./src
cpd --cross-formats js-ts ./src                      # preset: javascript,jsx,typescript,tsx
cpd --cross-formats "js-ts;css,scss" ./src           # multiple groups

When a group mixes TypeScript (typescript/tsx) with JavaScript (javascript/jsx), TypeScript files are compared with erasable type syntax stripped from the detection token stream — type annotations, generics, interface/type declarations, as/satisfies, ?/! markers, access modifiers, implements clauses, type-only imports/exports, overload signatures, and declare statements. Reported clone positions always reference the original sources.

Config file equivalents (all three shapes are accepted):

{ "crossFormats": "javascript,typescript;css,scss" }
{ "crossFormats": ["javascript,typescript", "css,scss"] }
{ "crossFormats": [["javascript", "typescript"], ["css", "scss"]] }

Notes:

  • TypeScript syntax with runtime semantics is not erased and will not cross-match: enum, non-declare namespace, parameter properties (constructor(private x)), import x = require(), export =.
  • A cross-format clone is attributed to one member format in the per-format statistics.
  • Overlapping groups are merged; groups with fewer than two formats are ignored.

Differences from jscpd v4 (Node.js)

Featurejscpd v4 (Node.js)cpd v5 (Rust)
--blameCalls git CLI for each fileSame output (==/<= markers), calls git blame --porcelain per file
--store (LevelDB/Redis)Persistent store for large reposNot supported. Use jscpd v4.x for external stores.
--formats-extsCustom format-to-extension mappingSame flag name, same behavior
--formats-namesCustom format-to-filename mappingSame flag name, same behavior
Programming APIjscpd() Promise API, detectClones()Rust API via cpd-finder crate; no Node.js API
Config file.jscpd.json with camelCase keysSame — .jscpd.json with camelCase keys
Cross-format detectionVue SFC, Svelte, Astro, MarkdownSame — per-block tokenization
Token countsVaries by tokenizerMay differ by 1-2% due to Rust tokenizer; clone detection matches
--reportersAll v4 reportersAll v4 reporters except full (use console-full)
--no-gitignoreDefault respects .gitignoreSame behavior, same flag name
--workersNot availableAvailable — control parallelism for file tokenization/detection
Output filenamesjscpd-report.json, html/ directoryjscpd-report.json, jscpd-report.html, jscpd-report.sarif, jscpd-report.csv, jscpd-report.md, jscpd-badge.svg, jscpd-lines-badge.svg

Rust API

For integration in Rust applications:

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);

Architecture

cpd (CLI binary)
 ├── cpd-core      — Detection algorithm (Rabin-Karp rolling hash)
 ├── cpd-tokenizer — Language tokenization (223 formats)
 ├── cpd-finder    — File walking, orchestration, git blame
 └── cpd-reporter  — Output formatting (13 reporters)