Duplicate code detection for Python

Find duplicate Python code before it multiplies.

Deslop finds repeated functions, copy-pasted classes and renamed copies across your whole Python codebase, ranks the worst duplicate code first, and flags new copies in VS Code as you type.

Opens VS Code and installs the extension. Free, open source, and your code never leaves your machine.

No VS Code yet? View the extension on the Marketplace

Remove duplicate Python code from Click in VS Code · 1:13 · English narration and captions
Read the English transcript

Click, open in VS Code

This is Click, the Python library behind thousands of command-line tools, open in VS Code with Deslop installed. Deslop has already read every Python file in the library and ranked the duplicate code it found. The worst copies sit at the top of this list, and the warning under this method says it exists more than once.

Compare two exceptions

Near the top, Deslop pairs two exception classes: No Such Option and No Such Command. Compare puts them side by side. The constructor, the default message and the close-match suggestions are the same code. The only change is that option became command, all the way through.

Three identical methods

This finding is exact. The Bash, Z shell and PowerShell completion classes each define the same get completion args method, line for line. I follow each file link to read the copies in place before I change anything.

Remove the copies

The other two classes can reuse the Bash method directly, so I replace both copies with one line each and save. Deslop scans again straight away and the finding is gone. Then I run the shell completion tests from Click, and all fifty eight still pass.

Real footage, real repository

Watch Deslop clean up duplicate code in Click

Click is the Python library behind thousands of command-line tools, and one of the best-kept codebases on GitHub. This film is real, unstaged footage of Deslop in VS Code on Click's source at commit 8b19813, zoomed and sped up only to keep it short. It finds real clones, compares them side by side, then removes one with a two-line refactor while Click's own tests keep passing.

Found in Click

Three kinds of duplicate code, all from one well-run Python project

Every mature Python codebase collects copies: a method pasted into a sibling class, an exception cloned and renamed, a decorator overload written twice. None of these is a bug. Each is a place where the next fix has to be made more than once.

  1. Identical

    One method, written three times

    def get_completion_args(self) -> tuple[list[str], str]:

    src/click/shell_completion.py · lines 432, 454 and 530

    The Bash, Zsh and PowerShell completion classes each define the same get_completion_args method, line for line. In the film, Zsh and PowerShell reuse the Bash method instead, and 58 shell-completion tests still pass.

  2. Renamed

    Two exceptions, one shape

    class NoSuchOption(UsageError):
    class NoSuchCommand(UsageError):

    src/click/exceptions.py · lines 232 to 301

    NoSuchOption and NoSuchCommand share a constructor, a default message and the close-match suggestions. A text diff sees dozens of changed lines; Deslop sees one consistent rename.

  3. Nearly identical

    Decorator overloads, side by side

    @t.overload
    def command(name: _AnyCallable) -> Command: ...

    src/click/decorators.py · lines 133 to 165 and 258 to 290

    The typing overloads for the command and group decorators are the same block with Command swapped for Group. Worth knowing before a change to one leaves the other behind.

Beyond the linter

Why your Python linter misses most copies

Pylint, Flake8 and Ruff are essential for Python code quality: they check style, imports and likely bugs. Duplication is a different question, because it is about how two pieces of code relate, not whether either one is wrong.

Pylint's duplicate-code check (R0801) compares lines of text, so it finds verbatim copies and loses them once a variable is renamed. Deslop parses Python with tree-sitter and compares the syntax, so option_name and command_name still line up. Keep your linter; add Deslop for the copies it cannot see.

How it fits

From install to your first refactor in a minute

  1. Install and open your project

    Deslop scans the Python files in your workspace on its own. There is nothing to configure, and the Top Offenders view lists every cluster of duplicate code, worst first.

  2. Compare the copies

    Open a finding to see every copy with its file and line, then compare any two in the VS Code diff editor before you decide what to merge.

  3. Refactor with live feedback

    Deslop rescans as you edit. Remove a copy and the finding disappears; paste one and the warning appears before code review ever sees it.

  4. Keep your AI coding agent honest

    The same live analysis runs as an MCP server, so Claude Code, Cursor and GitHub Copilot can ask whether similar Python already exists before writing more.

Questions Python developers ask

How do I find duplicate code in a Python project?

Install Deslop for VS Code and open the project. It parses every .py file, matches functions, methods and blocks that repeat the same logic even after renaming, and lists the clusters worst first in the Top Offenders view. The same engine runs as a CLI and a GitHub Action for CI.

Does Deslop replace Pylint, Ruff or Flake8?

No. Use them for style, imports and likely bugs. Deslop does one job they do not: finding the same logic written more than once across files, including copies where names and literals changed.

Does my code leave my machine?

No. Deslop runs locally inside VS Code. It needs no account and sends your source code nowhere.

Does it work with GitHub Copilot, Claude Code and Cursor?

Yes. Deslop includes an MCP server that coding agents can ask before they write new code, so they reuse an existing function instead of generating a near-duplicate.

Which other languages does it support?

Alongside Python: C, C#, Rust, Dart, JavaScript, TypeScript/TSX, PHP, F#, Go and Osprey, in the same extension.

Is Deslop free?

Yes. Deslop is open source under the MIT licence, and the VS Code extension is free on the Visual Studio Marketplace.

Your Python codebase has copies. See them in a minute.

One click installs Deslop in VS Code. Open a project and the worst duplicate code is already at the top of the list.