jscpd
Officialjscpd
面向编程源代码的复制/粘贴检测器。支持 224+ 种格式。通过 MCP 服务器和 token 高效报告器实现 AI 就绪。现在有了 Rust 引擎 — 速度快 24-37 倍。
jscpd 使用 Rabin-Karp 算法来查找跨文件的重复代码块。
快速开始
# Install (all platforms — installs the jscpd command)
curl -fsSL https://jscpd.dev/install.sh | bash
# TypeScript engine (Node.js, v4.x)
npm install -g jscpd@4
jscpd /path/to/code
# or use without installing
npx jscpd@4 /path/to/code
# Rust engine (v5.x, 24-37x faster) — installs the jscpd command
npm install -g jscpd@5
jscpd /path/to/code
# Rust engine — cpd command only
npm install -g cpd
cpd /path/to/code
# Rust-native install (exposes both jscpd and cpd)
cargo install jscpd
# Nix (installs both jscpd and cpd)
nix run github:kucherenko/jscpd -- /path/to/code
# or install permanently
nix profile install github:kucherenko/jscpd
# Homebrew (macOS/Linux)
brew install jscpdRelated MCP server: tree-sitter-analyzer
文档
Document | Description |
Node.js 引擎 — CLI、报告器、配置、检测模式 | |
Rust 引擎 — 安装、CLI、报告器、blame、Rust API | |
AI 报告器、Agent 技能、MCP 服务器 | |
TypeScript 和 Rust 编程 API | |
GitHub Action、pre-commit 钩子 | |
Monorepo 包和 crate 概览 |
双引擎
TypeScript (v4) | Rust (v5) | |
npm 包 | ||
CLI 命令 |
|
|
速度 | 基准 | 快 24-37 倍 |
格式 | 224 | 223 |
需要 Node.js | 是 | 否(自包含二进制) |
编程 API | TypeScript( | Rust( |
LevelDB 存储 | 是 | 否 |
报告器 | 13 | 13 |
jscpd@5 安装 jscpd 命令。cpd npm 包安装 cpd 命令。两者包含相同的 Rust 二进制。若想通过一次安装获得两个命令名,请使用 crates.io:cargo install jscpd。
更新内容
v5.0.x — Rust 引擎
jscpd v5 是从零开始用 Rust 重写的版本,以 jscpd@5(安装 jscpd 命令)或 cpd(安装 cpd 命令)的形式发布。自包含二进制 — 无需 Node.js 运行时。
相同的接口,快 24-37 倍:
保留 v4 的所有 CLI 选项 — 可直接替换:
jscpd→jscpd@5相同的
.jscpd.json配置文件、相同的检测算法、相同的报告器223 种语言格式,支持跨格式检测(Vue SFC、Svelte、Astro、Markdown)
v5 新增:
在真实项目上检测速度快 24-37 倍(参见 benchmark)
小型代码库(548 个文件):快 34 倍
中型代码库(9K 个文件):快 37 倍
大型代码库(17K 个文件,900 MB):快 24 倍
Git blame,支持并排作者对比(
--blame --reporters console-full)--workers— 控制文件分词和检测的并行度(默认:自动,使用所有 CPU 核心;v4 中不可用)13 个报告器:
console、console-full、json、xml、csv、html、markdown、badge、sarif、ai、xcode、threshold、silentAI 报告器 — 面向 LLM 管线的 token 高效输出(比 console 少约 79% 的 token)
--mcp— 内置基于 stdio 的 MCP 服务器:将你的 AI 助手指向该二进制,它就能针对你的代码库检查代码片段的重复情况(参见 docs)--summary— 代码库摘要:按 token、行数、大小和复杂度估算排名的文件和文件夹 — 直接从扫描中找出重构热点(参见 docs)自包含二进制 — 为 7 个平台预构建(macOS arm64/x64、Linux arm64/x64、Windows arm64/x64)
v5 中尚不支持(这些请使用 v4):
LevelDB/Redis 存储(
--store leveldb)Node.js 编程 API(
jscpd()、detectClones())
完整的 CLI 参考及与 v4 的差异,请参见 Rust 文档。
v4.2.x — TypeScript 引擎
自定义分词器后端 — 用基于 reprism 构建的自有后端取代了
prismjs。在真实项目上分词速度提升约 11.5%跨格式检测 — Vue SFC、Svelte、Astro 和 Markdown 按块分词,支持跨文件类型检测
新格式:Apex、CFML/ColdFusion、GDScript 以及 70+ 种其他格式(总计 224 种,原为 152 种)
Shebang 检测 — 自动检测无扩展名脚本的语言
--store-path— 配置并行运行的 LevelDB 缓存目录--skipComments—--mode weak的简写--formats-names— 将文件名(如Makefile、Dockerfile)映射到格式--noTips— 在 CI 中抑制提示输出Bug 修复:整文件重复被静默丢弃(#728)、Lisp/Elisp 文件上的 ReDoS(#737)、格式错误的
package.json导致进程崩溃(#739)、Vue SFC 跨文件检测(#737)、Vue SFC 列号(#737)、50 个依赖安全漏洞
完整的 CLI 参考,请参见 TypeScript 文档。
包
Package | Description |
CLI 和 Node.js API(v4.x) | |
REST API + MCP 服务器 | |
核心检测算法 | |
文件检测、报告器 | |
源代码分词 | |
HTML 报告 | |
SVG 徽章 | |
SARIF(GitHub 代码扫描) | |
LevelDB 持久化存储 | |
Redis 分布式存储 | |
cpd(Rust 引擎) | Rust 引擎(v5.x)— 也可作为 |
谁在使用 jscpd
jscpd npm 包每月下载量超过 1000 万次,并且有 ~5,000 个仓库 在 GitHub 的依赖关系图中声明使用它。
被以下分析平台集成:
GitHub Super Linter — 官方 GitHub linter 聚合器,将 jscpd 作为其复制/粘贴检测器
MegaLinter — 面向 CI 的开源 linter 聚合器,在每个版本(包括
ci_light)中都附带 jscpdCodacy — 自动化代码分析平台,jscpd 为其重复代码检测引擎提供支持
被以下知名项目使用:
OpenClaw — 个人 AI 助手,在其检查脚本中将 jscpd 作为重复代码门禁运行
DeepSeek Harness — DeepSeek 的插件框架,在 CI 中配置了 jscpd
degit — Rich Harris 的项目脚手架工具
MEGA webclient — MEGA.nz 网页客户端
Alibaba AppWorks — 将 jscpd 作为库嵌入
OVHcloud manager — OVHcloud 的客户控制面板
KiroCrew — 自我改进的持久化开发工作区
性能
基准测试在 macOS(Apple Silicon)上进行,每个目标运行 10 次(CopilotKit 为 3 次)。v4 使用 --no-gitignore -i "node_modules" 运行,以确保文件扫描具有可比性。
目标 | 文件数 | 大小 | jscpd v4 | jscpd v5 | 加速比 |
fixtures | 548 | 1.5 MB | 1.03s | 0.03s | 34.3x |
svelte | 9K | 38 MB | 15.80s | 0.43s | 36.9x |
CopilotKit | 17K | 159 MB | 82.89s | 3.44s | 24.1x |
完整的方法论和原始数据,请参见 performance-comparison.md。
AI 就绪功能
jscpd 通过三种机制集成到 AI 驱动的工作流中:
AI 报告器
面向 LLM 管线的 token 高效输出(比默认的 console 报告器少约 79% 的 token):
jscpd --reporters ai /path/to/source # v4
cpd --reporters ai /path/to/source # v5
cpd --reporters ai --summary /path/to/source # v5: + compact codebase summaryAgent 技能
两个可安装的技能,教 AI 编程助手如何使用 jscpd 并重构检测到的重复代码:
Skill | Purpose | Install |
| 工具参考 — CLI 选项、AI 报告器格式、配置语法 |
|
| 引导式重构工作流 — 读取克隆、选择策略、应用、验证 |
|
安装后,让你的 agent 执行“查找并修复代码重复”,它就会使用正确的选项调用 jscpd 并根据结果采取行动。
完整详情请参见 AI-Ready 文档。
贡献
请参阅 CONTRIBUTING.md 了解开发环境设置(Rust 和 TypeScript)、测试策略以及可接受的拉取请求的要求。安全问题请通过安全策略处理,而不是公开的 issue。
复刻仓库 kucherenko/jscpd
克隆复刻版本(
git clone https://github.com/{your-id}/jscpd)安装依赖(
pnpm install)以开发模式运行:
pnpm dev添加你的更改
添加测试并检查:
pnpm test构建:
pnpm build创建 PR
支持者
感谢所有支持者!🙏 [成为支持者]
赞助商
通过成为赞助商来支持这个项目。你的 logo 会显示在这里,并链接到你的网站。[成为赞助商]
许可证
MIT © Andrey Kucherenko
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityAmaintenanceFramework-aware code intelligence MCP server that builds a cross-language dependency graph from source code. 53 integrations (Laravel, Django, Rails, Spring, NestJS, Next.js, and more) across 68 languages. 100+ tools for navigation, impact analysis, refactoring, security scanning, session memory, and CI/PR reports — up to 97% token reduction.285,033102MIT
- AlicenseAqualityAmaintenanceAn MCP code-intelligence server for AI agents with pre-indexed AST cache, 62 MCP tools, and TOON-compressed output, enabling token-efficient code analysis and project health grading entirely locally.947MIT
- AlicenseNot gradedqualityBmaintenanceA local MCP server that indexes TypeScript/JavaScript projects and returns budget-aware, dependency-optimized context packs for AI coding assistants.1MIT
- AlicenseNot gradedqualityCmaintenanceToken-efficient MCP server for multi-language project analysis (Java, TypeScript, JavaScript, Markdown, Python) with plugins, semantic search, and static analysis.MIT
Related MCP Connectors
Zero-config MCP security scanner for AI-generated apps. 25K+ vulnerability patterns.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kucherenko/jscpd'
If you have feedback or need assistance with the MCP directory API, please join our Discord server