Programming API

September 2, 2026 · View on GitHub

jscpd is a Rust engine. The CLI ships as the jscpd crate on crates.io (installs the jscpd and cpd binaries) and as the jscpd / cpd npm packages (prebuilt binaries); the engine itself is a set of library crates you can depend on directly.

Rust

Use the cpd-finder crate — it is the orchestration entry point and pulls in the tokenizer, detection core, and reporters:

[dependencies]
cpd-finder = "0.1"
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);

A complete, runnable version is in examples/rust-cpd-finder.

The jscpd crate's own library target is not a public API — it exists to share helpers with the crate's tests and may change in any release. Depend on the engine crates instead.

Crate Architecture

CrateDescription
cpd-coreCore data models and hashing (Rabin-Karp rolling hash)
cpd-tokenizerSource code tokenization (224 formats, uses oxc_parser for JavaScript/TypeScript) — pure, no I/O
cpd-finderFile walking, orchestration, git blame (rayon + ignore + globset)
cpd-reporterOutput format rendering (15 reporters)

See Packages for versions and paths.

Other languages

There is no Node.js (or other language) binding for the v5 engine. From another language, run the binary and read the json reporter's output (--reporters json --output <dir> writes <dir>/jscpd-report.json), or talk to it over the MCP stdio transport.

The TypeScript API of jscpd v4 (jscpd(), detectClones(), @jscpd/core, LevelDB/Redis stores) is maintained on the master-v4 branch and published as jscpd@4.