API
API
Use jscpd programmatically in your applications.
Overview
jscpd offers three integration options:
| How | Best for | |
|---|---|---|
| CLI | jscpd ./src --reporters json | Any language — spawn the binary and parse the JSON report |
| Rust crates | cpd-finder, cpd-core, cpd-tokenizer, cpd-reporter | Embedding detection in Rust applications |
| MCP server | cpd --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
| Crate | Description |
|---|---|
| cpd | CLI entry point (produces both jscpd and cpd binaries) |
| cpd-core | Core detection algorithm (Rabin-Karp rolling hash) |
| cpd-tokenizer | Source code tokenizer (OXC for JS/TS, generic for 223 formats) |
| cpd-finder | File walking, orchestration, git blame |
| cpd-reporter | Output 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 themaster-v4branch — see the v4 page and the Migration Guide.