Check a snippet for duplication
check_duplicationDetect duplicate code in your project before writing or committing new functions, blocks, or classes. It scans existing code to find exact or similar matches, helping you reuse existing implementations.
Instructions
Check whether a code snippet duplicates code that already exists in the scanned project. Use it before writing or committing a function, class or block, to find the existing copy you should reuse instead. Detection is token-based with the server's --min-tokens / --min-lines thresholds: a snippet shorter than the threshold returns count 0 with a 'note' explaining why. Returns {format, count, returned, duplications[]} where each duplication has 'file', 'fileStartLine', 'fileEndLine', 'snippetStartLine', 'snippetEndLine', 'tokens' and 'kind' (exact, renamed or similar), biggest match first. With 'similarity' below 1, the response also carries 'similar[]' and 'similarCount': project functions whose syntax-tree structure resembles each function in the snippet (JavaScript/TypeScript only), each with 'file', 'name', line ranges and a 'similarity' ratio. Does not modify the project or the scan; the snippet is compared against the last scan, so call check_current_directory first if files changed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The source code to check, verbatim (whole functions or blocks work best; it must reach the server's --min-tokens threshold, 50 tokens by default) | |
| limit | No | Maximum number of duplications to include in the response. 'count' always carries the untruncated total, so a small limit still tells you how much was found. | |
| format | Yes | Language of the snippet: a jscpd format name such as 'javascript', 'typescript', 'python', 'java', or a file extension such as 'js', 'py' (run `jscpd --list` for all 224). Unknown values return an error naming the problem. | |
| similarity | No | Also return project functions whose syntax-tree structure is similar to the snippet's functions, when the similarity ratio reaches this value. 1 means exact matches only (no 'similar' section); 0.85 catches renames, literal changes and one-line edits; 0.7 tolerates a couple of added or removed statements. Defaults to the server's --similarity setting (1 unless configured). JavaScript/TypeScript only; other formats ignore it. |