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, markdown, 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) orsariffor 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.
Release files for treepeat 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| treepeat-0.8.0.tar.gz | 60.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| treepeat-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 137.8 kB
Release files / treepeat-0.8.0.tar.gz
| Download URL | treepeat-0.8.0.tar.gz |
|---|---|
| Size | 60.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05da1301146740070dbbff42526742b41ecaf1290973b9282310a8859123f505
|
|
BLAKE2b-256 checksum How to use checksums |
a7dde9c75c5787278376f143d55aaa652978f28df7dfd68a7113a9386e2f2091
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"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.8.0-py3-none-any.whl
| Download URL | treepeat-0.8.0-py3-none-any.whl |
|---|---|
| Size | 76.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e474061f8bfe20bbcb7c02990fea8d34ba9eb537494864553319bc63f823a82
|
|
BLAKE2b-256 checksum How to use checksums |
d423df6083ee61ab2d08b34d503036c444a0a352efad2192558767dc26babf26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"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}
|