similarity-rs
Skill29 starsChanged 12 days agoMITView on GitHub
Use when you suspect duplicate or near-duplicate Rust code — writing a utility function that might already exist, copy-paste-modifying a function, creating near-duplicate structs or enums, or running `similarity-rs 0.5` with flags like `--threshold`, `--cross-file`, or `--min-lines`. Also triggers on `cargo install similarity-rs`, reviewing CI duplication gates, or tuning false-positive thresholds.
- Installs packages
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- bevy-a11ySkill
- bevy-animationSkill
- bevy-assetsSkill
- bevy-audioSkill
- bevy-camerasSkill
- bevy-captureSkill
- bevy-cargo-featuresSkill
- bevy-core-conceptsSkill
- bevy-custom-assetsSkill
- bevy-diagnostics-profilingSkill
- bevy-ecs-componentsSkill
- bevy-ecs-queriesSkill
- bevy-ecs-systemsSkill
- bevy-fluentSkill
- bevy-input-actionsSkill
- bevy-migration-0-17-to-0-18Skill
- bevy-migration-0-18-to-0-19Skill
- bevy-migration-0-19-to-0-20Skill
- bevy-pbr-materialsSkill
- bevy-physicsSkill
- bevy-portingSkill
- bevy-renderingSkill
- bevy-save-loadSkill
- bevySkill
- bevy-testingSkill
- bevy-uiSkill
- bevy-vfxSkill
- bevy-voxel-dataSkill
- bevy-voxel-pipelineSkill
- bevy-voxel-runtimeSkill
- bevy-wasm-webgpuSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Before committing: verify you haven't introduced cross-file duplication.
- Very specific: line 74
--skip-teston CI: Test files often contain structurally similar setup fixtures by design.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
similarity-rs 0.5 — Rust duplication detection
Tool status: Beta — not production-tested per the upstream README. Evaluate findings manually before acting.
When to use this skill
Antipattern triggers (act before writing code):
- About to write a utility function — grep the codebase first; it may already exist.
- Caught yourself thinking "I'll just inline this here."
- Planning to copy-paste-modify an existing function with small changes.
- Adding a new enum or struct that may overlap with an existing one.
- Two
Pluginsetups that share large blocks of boilerplate. - Similar Bevy systems that differ only in their
Queryfilter component. - Repeated
commands.spawn((Mesh3d(...), MeshMaterial3d(...), ...))patterns that belong in aBundle.
Tool-integration triggers (run the check):
- Before committing: verify you haven't introduced cross-file duplication.
- During a cleanup sprint: identify consolidation candidates.
- Setting up a pre-commit hook or GitHub Actions gate.
- Adjusting
-t/--thresholdor--min-linesfor a noisy or too-quiet run.
Canonical workflow
The pattern is: search first → write minimally → run the check.
# 1. Search before writing — check whether the helper already exists
rg "fn <verb>" # e.g., rg "fn normalize" to find existing helpers
cargo doc --open --package <dep> # inventory what your deps already provide
# 2. Write only what's missing.
# 3. Before committing, check for accidental duplication
cargo install similarity-rs # one-time install
similarity-rs ./src # scan the src tree
# 4. If --cross-file output is needed (catches LLM's most common antipattern)
similarity-rs --cross-file ./src
# 5. Tighten or loosen if needed (see references/tuning.md)
similarity-rs -t 0.85 -m 5 --cross-file --skip-test ./srcConsult cargo doc --open for every dependency before reaching for a one-off helper. LLMs reproduce functions from stdlib, itertools, or an already-declared crate dep more often than from thin air.
Topics
| Topic | Reference |
| LLM duplication patterns with before/after examples | references/antipatterns.md |
| Search-before-write workflow (rg, cargo doc, CLAUDE.md scan) | references/search-before-write.md |
| Pre-commit hook and GitHub Actions CI recipes | references/ci-integration.md |
-t, --min-lines, --cross-file, --no-size-penalty knobs | references/tuning.md |
| When similar code is intentional — don't act on these | references/false-positives.md |
similarity-ts, similarity-py, similarity-generic for polyglot repos | references/sibling-tools.md |
Gotchas
--cross-fileis off by default. Without it, only within-file pairs are reported. Most LLM-introduced duplication is across files. Always pass--cross-fileunless you specifically want within-file only.- Beta tool. The upstream README marks
similarity-rsas not production-tested. Treat output as signal, not verdict. Review each flagged pair before refactoring. --skip-teston CI. Test files often contain structurally similar setup fixtures by design. Run with--skip-teston CI to suppress expected test-fixture symmetry; review test duplication locally.- Threshold tuning is project-specific. The default
-t 0.85catches obvious copy-paste. Use 0.75–0.80 during a cleanup sprint (more hits), 0.90–0.95 for production gating (fewer false alarms). See references/tuning.md. - No tester snippet for this skill.
similarity-rsis a CLI-only tool with no library API — there is nocargo checkexample to validate. This follows the same approach asbevy-cargo-featuresandbevy-migration-0-17-to-0-18, which also carry no tester examples.
See also
bevy-cargo-features— installingsimilarity-rsviacargo installsits alongside theCargo.tomlfeature story; also coversdefault-featuresdecisions that can hide accidental dep duplication.bevy-core-concepts— duplicatePluginsetup and schedule boilerplate is the most common Bevy-specific antipattern this tool catches.bevy-ecs-components— near-duplicate component structs and overlapping enums often surface when features are added without consolidation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

