Find duplicate code
find_duplicatesFind near-duplicate code across files by passing files or line ranges, returning candidate matches for review and refactoring.
Instructions
List code in other files that nearly matches the given files or line ranges. Use it in reviews and refactors - pass changed line ranges ("src/a.ts:10-40") for sharper pairs. Treat every pair as a candidate - read both ranges before you call it a duplicate. Expect it to be off per project - ask the user before you turn it on. Turn it on with index_project duplicates: true - the first build can take over an hour on large projects. Covers .ts, .tsx, .js, .jsx, .mjs files; skips tests, specs and .d.ts files.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Absolute project root - omit to use the working directory | |
| files | Yes | Root-relative or absolute paths, optionally with lines: "src/a.ts:10-40" | |
| limit | No | Max pairs per file | |
| exclude | No | Root-relative or absolute folders or files to leave out, e.g. ["src/generated"] | |
| threshold | No | Min similarity - raise to 0.92 for fewer false pairs, lower for more recall |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notes | Yes | Sync notes, why a file or exclude entry has no pairs, and how to read the pairs | |
| pairs | Yes | Candidates, best first per file | |
| status | Yes | "off": duplicate search is not enabled for this project, which is not the same as no duplicates |