Skip to main content
fallow similar-code finds functions that may do the same kind of work even when they are written differently. Use it after fallow dupes when copied structure is not the whole story. The normal duplication detector finds exact, normalized, and near-miss copies. Similar-code discovery compares the meaning represented by complete functions.
Every result is an unverified candidate. A similarity score is not a probability, proof that behavior matches, or permission to refactor. Inspect both functions and their tests before making a decision.

Set up the local model

The matching native companion installs with the main fallow npm package. Check whether its pinned model is ready:
The first download needs your explicit confirmation:
Setup shows the model, license, and download size before it asks. Use --yes only when you already approved the download and need a non-interactive command. Project config and agents cannot approve setup for you. After setup, analysis is offline. Function source stays on your machine. The companion receives bounded source over local process input and does not save it. Fallow persists derived vectors in the project cache so later runs are faster.

Find candidates

Machine-readable output uses an independent envelope:
A candidate looks like this:
The score is meaningful only for the pinned model and current settings. Use it to rank review work, not to compare projects or set a universal quality bar. The root output also records:
  • the exact companion, model revision, artifact digest, and parameters
  • whether every analysis phase completed
  • limits and skipped work
  • vector-cache hits and misses
  • non-severity diagnostics
An empty candidate list is conclusive only when completion.status is "complete". A "partial" run tells you which limit or provider problem made the result incomplete.
--file keeps pairs that touch the selected file. --changed-since and workspace options use the same project scoping as other fallow analyses.

Inspect before judging

Copy candidate_id from the discovery output:
Run this from the same project root and reuse the discovery scope plus the effective generation.threshold and generation.min_lines values. Human output includes the calibrated part of the inspect command. MCP callers pass the same discovery options to inspect_similar_code. Inspect first reproduces the candidate against your current source. This prevents a stale result from being reviewed after either function changed. It then adds bounded evidence where available:
  • source windows for both functions
  • import-graph relationship and entry-point reachability
  • callers and callees
  • CODEOWNERS ownership and recent churn
  • related tests
  • overlap with deterministic duplication results
  • syntax clues such as async behavior, throws, awaits, and possible side effects
Every evidence source has an availability state. Missing context stays missing. Fallow does not turn absence of evidence into a positive verdict.

Record a separate verdict

The raw candidate document never changes. A person or agent writes a separate verdict after inspecting the code:
Join the documents:
The three yes, no, or unknown judgments answer different questions: Use null when you cannot answer. refactor_safe: true requires behaviorally_equivalent: true, which requires candidate_worthy: true. Available outcomes are same-responsibility, related-but-distinct, intentional-duplication, unrelated, and needs-human-review.

Use it with an agent

The MCP server exposes two read-only tools:
  • find_similar_code returns unverified candidates with provenance and completion accounting.
  • inspect_similar_code reproduces one candidate and returns its evidence packet.
Neither tool downloads a model, edits source, or produces a verdict. If setup is missing, the agent should ask you to run fallow similar-code setup --local. An agent should return needs-human-review when tests, callers, behavior, or side effects are unclear.

Configure project defaults

These fields tune candidate discovery only. Config cannot choose a model, provider, executable, download, or credential. Clear derived project vectors without deleting the downloaded model:

Where it does not run

Similar-code discovery is separate from bare fallow, audit, dupes, CI gates, SARIF, LSP, VS Code diagnostics, and auto-fix. It is a review aid, not a new finding category. It accepts only the official pinned local model and does not send source to a remote provider.

See also

Code duplication

Find deterministic and near-miss copied structure.

Agent integration

Connect the read-only discovery and inspect tools.

Configuration

Set project-owned thresholds, size floors, and ignore globs.