Installation
v5 (Rust) — Recommended
jscpd v5 is a self-contained native binary — no Node.js runtime required. Install via curl, npm, or cargo.
Using curl (fastest)
One command installs the cpd binary for your platform:
curl -fsSL https://jscpd.dev/install.sh | bash
Install to a custom directory:
curl -fsSL https://jscpd.dev/install.sh | bash -s -- --prefix ~/.local/bin
Install a specific version:
curl -fsSL https://jscpd.dev/install.sh | bash -s -- --version 5.0.7
The script downloads from GitHub Releases (primary) and falls back to the npm registry. It supports macOS (arm64/x64), Linux (x64 glibc/musl, arm64 glibc), and Windows (x64 MSVC via Git Bash/WSL).
Using npm
The npm package installs a native binary for your platform:
npm install -g jscpd@5
Using cargo
If you have Rust installed, install directly from crates.io:
cargo install jscpd
This installs both the jscpd and cpd commands.
Using Homebrew
If you use Homebrew on macOS or Linux:
brew install jscpd
Using Nix
Install with Nix (installs both jscpd and cpd commands):
nix profile install github:kucherenko/jscpd
Or run without installing:
nix run github:kucherenko/jscpd -- /path/to/source
Using npx (No Installation)
Run jscpd directly without installing (downloads the native binary on first run):
npx jscpd@5 /path/to/source
Using yarn
yarn global add jscpd@5
Using pnpm
pnpm add -g jscpd@5
Platform Binaries
Direct downloads are available for each platform:
| Platform | Package |
|---|---|
| macOS Apple Silicon | cpd-darwin-arm64 |
| macOS Intel | cpd-darwin-x64 |
| Linux x64 (glibc) | cpd-linux-x64-gnu |
| Linux ARM64 (glibc) | cpd-linux-arm64-gnu |
| Linux x64 (musl/Alpine) | cpd-linux-x64-musl |
| Windows x64 | cpd-windows-x64-msvc |
v4 (TypeScript) — Maintenance
If you need the Node.js programmatic API, install v4:
npm install -g jscpd@4
# Or run without installing
npx jscpd@4 /path/to/source
v4 requires Node.js 18+ and provides the import { jscpd } from 'jscpd' API. See the Migration Guide for details on coexistence.
Basic Usage
Scan a directory
Run jscpd on your source code directory (same command in v4 and v5):
jscpd /path/to/source
Use pattern matching
Scan specific file patterns:
jscpd --pattern "src/**/*.js"
Generate HTML report
Create an HTML report of duplications:
jscpd /path/to/source --reporters html
Configuration
Create a .jscpd.json file in your project root (compatible with both v4 and v5):
{
"threshold": 0,
"reporters": ["html", "console"],
"ignore": ["**/__snapshots__/**", "**/node_modules/**"],
"absolute": true
}
Rust Crate API (v5 only)
jscpd v5 provides Rust crates for programmatic integration:
[dependencies]
cpd-finder = "0.1"
use cpd_finder::orchestrate;
fn main() {
let result = orchestrate(&["./src".into()], &Default::default());
println!("Found {} clones", result.statistics.total_clones);
}
Node.js API (v4 only)
If you need the programmatic JavaScript API:
import { IClone } from '@jscpd/core';
import { jscpd } from 'jscpd';
const clones: IClone[] = await jscpd(['', '', './src', '-r', 'json']);
console.log(clones);
Note: This API is only available in
jscpd@4. See the Migration Guide for alternatives in v5.
JSCPD Server
The server component (REST API + MCP) is still Node.js based and works with both versions. Install and run:
npm install -g jscpd-server
jscpd-server
Then check code for duplication:
curl -X POST http://localhost:3000/api/check \
-H "Content-Type: application/json" \
-d '{
"code": "console.log(\"hello\");\nconsole.log(\"world\");",
"format": "javascript"
}'