OpenParable
Skip to content
← Back to skills

Check Similarity

Testing & Quality
check-similarity

Check Similarity is an Agent Skill for testing & quality published in the mizchi/similarity repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Detect duplicate code using AST-based similarity analysis. Auto-selects the right tool based on file types in the project (similarity-ts for TypeScript/JavaScript, similarity-py for Python, similarity-mbt for MoonBit, similarity-rs for Rust, etc).

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/mizchi/similarity/blob/HEAD/.claude/skills/check-similarity/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/check-similarity, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Code Similarity Detection (Multi-Language)

What to do

Detect which languages are present in the target path and run the appropriate similarity tool. Then analyze results and propose refactoring.

Step 1: Detect language and select tool

Check the target path for file extensions:

ExtensionTool
.ts, .tsx, .js, .jsxsimilarity-ts
.pysimilarity-py
.mbtsimilarity-mbt
.rssimilarity-rs
.phpsimilarity-php
.ex, .exssimilarity-elixir
.css, .scsssimilarity-css

Before running, check if the command exists. If not, install it:

which similarity-<lang> || cargo install similarity-<lang>

Step 2: Run analysis

similarity-<lang> $ARGUMENTS

If no arguments given:

similarity-<lang> . --threshold 0.85 --min-lines 5

For TypeScript, also consider type similarity:

similarity-ts . --threshold 0.85 --min-tokens 25 --experimental-types

Step 3: Analyze and report

Categorize results by priority:

  1. 100% similarity: Exact duplicates - must refactor
  2. 95-100%: Near-identical - high-value refactoring targets
  3. 85-95%: Same pattern - consider extracting shared logic
  4. < 85%: Similar structure - investigate if related

Report the findings grouped by file, sorted by similarity (highest first). For each high-priority pair, propose a concrete refactoring with before/after code.

Common Options (all tools)

OptionDescription
--threshold <0-1>Similarity threshold (default: 0.85)
--min-lines <n>Skip short functions (default: 3)
--printShow code snippets
--fail-on-duplicatesExit code 1 if duplicates found
--filter-function <name>Filter by function name

CI Integration

# Fail CI if near-exact duplicates exist
similarity-<lang> . --threshold 0.95 --min-lines 5 --fail-on-duplicates