# Duplicated code detection tool

**URL:** <https://discuss.ocaml.org/t/duplicated-code-detection-tool/17399>\
**Category:** Ecosystem\
**Created:** [October 16, 2025, 12:39pm UTC](https://discuss.ocaml.org/t/duplicated-code-detection-tool/17399 "2025-10-16T12:39:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gusn](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@gusn](https://discuss.ocaml.org/u/gusn)\
**Post date:** [October 16, 2025, 12:39pm UTC](https://discuss.ocaml.org/t/duplicated-code-detection-tool/17399/1 "2025-10-16T12:39:59Z")

</div>

Hi everyone,

I’m working on a project where some functions are duplicated in different files, but the project is a bit too big to track them manually. Also, some functions have been coded in the project before they were added to more recent versions of OCaml.

Are there tools to detect duplicated OCaml code in a project (ideally also comparing to Stdlib)?

Thanks

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [October 16, 2025, 2:36pm UTC](https://discuss.ocaml.org/t/duplicated-code-detection-tool/17399/2 "2025-10-16T14:36:47Z")

</div>

I don’t know about a tool but here is a quick hack: format the code using OCamlformat such that the same code looks the same. Now sort lines of all files - identical lines from different files show up together.

---

<div class="post-metadata">

**Author:** ![gusn](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@gusn](https://discuss.ocaml.org/u/gusn)\
**Post date:** [October 20, 2025, 1:07pm UTC](https://discuss.ocaml.org/t/duplicated-code-detection-tool/17399/3 "2025-10-20T13:07:29Z")

</div>

Hi, Thanks for your answer. If there is nothing better out there, I might end up doing this 🙂

---

<div class="post-metadata">

**Author:** ![lambda\_foo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lambda_foo/32/275_2.png) [@lambda\_foo](https://discuss.ocaml.org/u/lambda_foo)\
**Post date:** [October 20, 2025, 9:36pm UTC](https://discuss.ocaml.org/t/duplicated-code-detection-tool/17399/4 "2025-10-20T21:36:10Z")

</div>

What about [GitHub - samoht/prune](https://github.com/samoht/prune/) it uses the mli files to prune code?
