cpd
v5.3.0
Published
Copy/paste detector for programming source code — Rust engine, self-contained binary, installs the cpd command
Maintainers
Readme
jscpd — Rust engine
Copy/paste detector for programming source code. A self-contained binary that finds duplicated blocks across 224 language formats, writes reports in 15 formats and can fail CI when duplication grows.
Published as jscpd on npm (installs the jscpd command), cpd on npm (installs the cpd command), and jscpd on crates.io (installs both). Full documentation: jscpd.dev and docs/rust.md.
Install
npm
# installs the jscpd command
npm install -g jscpd
# installs only the cpd command
npm install -g cpdPrebuilt binaries for 8 platforms (macOS arm64/x64, Linux arm64/x64 with glibc or musl, Windows arm64/x64) — no Node.js runtime required.
crates.io
cargo install jscpd
# or, without compiling (prebuilt release binaries via cargo-binstall):
cargo binstall jscpdInstalls both jscpd and cpd binaries.
PyPI
Platform wheels carrying the same prebuilt binary, for Python toolchains and pre-commit hooks that should not need Node.js:
pip install jscpd # or: pipx install jscpd / uv tool install jscpd
uvx jscpd /path/to/code # run without installingInstalls both jscpd and cpd commands.
Nix
# Run without installing
nix run github:kucherenko/jscpd -- /path/to/code
# Install permanently
nix profile install github:kucherenko/jscpdHomebrew
brew install jscpdFrom source
git clone https://github.com/kucherenko/jscpd.git
cd jscpd/rust
cargo build --release
# binaries at target/release/jscpd and target/release/cpdQuick Start
jscpd .
jscpd ./src ./lib
jscpd . --blame --reporters console-full
jscpd . --reporters json,html
jscpd . --threshold 10
jscpd --baseline-from-ref origin/main --fail-on-new-clones .
jscpd --mcp .
jscpd --listArchitecture
jscpd/cpd (CLI binary)
├── cpd-core — Detection algorithm (Rabin-Karp rolling hash)
├── cpd-tokenizer — Language tokenization (224 formats)
├── cpd-finder — File walking, orchestration, baseline, git blame
└── cpd-reporter — Output formatting (15 reporters)| Crate | Purpose |
|-------|---------|
| jscpd | CLI binary and entry point (crates/cpd) |
| cpd-core | Detection algorithm, rolling hash, models |
| cpd-tokenizer | Language tokenization (224 formats); pure, no I/O |
| cpd-finder | File walking, orchestration, git blame |
| cpd-reporter | Output formatting (15 reporters) |
Current versions are in each crate's Cargo.toml; scripts/sync-version.mjs keeps them and the npm packages in step. The workspace layout, npm launcher packages and platform packages are described in docs/packages.md.
Programmatic Usage (Rust)
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);See docs/api.md and examples/rust-cpd-finder.
Building and testing
Requires Rust 1.96+ (the MSRV declared in Cargo.toml, enforced by the msrv
job in CI). Development uses the exact toolchain pinned in rust-toolchain.toml.
cargo build --release
cargo nextest run --workspace # or: cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all --check
# End-to-end run over the multi-format corpus (what CI's smoke job does)
./target/release/jscpd ../fixtures --reporters console,json --output ../smoke-report --min-tokens 50After changing the format table in crates/cpd-tokenizer/src/formats.rs, regenerate the root FORMATS.md with node scripts/gen-formats-md.mjs.
Benchmarks
Compared against other copy/paste detectors (jscpd-rs, Duplo, Fallow, Simian, PMD CPD) on the repository's fixtures/ corpus — timing, detection counts, cross-format detection and AI-token efficiency — in benchmark/BENCHMARK.md. Re-run with benchmark/benchmark.sh.
Documentation
- docs/rust.md — Full CLI reference, all options, reporters, baseline, summary, complexity, dashboard, config file
- docs/ai-ready.md — AI reporter, agent skills, MCP server
- docs/api.md — Rust API
- docs/ci-and-hooks.md — GitHub Action, Docker, pre-commit hooks
- CHANGELOG.md — Release notes
Coming from jscpd v4?
The CLI flags, .jscpd.json config and reporters are the same; see the migration table for the few differences. jscpd v4 (TypeScript engine, Node.js API, LevelDB/Redis stores) is maintained on the master-v4 branch and published as jscpd@4.
License
MIT
