About the Duplicate Code Finder
Find copy-pasted code: blocks of lines that appear more than once in a file or across several files. Each repeated block is listed with every place it appears, biggest first, so you can see what is worth turning into one shared function.
Paste code or add files in any language, such as JavaScript, Python, PHP, Java, C#, SQL, CSS or HTML, and choose how long a block must be to count.
How it works
Every line is compared after trimming it and squeezing repeated spaces, so a block copied into a more deeply indented place is still found. Blank lines, comment lines and lines made only of brackets and punctuation, such as a lone closing brace, are left out of the comparison, so they neither create matches nor break them.
A match is extended as far as it goes, so a 20-line copy is reported once as 20 lines, not as many overlapping smaller blocks. When the same block appears three or more times, all copies are shown together.
The summary shows how many lines of your code are inside a repeated block, a quick measure of how much copy-paste the code has.
Assumptions and limits
- Lines must match exactly apart from spacing (and letter case, if you choose). Renamed variables make lines different, so a copy with renamed variables is only found where lines still match.
- A line counts as a comment when it starts with //, #, --, /*, *, <!-- or %. C and C++ lines such as #include and #define are kept as code.
- Each file can be up to 2 MB and all files together up to 10 MB.
Worked examples
A helper copied into two functions
Four lines that work out a price with tax appear in two functions. The tool lists them once with both line ranges, which is a hint to move them into one function.
Several files at once
Add every file of a small project and each repeated block shows which files and lines it is in, such as utils.js lines 10–24 and api.js lines 88–102.
SQL queries
Repeated SELECT ... FROM ... WHERE blocks across scripts show up even when they are indented differently.
How to use the Duplicate Code Finder
- Paste code or add files. Any programming language.
- Set the minimum block size. How many lines a copy must have.
- Review the repeats. Biggest first, with every location.
Frequently asked questions
What minimum block size should I use?
Start with 4 to 6 lines. Smaller values find many tiny repeats that are normal in code, such as the same two lines that open every file. Larger values show only the big copy-pastes that are clearly worth refactoring.
Does it understand my programming language?
It compares lines of text, so it works with any language without needing to understand it. That also means it finds exact copies rather than code that does the same thing written differently.
Why wasn't a copy found?
Something on one of the lines differs, such as a renamed variable or a changed number, or the block is shorter than the minimum. Try a lower minimum, or tick 'Ignore upper and lower case' if only capitals differ.
Are blank lines and braces counted?
No. Blank lines, comment lines and lines with only brackets or punctuation are skipped, so formatting differences don't hide a copy. The line numbers shown still point to the real lines in your file.
Is my code uploaded?
No. The search runs in your browser on this device, so private or unreleased code never leaves your computer, and nothing is stored after you close the page.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.