Getting Started

Installation

Get started with jscpd.

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:

Terminal
curl -fsSL https://jscpd.dev/install.sh | bash

Install to a custom directory:

Terminal
curl -fsSL https://jscpd.dev/install.sh | bash -s -- --prefix ~/.local/bin

Install a specific version:

Terminal
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:

Terminal
npm install -g jscpd@5

Using cargo

If you have Rust installed, install directly from crates.io:

Terminal
cargo install jscpd

This installs both the jscpd and cpd commands.

Using Homebrew

If you use Homebrew on macOS or Linux:

Terminal
brew install jscpd

Using Nix

Install with Nix (installs both jscpd and cpd commands):

Terminal
nix profile install github:kucherenko/jscpd

Or run without installing:

Terminal
nix run github:kucherenko/jscpd -- /path/to/source

Using npx (No Installation)

Run jscpd directly without installing (downloads the native binary on first run):

Terminal
npx jscpd@5 /path/to/source

Using yarn

Terminal
yarn global add jscpd@5

Using pnpm

Terminal
pnpm add -g jscpd@5

Platform Binaries

Direct downloads are available for each platform:

PlatformPackage
macOS Apple Siliconcpd-darwin-arm64
macOS Intelcpd-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 x64cpd-windows-x64-msvc

v4 (TypeScript) — Maintenance

If you need the Node.js programmatic API, install v4:

Terminal
npm install -g jscpd@4
Terminal
# 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):

Terminal
jscpd /path/to/source

Use pattern matching

Scan specific file patterns:

Terminal
jscpd --pattern "src/**/*.js"

Generate HTML report

Create an HTML report of duplications:

Terminal
jscpd /path/to/source --reporters html

Configuration

Create a .jscpd.json file in your project root (compatible with both v4 and v5):

.jscpd.json
{
  "threshold": 0,
  "reporters": ["html", "console"],
  "ignore": ["**/__snapshots__/**", "**/node_modules/**"],
  "absolute": true
}

Rust Crate API (v5 only)

jscpd v5 provides Rust crates for programmatic integration:

Cargo.toml
[dependencies]
cpd-finder = "0.1"
src/main.rs
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:

Terminal
npm install -g jscpd-server
jscpd-server

Then check code for duplication:

Terminal
curl -X POST http://localhost:3000/api/check \
  -H "Content-Type: application/json" \
  -d '{
    "code": "console.log(\"hello\");\nconsole.log(\"world\");",
    "format": "javascript"
  }'