Purpose
jscpd is a source code copy-paste (duplicate code) detection tool that supports over 220 language formats. It is aimed at developers and teams who need to check for code duplication before committing or in CI pipelines, helping to uncover copy-paste clones in a project and further providing analysis such as dead code, complexity hotspots, duplication trends, and codebase health scores.
Main Capabilities
Duplicate Detection
- Language-aware tokenization: all 224 formats are tokenized according to their respective language's comment and string rules, JavaScript/TypeScript/JSX/TSX use the oxc parser, and embedded language extraction is performed for Vue, Svelte, Astro, Markdown, and Razor, so clones are repeated sequences of language tokens rather than repeated fragments of text.
- Supports cross-format detection (Vue SFC, Svelte, Astro, Markdown), and clones can be matched between JavaScript and TypeScript via the --cross-formats group.
- Type-2 clones: via --ignore-identifiers, --ignore-literals, and --ignore-annotations, find code blocks that differ only in names, literal values, or annotations, reported as renamed.
- Type-3 near clones: --max-gap-lines N merges copies with a small number of inserted or modified lines into a single similar clone with a similarity score; --similarity compares entire functions of JavaScript, TypeScript, Python, Java, Kotlin, Scala, C#, Go, Rust, C, C++, PHP, Ruby, Swift, and Clojure by subtrees of the normalized syntax tree, and also applies to Markdown code blocks and components; renamed local variables and other literals can match, other called functions or operators do not match, and test files are excluded; the edn reporter lists each pair and its score.
- Type-4 semantic clones (experimental): --semantic uses a code embedding model to embed functions of JavaScript, TypeScript, Vue, Svelte, Astro, Python, Rust, Go, Java, Kotlin, C#, C, C++, PHP, Ruby,Scala, and Swift files, reporting functions written differently but functionally identical.
- Port progress and parity (experimental): jscpd --compare python/ typescript/ uses the same model to pair functions from two folders and lists the functions in each that already have a counterpart in the other.
- Clone types are labeled as exact, renamed, or similar in console, JSON, XML, HTML, Xcode, SARIF, and Code Climate output; the default run still reports only exact clones.
- --kind can keep only the clone types of interest, for example --kind renamed or --kind gap,ast.
- 15 reporters: console, console-full, json, xml, csv, html, markdown, badge, sarif, codeclimate, openmetrics, ai, xcode, threshold, silent.
- Clone baseline: --baseline .jscpd-baseline.json --fail-on-new-clones[=N] tolerates historical clones and fails the build only when a regression appears; --baseline-from-ref origin/main achieves the same effect without committing a file.
- Check only changed files: jscpd --changed . reports clones in the files listed by git status and matches them against the entire project, marking as new clones those that do not exist in HEAD; --changed-only compares only among changed files.
- Exit codes usable for gating: the exit code is 1 when --format is unknown, the scan path is missing, or a reporter cannot write to a file; --fail-on-empty fails when no files were analyzed.
- GitLab-ready reporters: codeclimate (gl-code-quality-report.json) and openmetrics (jscpd-metrics.txt) can be wired into artifacts:reports.
- Supports git blame and side-by-side author comparison (--blame --reporters console-full).
- --skip-local Only report clones across scan root directories; --skip-isolated ignores duplicates between monorepo folders owned by different teams.
Beyond duplicates
- --history: duplicate trends based on git history, scanning every commit within range and printing a mini chart, per-commit table, overall trend, and how much --threshold can be tightened.
- --dead-code: find code that no one runs, including unused files, exports, declarations, and imports in JavaScript, TypeScript, and Python; build the import graph from entry points and traverse it, dead code is reported in cascades, and each finding carries a confidence score. Also released as the standalone tool basta.
- --summary: derive refactoring hotspots directly from the scan, listing the top files and folders by token, line count, size, and complexity estimates.
- --complexity: complexity ranking only, without clone detection.
- --health: a 0-100 score and grade, based on duplication, dead code, or the proportion of code concentrated in complex files; size-aware, calibrated on 42 open-source projects, and can extend coverage, test, or security metrics via --health-input.
- --dashboard: summarizes project size, duplication by clone type, most complex files, and dead code categories on one screen under a health badge.
AI and operations
- --mcp: a built-in stdio-based MCP server with complete tool descriptions, allowing AI assistants to inspect the four types of clones between code snippets and the codebase, list clones for a file, and compare two folders function by function.
- --lsp: a stdio-based language server, with clones, similar functions, semantic clones, dead code, and complexity displayed as diagnostics in the edited file and following along as you type.
- AI reporter: token-efficient output for LLM pipelines (about 79% fewer tokens than console).
- Prebuilt for 8 platforms: macOS arm64/x64, Linux arm64/x64 (glibc and musl), Windows arm64/x64.
- --workers controls the parallelism of file tokenization and detection (uses all CPU cores by default).
- Configuration discovery: .jscpd.json, .config/jscpd.json, or in package.json the jscpd key.
- Symlinks are skipped by default unless --follow-symlinks is used.
- Stay quiet in pipelines: tips and sponsor lines are only printed in an interactive terminal; --no-tips, CI, or JSCPD_NO_TIPS can turn them off anywhere.
Usage
jscpd v5 is a Rust engine, released as a self-contained binary with no runtime required, distributed through two npm names (jscpd installs the jscpd command, cpd installs cpd), PyPI, crates.io, Homebrew, Nix, Docker, and GitHub Action. After installation, you can scan a project. By default, SARIF results are uploaded to GitHub Code Scanning.
In Super Linter and MegaLinter, both run jscpd with threshold: 0 by default, and any duplication fails the build, including pre-existing clones, which is the most common reason projects set VALIDATE_JSCPD: false. It is recommended to instead gate on new duplicates and remove the threshold: --baseline-from-ref scans the tree of the base ref with the same configuration and marks clones that do not exist there as new clones, and --fail-on-new-clones 0 fails the run when one appears. The base ref must be in the checkout (actions/checkout with fetch-depth: 0, or run git fetch origin main first), otherwise jscpd errors out and stops. jscpd needs the entire tree to find clones, so VALIDATE_ALL_CODEBASE: false does not narrow the scan range.
When multiple linters write to the same report directory, specify a separate filename for jscpd: --report-name sets the base name for json, xml, csv, html, markdown, sarif, and edn reports, defaulting to jscpd-report, and can also be set as reportName in .jscpd.json, or via the GitHub Action's report-name input. The name is a plain filename; paths, extensions, or empty names will error. badge, OpenMetrics Keep the CodeClimate files (jscpd-badge.svg, jscpd-metrics.txt, gl-code-quality-report.json) under their original names.
Use cases
- Duplicate code gating before commit or in CI pipelines.
- Duplicate and dead code governance for large projects and monorepos.
- Cross-language porting progress tracking (--compare).
- Letting AI agents check a codebase for clones via the MCP server.
- Viewing clones, similar functions, semantic clones, dead code, and complexity diagnostics in real time in the editor via LSP.
Limitations
- Type-4 semantic clones, porting progress and parity, and --compare are all experimental features.
- The default model for semantic clones is CodeRankEmbed (MIT), and jina-embeddings-v2-base-code can also be run; --semantic-models lists nine models and their calibrated thresholds, and --semantic-model selects one of them. When using a model not bundled with jscpd, point --semantic-url at an OpenAI-compatible embedding API (such as Ollama, LM Studio, or llama-server). The API key is read only from the JSCPD_SEMANTIC_API_KEY environment variable.
- A pair of functions within the same language requires a higher similarity than a cross-language pair; when using CodeRankEmbed, the two thresholds are 0.4125 and 0.6375 respectively.
- Dead code detection currently covers JavaScript, TypeScript, and Python.
- Symbolic links are skipped by default unless --follow-symlinks is used.
- Materials such as specific fees, prices, and platform support details are not provided.