Show HN: Treepeat – Code similarity detection using Tree-sitter
Summary
Treepeat is an open-source tool that uses Tree-sitter for code similarity detection, supporting multiple programming languages with features for finding duplicates, near-duplicates, and structurally similar code.
View Cached Full Text
Cached at: 09/24/26, 07:11 PM
dsummersl/treepeat
Source: https://github.com/dsummersl/treepeat
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, 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.
Similar Articles
Show HN: CLI tool for detecting non-exact code duplication with embedding models
Slopo is a lightweight CLI tool that detects non-exact code duplication across a codebase using embedding models, helping developers find similar code snippets that are hard to spot manually.
Show HN: RealDiff – runtime behavior diffing for pull requests (six languages)
RealDiff is an open-source tool that detects runtime behavior changes in pull requests by comparing test outputs, highlighting unintended effects even in files not directly edited.
tirth8205/code-review-graph
code-review-graph is a Python tool that builds a structural map of code using Tree-sitter, tracks incremental changes, and provides precise context to AI coding assistants via MCP, significantly reducing token usage during code review tasks.
Show HN: Semble – Code search for agents that uses 98% fewer tokens than grep
Semble is a fast code search library for AI agents that uses ~98% fewer tokens than grep+read, runs on CPU with no external dependencies, and integrates via MCP or CLI.
Show HN: Treedocs: Documentation that automatically checks for staleness
Treedocs is a Swift CLI tool that generates a documented tree view of a repository and automatically checks for stale documentation entries, helping teams keep docs up to date.