# Reduce Similarities

> Detects duplicated Rust code with the dev-shell similarity-rs CLI. Use when reviewing .rs files for repeated functions, impl methods, or parallel struct and enum definitions, or before extracting a shared helper.

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

---


# Rust Code Similarity Detection

`similarity-rs` comes from the Nix dev shell (`similarity` in
`nix/dev-shell.nix`); prefix it with `direnv exec .` from outside the shell.
TypeScript duplication belongs to the `typescript` and `ast-grep` skills.

Run it over `$ARGUMENTS`, or over `.` when none was given. Functions and type
definitions are separate passes, so a default run silently misses parallel
structs and enums:

```bash
similarity-rs . --threshold 0.85 --min-lines 5
similarity-rs . --threshold 0.85 --experimental-types
```

`--print` shows the matching snippets and `similarity-rs --help` has the rest;
`--skip-test` is worth adding when fixture-shaped test functions drown out the
real findings.

## Triage

A score is a starting point, not a verdict. Usually worth refactoring:

- 100% matches: extract a shared function or generic.
- 95-100% across different types: generic function with trait bounds.
- Duplicate impl methods on several types: trait with default implementations.
- 85-95% match arms or error handling: shared helper or macro.
- Parallel structs with identical fields: shared base or generic struct.

Usually left alone: short `new()` constructors, simple `From`/`Into` impls, and
anything a derive would generate.

Report each surviving candidate as a concrete before/after shape, not as a list
of scores.

