# Check Similarity

> 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).

- Skill: `mizchi/check-similarity` (Agent Skill)
- Install (CLI): `npx skillmds@latest add mizchi/check-similarity`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizchi/check-similarity/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: mizchi (https://skillmd.com/u/mizchi)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/mizchi/check-similarity

---


# 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:

| Extension | Tool |
|-----------|------|
| `.ts`, `.tsx`, `.js`, `.jsx` | `similarity-ts` |
| `.py` | `similarity-py` |
| `.mbt` | `similarity-mbt` |
| `.rs` | `similarity-rs` |
| `.php` | `similarity-php` |
| `.ex`, `.exs` | `similarity-elixir` |
| `.css`, `.scss` | `similarity-css` |

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

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

## Step 2: Run analysis

```bash
similarity-<lang> $ARGUMENTS
```

If no arguments given:

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

For TypeScript, also consider type similarity:

```bash
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)

| Option | Description |
|--------|-------------|
| `--threshold <0-1>` | Similarity threshold (default: 0.85) |
| `--min-lines <n>` | Skip short functions (default: 3) |
| `--print` | Show code snippets |
| `--fail-on-duplicates` | Exit code 1 if duplicates found |
| `--filter-function <name>` | Filter by function name |

## CI Integration

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

