Thanks to visit codestin.com
Credit goes to jscpd.dev

API

API

Use jscpd programmatically in your applications.

Overview

jscpd offers three integration options:

HowBest for
CLIjscpd ./src --reporters jsonAny language — spawn the binary and parse the JSON report
Rust cratescpd-finder, cpd-core, cpd-tokenizer, cpd-reporterEmbedding detection in Rust applications
MCP servercpd --mcp <path>AI assistants (Claude, Cursor, Copilot) checking code as you write it

Rust Crate API

The core detection engine is available as Rust crates:

Cargo.toml
[dependencies]
cpd-finder = "0.1"
src/main.rs
use cpd_finder::orchestrate;

fn main() {
    let result = orchestrate(&["./src".into()], &Default::default());
    println!("Clones: {}", result.statistics.total_clones);
    println!("Duplication: {:.1}%", result.statistics.total_percentage);
}

Available Crates

CrateDescription
cpdCLI entry point (produces both jscpd and cpd binaries)
cpd-coreCore detection algorithm (Rabin-Karp rolling hash)
cpd-tokenizerSource code tokenizer (OXC for JS/TS, generic for 223 formats)
cpd-finderFile walking, orchestration, git blame
cpd-reporterOutput reporters

See Rust Crates for full documentation.

Rust Crate Features

  • Pure Rust — no external runtime required
  • Parallel detection across format groups via rayon
  • OXC-based JS/TS/JSX/TSX tokenization
  • Git blame enrichment (--blame)
  • Cross-format detection for Vue, Svelte, Astro, Markdown

CLI

The simplest integration from any language is the command line with a machine-readable reporter:

jscpd ./src --reporters json --output ./reports

See Installation and Configuration for full CLI options, and the JSON reporter for the report schema.

MCP Server

The binary serves the Model Context Protocol over stdio with cpd --mcp <path>, so AI assistants can check snippets and files against your project. See MCP Server.

Need a JavaScript/TypeScript API (import { jscpd } from 'jscpd')? It is available in v4 on the master-v4 branch — see the v4 page and the Migration Guide.