Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计通过

code-clone-assistant代码 clone 助手

Agent Skill

code-clone-assistant 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

2,203

周安装

90

GitHub Stars

38

下载量

706
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:code-clone-assistant(代码 clone 助手)
来源仓库:https://github.com/terrylica/cc-skills
仓库路径:skills/code-clone-assistant
安装命令:
npx skills add https://github.com/terrylica/cc-skills --skill code-clone-assistant
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/terrylica/cc-skills --skill code-clone-assistant

简介

检测代码克隆并指导重构,结合 PMD CPD 与 Semgrep 工具。

  • 支持精确重复与模式匹配两种检测方式,提升违规发现率。
  • 随使用次数增加而自我演进,修正指令偏差与参数漂移。
  • 需确保已安装指定版本的 PMD 和 Semgrep 工具链。
  • code-clone-assistant 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Code Clone Assistant

Detect code clones and guide refactoring using PMD CPD (exact duplicates) + Semgrep (patterns).

Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.

Tools

  • PMD CPD v7.17.0+: Exact duplicate detection
  • Semgrep v1.140.0+: Pattern-based detection

Tested: October 2025 - 30 violations detected across 3 sample files Coverage: ~3x more violations than using either tool alone


When to Use This Skill

Use this skill when:

  • Finding duplicate code in a codebase
  • Detecting DRY violations
  • Refactoring similar code patterns
  • Identifying copy-paste code

Why Two Tools?

PMD CPD and Semgrep detect different clone types:

AspectPMD CPDSemgrep
DetectsExact copy-paste duplicatesSimilar patterns with variations
ScopeAcross files ✅Within/across files (Pro only)
MatchingToken-based (ignores formatting)Pattern-based (AST matching)
Rules❌ No custom rules✅ Custom rules

Result: Using both finds ~3x more DRY violations.

Clone Types

TypeDescriptionPMD CPDSemgrep
Type-1Exact copies✅ Default
Type-2Renamed identifiers--ignore-*
Type-3Near-miss with variations⚠️ Partial✅ Patterns
Type-4Semantic clones (same behavior)

Quick Start Workflow

# Step 1: Detect exact duplicates (PMD CPD)
pmd cpd -d . -l python --minimum-tokens 20 -f markdown > pmd-results.md

# Step 2: Detect pattern violations (Semgrep)
semgrep --config=clone-rules.yaml --sarif --quiet > semgrep-results.sarif

# Step 3: Analyze combined results (Claude Code)
# Parse both outputs, prioritize by severity

# Step 4: Refactor (Claude Code with user approval)
# Extract shared functions, consolidate patterns, verify tests


Accepted Exceptions (Known Intentional Duplication)

Not all code duplication is a problem. Some codebases deliberately use copy-and-adapt patterns where refactoring would be harmful. When running clone detection, always check for accepted exceptions before recommending refactoring.

When Duplication Is Acceptable

PatternWhy AcceptableExample
Generation-per-directory experimentsEach generation is an immutable, self-contained experiment. Sharing code across generations would break provenance and make past experiments non-reproducible.SQL templates, sweep scripts where each gen{NNN}/ is independent
SQL templates with placeholder substitutionSQL has no import/include mechanism. Templates use sed placeholder replacement (__PLACEHOLDER__), not function calls. Extracting shared CTEs into separate files would break the single-file execution model.ClickHouse sweep templates sharing signal detection + metrics CTEs
Protocol/schema boilerplateSerialization formats, API contracts, and wire protocols require exact structure in each location. Abstracting them hides the contract.NDJSON telemetry line construction in wrapper scripts
Test fixtures and golden filesTest data intentionally duplicates production patterns to verify behavior. Sharing fixtures creates brittle cross-test dependencies.Test setup code, expected output snapshots

How to Report Accepted Exceptions

When clone detection finds duplication that matches an accepted exception pattern:

  1. Report it — always show the user what was found (lines, tokens, files)
  2. Flag as accepted — explicitly state it matches a known exception pattern
  3. Explain why — cite the specific reason refactoring is not recommended
  4. Do NOT recommend refactoring — this is the key difference from actionable findings

Example output format:

Code Clone Analysis Results

PMD CPD Findings:
  Clone 1: 115 lines (575 tokens) — base_bars → signals CTEs
    gen610_template.sql:33 ↔ gen710_template.sql:38
    Status: ACCEPTED EXCEPTION (generation-per-directory experiment)
    Reason: Each generation is immutable. Shared CTEs would break
            experiment provenance and reproducibility.

  Clone 2: 36 lines (478 tokens) — metrics aggregation
    gen610_template.sql:207 ↔ gen710_template.sql:244
    Status: ACCEPTED EXCEPTION (SQL template without include mechanism)

Actionable Findings: 0
Accepted Exceptions: 2

Project-Level Exception Configuration

Projects can declare accepted exception patterns in their CLAUDE.md:

## Code Clone Exceptions

- `sql/gen*_template.sql` — generation-per-directory experiments (immutable)
- `scripts/gen*/` — copy-and-adapt sweep scripts (no shared infrastructure)
- `tests/fixtures/` — intentional duplication for test isolation

When this section exists in a project's CLAUDE.md, the code-clone-assistant should check it before classifying findings.


Reference Documentation

For detailed information, see:


Troubleshooting

IssueCauseSolution
PMD CPD not foundNot installed or not in PATHbrew install pmd or download from PMD releases
Semgrep timeoutLarge codebase scanUse --exclude to limit scope
No duplicates detectedminimum-tokens too highLower --minimum-tokens value (try 15)
Too many false positivesminimum-tokens too lowIncrease --minimum-tokens (try 30+)
Language not recognizedWrong -l flagCheck PMD CPD supported languages list
SARIF parse errorSemgrep output malformedUpgrade Semgrep to latest version
Memory error on large repoJava heap too smallSet PMD_JAVA_OPTS=-Xmx4g
Missing clone rules fileCustom rules not createdCreate clone-rules.yaml or use default config

Post-Execution Reflection

After this skill completes, check before closing:

  1. Did the command succeed? — If not, fix the instruction or error table that caused the failure.
  2. Did parameters or output change? — If the underlying tool's interface drifted, update Usage examples and Parameters table to match.
  3. Was a workaround needed? — If you had to improvise (different flags, extra steps), update this SKILL.md so the next invocation doesn't need the same workaround.

Only update if the issue is real and reproducible — not speculative.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

27.8%
按下载量换算196

OpenCode

22.25%
按下载量换算157

Antigravity

19.93%
按下载量换算141

Gemini CLI

13.34%
按下载量换算94

windsurf

8.15%
按下载量换算58

Codex

3.22%
按下载量换算23

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills