detect_ast_clones
Identify Type-2 AST clones across your codebase: functions with identical structure after normalizing identifiers and literals. Groups structurally identical symbols to detect duplicated code for DRY refactoring.
Instructions
Find Type-2 AST clones across the codebase: functions/methods with identical structure after normalizing identifiers and literals. Unlike check_duplication (name/signature similarity — Type-1-ish), this parses each function body with tree-sitter, replaces identifiers and literals with a placeholder, and hashes the AST subtree. Reports groups of structurally identical symbols — prime candidates for DRY refactoring or extracting a shared helper. Supported languages: TypeScript, JavaScript, Python, Ruby, Go, Java, Rust, PHP, C, C++, C#, Swift, Kotlin, Scala, Elixir. Read-only. Returns JSON: { groups: [{ hash, size, loc, symbols: [{ symbol_id, name, file, line_start, line_end }] }], total_groups, total_duplicated_symbols, files_scanned, symbols_scanned }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| min_loc | No | Minimum function body line span to consider (default: 10) | |
| min_nodes | No | Minimum AST node count to consider (filters trivial clones like one-line getters) (default: 30) | |
| file_pattern | No | Filter to files whose path contains this substring | |
| limit | No | Max clone groups to return (default: 100) |