fallow similar-code
Find the subcommands, options, output fields and exit codes of fallow similar-code, which finds functions that may do the same job.
fallow similar-code finds pairs of functions that may do the same job, also when their code is different.
For the concepts and the workflow, read Similar code.
Synopsis
fallow similar-code [OPTIONS] [PATH] [COMMAND]
The command is opt-in. Bare fallow, fallow audit, fallow dupes and the CI formats do not run it. It needs the fallow-similar-code program next to the fallow executable and a model that setup downloads.
Subcommands
| Subcommand | Description |
|---|---|
status | Show the readiness of the similar-code companion and the pinned model without reading project source |
setup | Download and verify the pinned local model after explicit confirmation |
inspect | Reproduce and inspect one unverified candidate with bounded source evidence |
review | Join candidate JSON with a separate human or agent verdict document |
cache | Manage the user-local, project-namespaced vector cache. |
Without a subcommand, fallow similar-code compares the functions of the project and prints the candidates.
status
fallow similar-code status [OPTIONS]
This command has no options of its own.
status does not read the source of the project. It exits with code 0 when the model is not ready. Read model_ready in the JSON output.
setup
fallow similar-code setup [OPTIONS] --local
| Option | Description |
|---|---|
--local | Confirm this is local setup for the first-party pinned model |
--yes | Confirm non-interactively. Required when stdin is not a terminal |
setup shows the model, its license and the download size, and asks for a confirmation. Use --yes only when a person approved the download.
inspect
fallow similar-code inspect [OPTIONS] <CANDIDATE_ID>
| Argument | Description |
|---|---|
<CANDIDATE_ID> | Snapshot-stable candidate identity from fallow similar-code |
| Option | Description |
|---|---|
--candidates <PATH> | Raw discovery JSON containing the selected candidate |
review
fallow similar-code review [OPTIONS] --candidates <PATH> --verdicts <PATH>
| Option | Description |
|---|---|
--candidates <PATH> | Raw fallow similar-code --format json document |
--verdicts <PATH> | Versioned verdict JSON document |
--require-verdict-for-each-candidate | Fail closed unless every candidate receives a safely matched verdict |
cache
fallow similar-code cache [OPTIONS] <COMMAND>
| Subcommand | Description |
|---|---|
clear | Remove cached vectors after explicit confirmation |
clear
fallow similar-code cache clear [OPTIONS]
| Option | Description |
|---|---|
--yes | Confirm deletion of derived vectors |
cache clear removes the cached vectors of the project. The downloaded model stays.
Options
These options apply to the run without a subcommand.
| Argument | Description |
|---|---|
[PATH] | Scope reported findings to this file or directory (default: whole project). The full project graph is still built; only reported items are narrowed |
| Option | Description |
|---|---|
--threshold <0..1> | Minimum cosine similarity retained as an unverified candidate |
--min-lines <N> | Minimum source lines per extracted function |
--top <N> | Cap displayed candidates after bounded full-corpus comparison |
--file <PATH> | Report pairs touching one of these project-relative files |
The global options are in these groups: Project, Output, Scope, Baselines, Gates, Duplication, Type-aware, Performance.
--threshold and --min-lines take their default from the similarCode config. The command accepts the human and json formats, and these global options: --root, --config, --allow-remote-extends, --format, --pretty, --quiet, --no-cache, --threads, --changed-since, --diff-file, --diff-stdin, --workspace, --changed-workspaces, --max-file-size, --explain and --output-file. A scope option compares only the pairs in which at least one function is fully in scope.
Option details
Install the program
The fallow npm package does not install fallow-similar-code. Fallow accepts it only at the same version as fallow, and it searches neither PATH nor the executables of the project.
| How you run fallow | What to install |
|---|---|
fallow is a dependency of the project | npm install --save-dev fallow-similar-code@<fallow version>. The fallow npm launcher finds the package, checks its signature and gives the program to fallow. |
A global fallow from npm | npm install --global fallow-similar-code@<fallow version> |
npx | Start both packages together: npx -p fallow@<version> -p fallow-similar-code@<version> fallow similar-code. An MCP client that starts npx fallow-mcp needs the same pair. |
A fallow binary from Homebrew, cargo install or a release archive | Download the release archive of the same version for your platform from GitHub Releases. Copy fallow-similar-code from the archive into the directory of the fallow executable. |
Fallow resolves symlinks before it looks for the program. For Homebrew, the directory is the Cellar directory, for example /opt/homebrew/Cellar/fallow/<version>/bin, not the directory of the /opt/homebrew/bin/fallow link. A Homebrew upgrade installs fallow in a new Cellar directory, so copy the program of the new version again. You can also install both packages from npm: npm install --global fallow@<version> fallow-similar-code@<version>.
When fallow does not find the program, fallow similar-code exits with code 3 and the message names the install step for your setup.
Inspect a saved candidate
inspect reads the candidate from the discovery JSON of --candidates, so you do not give the discovery options again. Run it from the same project root. If one of the two functions changed after the discovery, inspect does not show the old result. An MCP client gives the candidate_id and the candidate snapshot of the find_similar_code response to inspect_similar_code.
Verdict matching
review matches each verdict to a candidate by its candidate_id first. A verdict with an unknown candidate_id matches by its review_key. The review_key comes only from the source of the two functions. When one function is copied without a change into two files, two candidates can have the same review_key. These rules apply:
- Verdicts that match by
candidate_idcan share areview_key. To pass--require-verdict-for-each-candidate, write one verdict for each candidate. - A
review_keymust be unique only among the verdicts that match byreview_key. Otherwisereviewexits with code 2. reviewdoes not apply areview_keyverdict that matches more than one candidate. It adds the diagnosticFALLOW_SIMILAR_CODE_REVIEW_KEY_AMBIGUOUS.reviewexits with code 2 when two verdicts have the samecandidate_id, when thereview_keyof a verdict does not match itscandidate_id, when two verdicts match the same candidate, or when a verdict matches no candidate.- Each input file can have 16 MiB at most.
Output
The human output starts with the line Similar-code candidates (unverified). Each candidate then has these lines:
- the candidate id, the cosine similarity and its band
- the file, the line and the name of each of the two functions
- an
Inspect:line with thefallow similar-code inspectcommand for the candidate
The output ends with a Completion: line (Complete or Partial) and a Cache: line with the cache hits and misses.
With --format json, the output has these top-level fields:
| Field | Content |
|---|---|
kind | "similar-code". The subcommands give "similar-code-status", "similar-code-inspect", "similar-code-review" and "similar-code-cache-clear". |
schema_version, version, elapsed_ms | The version of this output format, the fallow version and the run time. |
generation | The provider, the model and the parameters of the run. |
candidates | The unverified candidates, in a fixed order. |
completion | Whether the run compared every function, and the cache statistics. Read it before you conclude that no candidate exists. |
diagnostics | Notes about the run, in a fixed order. |
The status output has model_ready, integrity_verified, model_id, model_revision, license, download_bytes, cache_dir, and problem when the model is not ready. The JSON output reference has each field.
Candidate fields
Each entry of candidates has this shape. The sample shows the fields of the output schema of fallow, with shortened ids and digests:
{
"candidate_id": "similar-code:candidate:v1:...",
"review_key": "similar-code:review:v1:...",
"left": {
"path": "src/orders/normalize.ts",
"name": "normalizeOrder",
"start_line": 12,
"start_column": 1,
"end_line": 34,
"end_column": 2,
"source_sha256": "..."
},
"right": {
"path": "src/imports/clean.ts",
"name": "cleanImportedOrder",
"start_line": 8,
"start_column": 1,
"end_line": 31,
"end_column": 2,
"source_sha256": "..."
},
"similarity": 0.91,
"similarity_band": "high",
"verification_status": "unverified",
"enrichment": {
"graph_relationship": "not-requested",
"entry_point_reachability": "not-requested",
"callers": "not-requested",
"callees": "not-requested",
"ownership": "not-requested",
"churn": "not-requested",
"tests": "not-requested",
"deterministic_clone_coverage": "not-requested",
"runtime": "not-requested"
},
"actions": [
{ "action": "inspect", "description": "...", "read_only": true },
{ "action": "review", "description": "...", "read_only": true }
]
}
| Field | Content |
|---|---|
candidate_id | The id of this pair in this discovery run. It changes when a function moves. |
review_key | A key from the source of the two functions only. It stays the same when a function moves. |
left, right | The two functions, in a fixed order. Lines and columns are 1-based. source_sha256 is the SHA-256 digest of the function source. |
similarity | The cosine similarity, from the pinned model. |
similarity_band | very-high from 0.95, high from 0.88, else moderate. |
verification_status | Always unverified. |
enrichment | For each kind of evidence: available, unavailable or not-requested. Discovery requests none, so inspect adds the evidence. |
actions | The read-only next steps, inspect and review. |
Review output
review gives kind: "similar-code-review". Each entry of its candidates has the unchanged candidate, the matched verdict (absent when no verdict matched), verdict_match and outcome. verdict_match is candidate-id, review-key, ambiguous-review-key or unverified. A candidate without a matched verdict gets the outcome needs-human-review. The review object has the SHA-256 digests of the two input files in candidates_sha256 and verdicts_sha256.
Exit codes
| Code | Meaning |
|---|---|
0 | The command ran. Candidates do not change the exit code. |
2 | Invalid input, for example cache clear without --yes, an invalid verdict document, or a candidate without a verdict under --require-verdict-for-each-candidate. Also a failure of the fallow-similar-code program after it starts. |
3 | The fallow-similar-code program is missing, or the model is not ready. Run fallow similar-code setup --local. |
Exit codes has the codes that all commands share.
Examples
# Check that the program and the model are ready
fallow similar-code status
# Download and verify the model
fallow similar-code setup --local
# Save the candidates of the project
fallow similar-code --format json --quiet > similar-code.json
# Show the code and the evidence of one candidate
fallow similar-code inspect <CANDIDATE_ID> --candidates similar-code.json
# Join the candidates with your verdicts
fallow similar-code review --candidates similar-code.json --verdicts verdicts.json
Related
- Similar code: the discovery, inspect and verdict workflow.
fallow dupes: copies of code with the same tokens.- MCP server: the
find_similar_codeandinspect_similar_codetools.