Skip to main content
The @fallow-cli/fallow-node package exposes the main fallow analyses as async Node.js functions. The bindings avoid CLI subprocesses and JSON parsing, reuse the shared analysis layer, and return the same JSON report envelopes the CLI emits for --format json. The optional detectSimilarCode function verifies and launches its exact local model companion. Use them when you want to embed fallow inside another tool, a Node.js server, an editor extension, or a custom script that otherwise would shell out to the CLI.

Install

The package is a native NAPI-RS addon with platform-specific optionalDependencies for macOS (arm64, x64), Linux (gnu + musl on arm64 and x64), and Windows (x64, arm64). npm picks the matching binary at install time. Node 18 or newer is required.

Basic usage

Every function returns a promise resolving to the same JSON envelope the CLI emits when called with --format json: a top-level kind discriminator on typed roots, schema_version, summary, relative paths, injected actions arrays, and (when explain: true) a _meta block with docs links.

API

All eight functions are async and accept an optional options object. Unknown fields are ignored. Enum-like fields take lowercase CLI-style literals ("mild", "cyclomatic", "handle", "low").

Shared options

Every options object extends AnalysisOptions:

Dead-code options

detectDeadCode, detectCircularDependencies, and detectBoundaryViolations accept the same superset, DeadCodeOptions. Setting any of the filter booleans below restricts the report to the selected issue types; leaving them all unset returns every category (the CLI’s default behavior).

Duplication options

DuplicationOptions adds duplication-specific fields on top of AnalysisOptions: Each returned clone group includes spread. Near-miss groups also include similarity. Duplication stats can include clone_groups_ignored and near_candidates_skipped; zero values are omitted.

Similar-code options

SimilarCodeOptions adds model-backed discovery fields on top of AnalysisOptions: The loader resolves the exact-version fallow-similar-code package and verifies its native binary before source is read. detectSimilarCode never downloads the model. After explicit user approval, run fallow similar-code setup --local once through the CLI. Results remain unverified. Read Semantic similar code before using a score to plan a refactor.

Feature flag options

FeatureFlagsOptions adds one field on top of AnalysisOptions:

Complexity / health options

ComplexityOptions mirrors the fallow health flag surface:

Structured errors

Rejected promises throw a FallowNodeError (a plain Error with extra fields) that mirrors the CLI’s structured error surface:
The exit-code ladder matches the CLI: 0 ok, 2 generic / validation, 7 network (paid features only), etc.

When to use bindings vs the CLI

Both paths run the same analysis engine and return the same data. The bindings are not a reduced subset.

Limitations

  • The bindings wrap the one-shot analyses. Commands that write to the filesystem (fix, init, hooks install, hooks uninstall, audit --save-baseline, license activate, coverage setup) are not exposed.
  • detectSimilarCode is read-only and never performs its first model download. Use the CLI after explicit approval: fallow similar-code setup --local.
  • No baseline or regression support yet. Use the CLI’s --baseline / --save-baseline flags for those workflows.
  • No watch mode. If you want incremental analysis, re-invoke the relevant function; fallow’s per-file cache makes repeat runs fast.
  • The API surface is young; breaking changes between minor versions are possible until it stabilizes.