# Fallow CLI Reference Complete command and flag specifications for all fallow CLI commands. --- ## Table of Contents - [`dead-code`: Dead Code Analysis](#dead-code-dead-code-analysis) - [`dupes`: Duplication Detection](#dupes-duplication-detection) - [`fix`: Auto-Remove Unused Code](#fix-auto-remove-unused-code) - [`list`: Project Introspection](#list-project-introspection) - [`init`: Config Generation](#init-config-generation) - [`migrate`: Config Migration](#migrate-config-migration) - [`health`: Function Complexity Analysis](#health-function-complexity-analysis) - [`audit`: Changed-File Quality Gate](#audit-changed-file-quality-gate) - [`flags`: Feature Flag Detection](#flags-feature-flag-detection) - [`security`: Security Candidate Detection](#security-security-candidate-detection) - [`explain`: Rule Explanation](#explain-rule-explanation) - [`schema`: CLI Introspection](#schema-cli-introspection) - [`config-schema`: Config JSON Schema](#config-schema-config-json-schema) - [`plugin-schema`: Plugin JSON Schema](#plugin-schema-plugin-json-schema) - [`rule-pack-schema`: Rule Pack JSON Schema](#rule-pack-schema-rule-pack-json-schema) - [`config`: Show Resolved Config](#config-show-resolved-config) - [Global Flags](#global-flags) - [Environment Variables](#environment-variables) - [Output Formats](#output-formats) - [JSON Output Structure](#json-output-structure) - [Configuration File Format](#configuration-file-format) - [Inline Suppression Comments](#inline-suppression-comments) --- ## `dead-code`: Dead Code Analysis Analyzes the project for unused files, exports, dependencies, types, members, and more. Running `fallow` with no subcommand runs all analyses (dead code + duplication + complexity). Use `fallow dead-code` for dead code only. ### Flags | Flag | Type | Default | Description | |---|---|---|---| | `--include-dupes` | `bool` | `false` | Cross-reference with duplication findings | | `--trace` | `string` | - | Trace export usage chain | | `--trace-file` | `string` | - | Show all edges for a file | | `--trace-dependency` | `string` | - | Trace where a dependency is used | | `--top` | `string` | - | Show only the top N items per category | | `--file` | `string` | - | Scope output to specific files. Only issues in the specified files are reported. Project-wide dependency issues are suppressed. Warns on non-existent paths. Useful for lint-staged | Common global flags for this command: [`--format`](#global-flags), [`--quiet`](#global-flags), [`--output-file`](#global-flags), [`--legacy-envelope`](#global-flags), [`--changed-since`](#global-flags), [`--max-file-size`](#global-flags), [`--production`](#global-flags), [`--no-production`](#global-flags), [`--production-dead-code`](#global-flags), [`--baseline`](#global-flags), [`--save-baseline`](#global-flags), [`--workspace`](#global-flags), [`--changed-workspaces`](#global-flags), [`--include-entry-exports`](#global-flags). ### Issue Type Filters | Flag | Issue Type | |---|---| | `--unused-files` | Unused files | | `--unused-exports` | Unused exports | | `--unused-deps` | Unused dependencies, devDependencies, optionalDependencies, type-only production deps, and test-only production deps | | `--unused-types` | Unused types | | `--private-type-leaks` | Opt-in API hygiene check (default `off`) for exported signatures that reference same-file private types. Storybook `*.stories.*` story files and framework routing convention files (Next.js App + Pages Router, Gatsby, Remix v2, TanStack Router, Expo Router) are skipped to avoid noise. Enable via this flag or `private-type-leaks: "warn"` / `"error"` in [`rules`](#rules-configuration). | | `--unused-enum-members` | Unused enum members | | `--unused-class-members` | Unused class members | | `--unresolved-imports` | Unresolved imports | | `--unlisted-deps` | Unlisted dependencies | | `--duplicate-exports` | Duplicate exports | | `--circular-deps` | Circular dependencies | | `--re-export-cycles` | Re-export cycles (`kind: multi-node` for barrel files re-exporting from each other in a loop, `kind: self-loop` for a barrel re-exporting from itself). File-scoped finding; chain propagation through the loop is a no-op so imports may silently come up empty. Distinct from `--circular-deps` (runtime cycles). | | `--boundary-violations` | Boundary violations (imports crossing architecture zone boundaries, unzoned source files when `boundaries.coverage.requireAllFiles` is set, and forbidden calls from `boundaries.calls.forbidden`; suppression token `boundary-violation`, with `boundary-call-violation` and `boundary-call-violations` accepted as aliases for the whole family) | | `--policy-violations` | Rule-pack policy violations (banned calls and banned imports declared via the `rulePacks` config key) | | `--stale-suppressions` | Stale suppression comments or `@expected-unused` JSDoc tags | | `--unused-catalog-entries` | Unused pnpm catalog entries | | `--empty-catalog-groups` | Empty named pnpm catalog groups | | `--unresolved-catalog-references` | Package references to missing pnpm catalog entries | | `--unused-dependency-overrides` | Unused pnpm dependency overrides | | `--misconfigured-dependency-overrides` | Malformed pnpm dependency overrides | ### Examples ```bash # Full analysis with JSON output fallow dead-code --format json --quiet # Only unused exports fallow dead-code --format json --quiet --unused-exports # PR check: only changed files fallow dead-code --format json --quiet --changed-since main --fail-on-issues # CI mode with SARIF upload fallow dead-code --ci # Production-only analysis fallow dead-code --format json --quiet --production # Single workspace package fallow dead-code --format json --quiet --workspace my-package # Multiple workspaces: comma-separated fallow dead-code --format json --quiet --workspace web,admin # Glob (matches package name OR relative path) fallow dead-code --format json --quiet --workspace 'apps/*' # Exclude a workspace from the set fallow dead-code --format json --quiet --workspace 'apps/*,!apps/legacy' # Monorepo CI: auto-scope to workspaces containing any file changed since origin/main fallow dead-code --format json --quiet --changed-workspaces origin/main # Debug: trace an export fallow dead-code --format json --quiet --trace src/utils.ts:myFunction # Incremental adoption with baseline fallow dead-code --format json --quiet --save-baseline fallow-baselines/dead-code.json fallow dead-code --format json --quiet --baseline fallow-baselines/dead-code.json --fail-on-issues # Regression detection: save baseline on main, compare on PRs fallow dead-code --format json --quiet --save-regression-baseline fallow dead-code --format json --quiet --fail-on-regression --tolerance 2% # Scope to specific files (e.g., lint-staged) fallow dead-code --format json --quiet --file src/utils.ts --file src/helpers.ts # Catch typos in entry file exports fallow dead-code --format json --quiet --include-entry-exports ``` --- ## `dupes`: Duplication Detection Finds code duplication and clones across the project. By default, `fallow dupes` skips generated framework output matching `**/.next/**`, `**/.nuxt/**`, `**/.svelte-kit/**`, `**/.turbo/**`, `**/.parcel-cache/**`, `**/.vite/**`, `**/.cache/**`, `**/out/**`, and `**/storybook-static/**`. These defaults merge with `duplicates.ignore`. Set `duplicates.ignoreDefaults = false` to opt out and use only your configured ignore list. If the reported duplication percentage drops after upgrading, this generated-output filtering is the expected reason. ### Flags | Flag | Type | Default | Description | |---|---|---|---| | `--mode` | `strict\|mild\|weak\|semantic` | - | Detection mode | | `--min-tokens` | `string` | - | Minimum token count for a clone | | `--min-lines` | `string` | - | Minimum line count for a clone | | `--min-occurrences` | `string` | - | Minimum number of occurrences before a clone group is reported (must be ≥ 2). Raise to skip pair-only clones and focus on widespread copy-paste worth refactoring. `fallow init` writes `minOccurrences: 3` into new projects. | | `--threshold` | `string` | - | Fail if duplication exceeds this percentage | | `--skip-local` | `bool` | `false` | Only report cross-directory duplicates | | `--cross-language` | `bool` | `false` | Strip type annotations for TS↔JS matching | | `--ignore-imports` | `bool` | `false` | Exclude import declarations from clone detection | | `--top` | `string` | - | Show only the N most-duplicated clone groups (sorted by instance count desc, tiebreak: line count desc, then path/line). Summary stats reflect the full project. | | `--trace` | `string` | - | Deep-dive clones. `FILE:LINE` traces all clones at a location; `dup:` traces a clone group by the stable fingerprint shown in the listing and on `clone_groups[].fingerprint` in JSON. Fingerprints are usually `dup:<8hex>` and widen only on rare report collisions. Trace output adds an extract-function suggestion, estimated savings, and a best-effort proposed name per group | Common global flags for this command: [`--format`](#global-flags), [`--quiet`](#global-flags), [`--changed-since`](#global-flags), [`--baseline`](#global-flags), [`--save-baseline`](#global-flags), [`--workspace`](#global-flags), [`--changed-workspaces`](#global-flags), [`--group-by`](#global-flags), [`--explain-skipped`](#global-flags). ### Detection Modes | Mode | Behavior | |------|----------| | `strict` | Exact token match (no normalization) | | `mild` | Syntax normalized (whitespace, semicolons) | | `weak` | Different literal values treated as equivalent | | `semantic` | Renamed variables also treated as equivalent | ### Examples ```bash # Default duplication scan fallow dupes --format json --quiet # Semantic mode (detects renames) fallow dupes --format json --quiet --mode semantic # Cross-directory only, fail at 5% fallow dupes --format json --quiet --skip-local --threshold 5 # Trace clones at a specific location fallow dupes --format json --quiet --trace src/utils.ts:42 # Deep-dive a clone group by its dup: fingerprint (from the listing or JSON) fallow dupes --format json --quiet --trace dup:7f3a2c1e # Only check duplication in changed files fallow dupes --format json --quiet --changed-since main # Incremental CI fallow dupes --format json --quiet --save-baseline fallow-baselines/dupes.json fallow dupes --format json --quiet --baseline fallow-baselines/dupes.json --threshold 5 ``` --- ## `fix`: Auto-Remove Unused Code Auto-removes unused exports, dependencies, enum members, and pnpm catalog entries. ### Flags | Flag | Type | Default | Description | |---|---|---|---| | `--dry-run` | `bool` | `false` | Show what would be removed without modifying files. For `add-to-config` actions, prints a unified-diff preview of the proposed config write; JSON mode includes the diff under a `proposed_diff` field on the fix entry. | | `--yes` | `bool` | `false` | Skip confirmation prompt (**required** in non-TTY) | | `--no-create-config` | `bool` | `false` | Refuse to create a new `.fallowrc.json` when none exists. The duplicate-export config-add path is skipped with `skip_reason: "no_create_config"`; source-file edits proceed normally. Use in pre-commit hooks, CI bots, and `fallow watch` where silently materialising a new top-level file would surprise the user. | Common global flags for this command: [`--format`](#global-flags), [`--quiet`](#global-flags). ### What gets fixed - Unused exports (removes the `export` keyword; whole-enum block when every member is unused) - Unused dependencies (removed from `package.json`) - Unused enum members (removed from the declaration) - Unused pnpm catalog entries (removed from `pnpm-workspace.yaml` by line-aware deletion). Object-form entries are removed as one block. By default, fallow also removes a contiguous YAML comment block immediately above the entry when it clearly belongs to that entry; configure this with `fix.catalog.deletePrecedingComments` (`"auto"`, `"always"`, or `"never"`). Two escape hatches keep curated comments safe regardless of policy: a `# fallow-keep` marker on any line in the block preserves it, and the `auto` policy additionally preserves section-banner blocks whose body starts with three or more `=`, `-`, `*`, `_`, `~`, `+`, or `#` characters (e.g. `# === React 18 production pins ===`). Other comments and stylistic choices are preserved. When the last entry of a catalog group is removed, the header is rewritten to `catalog: {}` / `: {}` so pnpm doesn't reject the resulting null value. Entries with non-empty `hardcoded_consumers` are skipped to avoid breaking `pnpm install`; the skip is surfaced in the JSON fix output as `{"type": "remove_catalog_entry", "applied": false, "skipped": true, "skip_reason": "hardcoded_consumers", "consumers": [...]}`. The JSON action carries both `line` (first deleted line, the leading comment when policy absorbs one) and `entry_line` (the catalog entry's original 1-based line); use `entry_line` as a stable anchor across policy changes. After a successful catalog edit the CLI emits a one-line `Run pnpm install to refresh pnpm-lock.yaml` reminder, and the human stderr summary appends `(+M catalog comment lines)` to the fixed-issue count when comment lines were absorbed. The JSON envelope carries a top-level `"skipped"` count alongside `"total_fixed"` for partial-fix gating. - Duplicate exports (appends an `ignoreExports` rule to your fallow config file). When no fallow config file exists, `.fallowrc.json` is created using the same scaffolding `fallow init` would emit (framework detection, `$schema`, `entry`, `ignorePatterns`, etc.) and the rules are layered on top. Inside a monorepo subpackage (`pnpm-workspace.yaml`, `package.json#workspaces`, `turbo.json`, `lerna.json`, or `rush.json` above the invocation directory) the create-fallback refuses to fire and emits `skip_reason: "monorepo_subpackage"` with a relative `workspace_root` path pointing at the workspace root. The applied entry carries `created_files: [".fallowrc.json"]` so consumers can detect file-creation side effects programmatically. ### On-disk drift protection `fallow fix` captures every parsed source file's xxh3 content hash during the in-process analysis and recomputes it at fix time. Files whose hash drifted between analysis and write (parallel editor save, CI rebase, concurrent tool) are skipped with `{"type": "skipped", "path": "...", "skipped": true, "skip_reason": "content_changed"}` in the JSON output and `Skipping : file content changed since fallow dead-code ran. Re-run fallow fix to refresh the analysis first.` on stderr (gated on non-quiet). A run with any content-changed skip exits with code 2 so CI does not treat the partial run as a clean no-op. The JSON envelope's top-level `skipped_content_changed: number` is always present and disjoint from `skipped` (which still tallies catalog / YAML guard skips only). Per-file writes are batched: each rewrite is staged to a sibling temp file, and the orchestrator promotes the batch only after every stage succeeds. A stage failure leaves every target file at its original content. Hash precondition covers source files (TS, JS, Vue, Svelte, Astro, MDX); `package.json` and `pnpm-workspace.yaml` are not in the captured hash map because the extract layer does not parse them, but the dep and catalog fixers re-parse those files at fix time as the natural safety net. ### Low-confidence export removals Issue #602: `fallow fix` withholds unused-export removals when the consumer may be invisible to static analysis, because stripping a real export breaks `tsc` and the build. Two cases are skipped: - **Off-graph consumer directories.** The file is under any of `__mocks__`, `__fixtures__`, `fixtures`, `e2e`, `e2e-tests`, `cypress`, `playwright`, `examples`, `evals`, `golden` (matched on any path segment). Catches Vitest mock aliases, off-workspace e2e suites, and fixture / golden harnesses. Plain `test` / `tests` / `__tests__` are deliberately NOT on the list, so genuinely-dead test helpers still auto-remove. - **Files with an unresolved import.** The file itself imports something fallow could not resolve, so its local usage graph is incomplete. JSON output carries `{"type": "skipped", "path": "...", "skipped": true, "skip_reason": "low_confidence_off_graph"}` (or `"low_confidence_unresolved_imports"`) plus a top-level counter `skipped_low_confidence_exports: number` (always present), disjoint from `skipped`. Unlike the drift and encoding skips this is INTENTIONAL and does NOT change the exit code; the export stays reported by `fallow dead-code` for manual review. High-confidence exports in normal source files are removed unchanged. The AI agent should report kept exports to the user and let them decide whether the export is truly unused before removing it by hand. ### File encoding contract `fallow fix` is UTF-8 only. Two encoding shapes that previously caused silent corruption are handled explicitly (issue #475): - **UTF-8 BOM round-trip.** Files with a leading UTF-8 byte-order mark (`EF BB BF`, common on Windows-authored TypeScript) are read with the BOM stripped before line-offset computation and parsing, so reported line numbers do not shift by the BOM codepoint, and the BOM is re-prepended on write so the file's encoding is preserved on round-trip. fallow neither adds nor removes a BOM; if your input has one, the output has one. - **Mixed CRLF / LF rejection.** Files containing both `\r\n` and bare-LF line endings (common after cross-platform edits without `core.autocrlf`) are skipped instead of silently rewritten to the wrong offsets. The stderr message names the remediation: `Skipping : file has mixed CRLF/LF line endings. Normalize with dos2unix or set git config core.autocrlf input, then re-run fallow fix.`. JSON output carries `{"type": "skipped", "path": "...", "skipped": true, "skip_reason": "mixed_line_endings"}` plus a top-level counter `skipped_mixed_line_endings: number` (always present) disjoint from `skipped_content_changed`. Any non-zero mixed-EOL count exits the run with code 2. **The skip is NOT self-healing**. Re-running `fallow fix` produces the same skip; the AI agent or user must run `dos2unix ` (or set `git config core.autocrlf input` and re-checkout) before fallow can act on the file. When the same file carries findings for multiple fixers (e.g. an unused export AND an unused enum member), the skip is reported once per file, not once per fixer. ### Examples ```bash # Preview changes fallow fix --dry-run --format json --quiet # Apply changes (--yes required in agent/CI environments) fallow fix --yes --format json --quiet ``` --- ## `list`: Project Introspection Inspect discovered files, entry points, detected frameworks, and architecture boundary zones. ### Flags | Flag | Type | Default | Description | |---|---|---|---| | `--entry-points` | `bool` | `false` | List detected entry points | | `--files` | `bool` | `false` | List all discovered files | | `--plugins` | `bool` | `false` | List active framework plugins | | `--boundaries` | `bool` | `false` | Show architecture boundary zones, rules, per-zone file counts, and `logical_groups[]` for `autoDiscover` parents | | `--workspaces` | `bool` | `false` | Show discovered monorepo workspaces plus any workspace-discovery diagnostics (malformed `package.json`, unreachable glob matches, missing tsconfig references). Available as the `fallow workspaces` alias too. | Common global flags for this command: [`--format`](#global-flags), [`--quiet`](#global-flags). ### Examples ```bash fallow list --files --format json --quiet fallow list --entry-points --format json --quiet fallow list --plugins --format json --quiet fallow list --boundaries --format json --quiet fallow list --workspaces --format json --quiet fallow workspaces --format json --quiet # alias of `fallow list --workspaces` ``` The `--workspaces` JSON output carries `workspaces[]` (name, project-root-relative path, `is_internal_dependency` bool) plus `workspace_diagnostics[]`. Each diagnostic has a `kind` discriminator (`undeclared-workspace`, `malformed-package-json`, `glob-matched-no-package-json`, `malformed-tsconfig`, `tsconfig-reference-dir-missing`) with a typed payload (`error`, `pattern`, or none). The same `workspace_diagnostics[]` array is also surfaced on `fallow dead-code --format json`, `fallow dupes --format json`, and `fallow health --format json` envelopes (omitted when empty). A malformed ROOT `package.json` exits 2 at config load; everything else warns and continues. The `--boundaries` JSON output carries `boundaries.logical_groups[]` alongside the existing `zones[]` / `rules[]` arrays. Each logical-group entry surfaces a user-authored `autoDiscover` parent zone (which expansion otherwise flattens into per-child zones like `features/auth` / `features/billing`): `name`, `children`, `auto_discover` (verbatim user strings), `status` (`ok` / `empty` / `invalid_path`), `source_zone_index`, summed `file_count`, optional `authored_rule` (the pre-expansion `{ allow, allowTypeOnly }` keyed on the parent), optional `fallback_zone` cross-reference when the parent also kept its own `patterns` (Bulletproof case), optional `merged_from` (parent zone indices when the user declared the same parent name twice; surfaces the duplicate in JSON instead of only in `tracing::warn!`), optional `original_zone_root` (echo of the parent's `root` subtree scope for monorepo patchers), and optional `child_source_indices` (parallel to `children`, attributing each child to a specific `auto_discover` entry when multiple paths were authored). The full shape is documented in `docs/output-schema.json` under `ListBoundariesOutput`. --- ## `init`: Config Generation Creates a config file in the project root. ### Flags | Flag | Type | Default | Description | |---|---|---|---| | `--toml` | `bool` | `false` | Create `fallow.toml` instead of `.fallowrc.json` | | `--agents` | `bool` | `false` | Scaffold a starter `AGENTS.md` guide for coding agents. Prefills Install (from the `packageManager` field, or pnpm via `pnpm-workspace.yaml`), Test (only when exactly one of Vitest / Jest / Playwright is present), Typecheck (`tsc --noEmit` when `tsconfig.json` exists), and monorepo module-boundary lines; everything ambiguous stays blank (no lockfile sniffing). Prefilled command lines carry an HTML provenance comment. Refuses to overwrite an existing `AGENTS.md` | | `--hooks` | `bool` | `false` | Scaffold a pre-commit git hook that runs `fallow audit --base --quiet --gate-marker pre-commit`. Alias for `fallow hooks install --target git` | | `--branch` | `string` | - | Fallback base branch for the pre-commit hook when no upstream is set (default: `main`). Only used with `--hooks` | | `--decline` | `bool` | `false` | Record that this project deliberately stays unconfigured: persists a decline so the first-contact setup hint and the `setup` next-step stop appearing here. Writes no config file; idempotent | Common global flags for this command: [`--root`](#global-flags), [`--config`](#global-flags). ### Examples ```bash fallow init # creates .fallowrc.json with $schema fallow init --toml # creates fallow.toml fallow init --agents # scaffolds a starter AGENTS.md prefilled from detected project info (never overwrites) fallow hooks install --target git fallow hooks install --target git --branch develop # fallback base branch when no upstream is set ``` ## `hooks`: Managed Hook Status And Installation ```bash fallow hooks status --format json fallow hooks install --target git fallow hooks install --target agent fallow hooks uninstall --target git fallow hooks uninstall --target agent ``` `hooks status` is read-only and reports `git`, `claude`, and `codex` surfaces. Each surface includes `installed`, `managed_block_present`, `user_edited`, and `path`; generated agent scripts also include `script_version` and `min_version_floor`. Use it before mutating setup so agents can distinguish fallow-managed artifacts from user-owned hooks or partial managed blocks. --- ## `migrate`: Config Migration Migrates configuration from knip and/or jscpd to fallow. Auto-detects config files. ### Flags | Flag | Type | Default | Description | |---|---|---|---| | `--toml` | `bool` | `false` | Output as `fallow.toml` (mutually exclusive with `--jsonc`) | | `--jsonc` | `bool` | `false` | Write to `.fallowrc.jsonc` instead of `.fallowrc.json`. Same JSONC content either way; the `.jsonc` extension lets editors auto-detect JSON-with-comments syntax highlighting | | `--dry-run` | `bool` | `false` | Preview without writing | | `--from` | `string` | - | Specify source config file path | Common global flags for this command: [`--root`](#global-flags), [`--config`](#global-flags). Without `--jsonc` or `--toml`, fallow auto-mirrors the source extension: a `knip.jsonc` migration writes `.fallowrc.jsonc`, a `knip.json` migration writes `.fallowrc.json`. ### Detected Source Configs - `knip.json`, `knip.jsonc`, `.knip.json`, `.knip.jsonc` - `package.json` embedded `knip` field - `.jscpd.json` - `package.json` embedded `jscpd` field ### Examples ```bash fallow migrate --dry-run # preview fallow migrate # auto-detect; mirrors source extension fallow migrate --jsonc # force .fallowrc.jsonc output fallow migrate --toml # output as fallow.toml fallow migrate --from knip.jsonc ``` --- ## `health`: Function Complexity & File Health Analysis Analyzes function complexity across the project using cyclomatic and cognitive complexity metrics. By default all sections are included (health score, complexity findings, file scores, hotspots, and refactoring targets). Use `--complexity`, `--file-scores`, `--hotspots`, `--targets`, or `--score` to show only specific sections. Angular templates contribute synthetic `