Skip to main content
This page covers what fallow dupes reports, how to read the output, and when to act.
Pass --explain to any command with --format json to include metric definitions directly in the JSON output as a _meta object. The MCP server always includes _meta automatically.

Clone types

Fallow classifies clones using the standard taxonomy from clone detection research. As you move from strict to semantic, recall increases (more clones found) but precision decreases (more potential false positives).
The Type-1 through Type-4 clone taxonomy was surveyed by Roy, Cordy, and Koschke (2009). Fallow detects Type-1 and Type-2 clones. Type-3 (gapped clones with inserted/deleted statements) and Type-4 (semantically equivalent but syntactically different) require analysis beyond token comparison and are not currently supported.

Detection modes in detail

fallow dupes --mode semantic

Key metrics

Duplication percentage

Fraction of total source tokens that appear in at least one clone group. Computed over the full analyzed file set, not just the groups shown by --top.
Duplication percentage is mode-dependent. Running with semantic mode will always report a higher percentage than strict because more normalization means more matches. Compare percentages only across runs using the same mode.

Token count and line count

Each clone group reports both token count and line count.
  • Tokens are language-aware units (keywords, identifiers, operators, literals). This is what the detection engine matches on.
  • Lines are the source lines spanned by the clone. Useful for estimating refactoring effort.
Larger clones have higher refactoring value. A 200-line clone group is worth extracting; a 6-line one probably isn’t.

Instance count

The number of locations where the same code appears. A clone group with 5 instances means the same block was copied to 5 places. Fixing a bug in the logic requires updating all 5.

Clone groups and families

Clone groups

A clone group is a single duplicated code block found at 2+ locations. Each location is an instance.
This means one block of 8 lines appears in both files. Here’s what it looks like:
One clone group = one duplicated block. But the same two files may share more than one block:
Three separate clone groups, all between the same two files. That pattern is a clone family.

Clone families

A clone family is when multiple clone groups involve the same files. Those files share multiple distinct clones and were probably copy-pasted from each other.
This changes the refactoring approach. Individual clone groups suggest extracting a function. A clone family suggests the files themselves need to be merged or restructured.

When duplication is acceptable

Not all duplication should be eliminated. Context matters.
  • Test files: Test cases often repeat setup code intentionally. Abstracting test setup makes tests harder to read and debug. Use --production to exclude test/story/dev files entirely, or use dupes.ignore patterns for more granular control.
  • Generated code: Codegen output (GraphQL, Prisma, OpenAPI) is inherently duplicative. Exclude with dupes.ignore.
  • Small clones (< 10 lines): Very small clones are often idiomatic patterns (error handling, guard clauses) rather than meaningful duplication.
  • Cross-language ports: If you maintain both .ts and .js versions intentionally, use --skip-local to focus on cross-directory duplicates instead.
Premature abstraction is worse than duplication. If the duplicated code isn’t changing and isn’t causing bugs, leave it. Extract clones that are both large and in actively changing files. Use fallow health --hotspots to cross-reference.

Interpreting --threshold results

The --threshold flag sets a maximum allowed duplication percentage. If the project exceeds the threshold, fallow exits with code 1.
fallow dupes --threshold 15
Start with a threshold above your current level, then ratchet it down over time. Combine with --baseline for even more gradual adoption.

How suffix-array detection works

Fallow concatenates all token streams into one sequence, builds a with , and scans for repeated subsequences above the minimum length. This runs in O(n log n) time, no pairwise file comparison needed.
Token-based clone detection was pioneered by Baker (1995). Suffix-array approaches for scalable clone detection were developed by Li et al. (2006). Fallow’s approach is closest to the suffix-array method, with normalization levels corresponding to clone types.

Limitations

  • Type-3 clones (gapped clones with inserted/deleted lines) are not detected. If someone copied a function and added a few lines in the middle, fallow will report the matching portions as separate smaller clones rather than one large near-miss.
  • Type-4 clones (semantically equivalent but syntactically different) are not detected. Two functions that do the same thing but are written differently will not be flagged.
  • Cross-file-type detection only works between .ts and .js files (via --cross-language). Other language pairs are not supported.
  • Minimum size thresholds mean very small clones (below --min-tokens / --min-lines) are invisible. This is intentional: small clones are usually idiomatic patterns.
  • Semantic mode false positives: Normalizing identifiers and literals can match code that is structurally similar but semantically unrelated. Review semantic-mode results before acting.

JSON _meta object

When --explain is passed (or via MCP), the JSON output includes a _meta object:
AI agents and CI systems can use this to interpret results without consulting external documentation.