Skip to main content

Overview

treepeat is a tool that finds similarities in your codebase.

  • Find duplicate code blocks meaningful to the language (classes/functions), not just lines (--ruleset none)
  • Find near-duplicates, ignore whitespace, strings, high level AST nodes such as function and names (--ruleset default)
  • Find structurally similar code, anonymizing identifiers, constants, etc (--ruleset loose)

Pull requests welcome: This is very much an proof of concept - I'm happy with it, but I haven't supported very many languages at present. PRs welcome!

Languages supported: astro, bash, css, go, html, javascript, lua, markdown, php, python, sql, typescript, java, kotlin, rust, yaml

Usage

Installation

pip install treepeat

detect

Scan a codebase for similar or duplicate code blocks using tree-sitter AST analysis and locality-sensitive hashing.

Key flags:

  • --ruleset: Normalization ruleset to use (none, default, loose) - controls how code is normalized before comparison
  • --similarity: Percent similarity from 1-100 (default: 100 for exact duplicates)
  • --min-lines: Minimum number of lines for a match (default: 5)
  • --diff: Show side-by-side comparisons of similar blocks
  • --format: Output format - console (default) or sarif for CI integration
  • --verbose: Show additional run metrics, including per-stage timing when available
  • --progress: Show progress bars for long-running pipeline stages
# Find exact duplicates
treepeat detect /path/to/codebase

# Find near-duplicates with 80% similarity threshold
treepeat detect --similarity 80 /path/to/codebase

# Show diffs between similar blocks and use loose ruleset
treepeat --ruleset loose detect --diff --min-lines 10 /path/to/codebase

# Show parse progress and verbose stage timing
treepeat detect --progress --verbose /path/to/codebase

# Output results in SARIF format for CI tools
treepeat detect --format sarif -o results.sarif /path/to/codebase

--progress is intended primarily as interactive CLI feedback. The current implementation writes tqdm progress bars to stderr, leaving normal command output on stdout or --output.

Other sub commands

list-ruleset

List all rules in a ruleset, along with their descriptions. Use --language to see which rules apply to a specific language.

treesitter

Display how treepeat normalizes source code into tree-sitter tokens for similarity detection -- helpful for debugging why a certain section of a file might be similar to another. Shows the original source code side-by-side with the normalized token representation.

Dev setup

make setup
make test

Performance harness for benchmarking real repositories: tools/perf/harness.py (docs).

ADRs

Architecture Decision Records live in docs/adr.

Metadata

Release files for treepeat 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treepeat 0.11.0
File Size Uploaded Provenance Actions
treepeat-0.11.0.tar.gz 50.1 kB Without provenance Details for treepeat-0.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for treepeat 0.11.0
File Interpreter ABI Platform Actions
treepeat-0.11.0-py3-none-any.whl Python 3 none any Details for treepeat-0.11.0-py3-none-any.whl

Total release size: 116.6 kB

Release files / treepeat-0.11.0.tar.gz

Download URL treepeat-0.11.0.tar.gz
Size 50.1 kB
Tags Source
SHA-256 checksum
How to use checksums
995cffa622dc668446f3757c1c0b7dbf103e39188d4e24071e537647448a3285
BLAKE2b-256 checksum
How to use checksums
a0ecbce7c405de73f4707253c2cff98de25a03cb536bda20fda903ef3fd07635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / treepeat-0.11.0-py3-none-any.whl

Download URL treepeat-0.11.0-py3-none-any.whl
Size 66.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8842b40a48cd896d6dbd7154a1747558facd94a6dc91610b66dab5c2593fd98
BLAKE2b-256 checksum
How to use checksums
3fb204e0f9f489d077394deb6f1095238eaf175c36a3cbe2e7e9055c1f1019c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for treepeat 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page