fallow fix
Find the options, output fields and exit codes of fallow fix, which removes unused exports, dependencies and enum members.
Remove unused code that fallow can remove safely, and add config rules for duplicate exports.
For what each fix changes and what it leaves alone, read Auto-fix.
Synopsis
fallow fix [OPTIONS] [PATH]
Options
| 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 |
|---|---|
--dry-run | Dry run, show what would be changed without modifying files |
--yes | Skip confirmation prompt (required in non-TTY environments like CI or AI agents) |
--no-create-config | Refuse to create a new fallow config file when none exists. Use this from pre-commit hooks, CI bots, and fallow watch where silently materialising a new top-level config file would surprise the user. |
The global options are in these groups: Project, Output, Scope, Baselines, Gates, Duplication, Type-aware, Performance.
--yes also has the name --force. Without --dry-run, a run that has no terminal needs --yes. Else fallow exits with code 2.
A run that writes changes reads and writes no parse or graph cache, as with --no-cache. A cache file in the checkout therefore never decides what fallow removes. On a large project such a run takes longer. --dry-run keeps the cache.
Fallow fixes these issue types: unused-export, unused-dependency, unused-enum-member, unused-catalog-entry and duplicate-export. It fixes unused-class-member only after type-aware analysis found no reference.
A class field with no ;, such as value = 1, continues into the next member when that member starts with [ or *. When fallow removes a method after such a field, it writes a ; in front of the next kept member, for example ;[key]() {}, so the class still parses.
Option details
Scope
These options narrow the fixes as they narrow the report: --workspace, --changed-workspaces, --changed-since, the package baselines of workspaces.changedSince, and a diff from --diff-file, --diff-stdin or FALLOW_DIFF_FILE. fallow fix plans only the findings that fallow dead-code reports with the same options. A workspace that does not exist stops the run with exit code 2.
The workspace parameter of the MCP tools fix_preview and fix_apply, and the scope of the GitHub Action with command: fix, follow the same rule.
Export lists
In an export { ... } list, on one line or on more lines, fallow fix removes only the unused names. It keeps the layout, the comments and the trailing commas of the names that stay. When no name stays, it deletes the statement. A re-export with a from clause also loads its module, so then fallow fix writes import './module'; in its place, and a module with side effects still runs. It deletes the statement when another static import or re-export of the file loads the same module, when the re-export is type-only, or when the names come from a declaration file such as types.d.ts. It removes an aliased name, such as export { a as b }, by its exported name b.
// Before: b is unused
export {
a,
b,
c,
} from "./mod";
// After
export {
a,
c,
} from "./mod";
Exports that a kept re-export names
fallow fix does not remove the export keyword of a declaration while a re-export that it keeps still names the declaration. Else the type check of the fixed code fails, because the re-export names a name that the file no longer exports. A re-export stays, for example, when fallow skips its file as low confidence, or when ignoreExports hides its names. To remove the export, remove the re-export first, then run fallow fix again.
A file in ignorePatterns is not in the module graph, so a re-export in that file cannot stop a removal. When such a file exports project code again, run the type check after fallow fix.
Declarations that export more than one name
One export keyword can export more than one name, for example export const { a, b } = source; or export const a = 1, b = 2;. fallow fix removes that keyword only when each name of the declaration is unused. It does not split the declaration, because a split runs the initializer twice. To remove one unused name, move it to its own declaration, then run fallow fix again.
Exports that test files import
With --production, fallow does not read test, story, fixture and bench files, the files of production.ignore, and the files that only a support entry point loads. An export that only these files import is unused in production, so fallow dead-code --production reports it. fallow fix --production does not remove the export keyword of such an export, because the import in the test file then fails. Only a file that an entry point reaches counts. An unused test helper does not stop a removal.
To find these imports, a production run also builds the module graph without production mode. It keeps the caches of that graph in the test-side-scan folder of the cache directory. In the JSON output of fallow dead-code --production, the finding has a test_importers object with files, the first 5 importing files, and remaining, the number of other importing files. Its remove-export action has auto_fixable: false. To remove the export, change or remove the import in the test file first.
Catalog entries
Fallow removes a catalog entry from pnpm-workspace.yaml line by line, and keeps the other comments and the layout of the file. It removes an entry in object form as one block. When it removes the last entry of a catalog group, it writes catalog: {} (or <name>: {}), because pnpm fails to install with an empty catalog: key. After the change, fallow tells you to run pnpm install, so that pnpm-lock.yaml stays current.
Fallow reports and removes only an entry or a group in block style, with one key on each line. An entry inside a flow mapping, such as ui: { react: "18" }, gives no finding, because fallow cannot remove it line by line. An entry that a merge key (<<) adds also gives no finding. Fallow still resolves the catalog: references to these entries.
Fallow also removes a block of comment lines directly above the entry. fix.catalog.deletePrecedingComments sets the policy:
| Value | Effect |
|---|---|
auto (default) | Fallow removes the block when a blank line or the catalog header is above it. It keeps a banner block, whose text starts with three or more of =, -, *, _, ~, + or #, for example # === React 18 pins ===. |
always | Fallow removes the block. |
never | Fallow keeps the block. |
A # fallow-keep marker on a line of the block keeps the block with each policy. When fallow removes comment lines, the count line says so, for example Fixed 1 issue(s) (+1 catalog comment line). Fallow skips an entry that a workspace package still pins with a version (hardcoded_consumers), because the next install would fail.
Before it writes the file, fallow parses the edited YAML and compares it with the original. It writes the change only when the requested entries are the only difference. Otherwise it skips the entry and gives the reason in skip_reason:
skip_reason | Cause |
|---|---|
not_found | The catalog key is not in the file. The file changed after the analysis. |
not_empty | The catalog group has entries. The file changed after the analysis. |
unsupported_yaml_style | The file changed after the analysis, and the key is in a flow mapping. Or the catalog header has a value on its line, for example an anchor. Edit the catalog by hand. |
unsafe_edit | The edit would change other parts of the file, for example because another key is an alias of the removed entry. Edit the catalog by hand. |
multi_document_yaml | The file has a --- document separator. |
The editor quick fix uses the same check on the unsaved buffer. It offers no action when the check fails.
Config file for duplicate exports
For a duplicate export, fallow fix adds an ignoreExports rule to your config file. When no config file exists, it creates .fallowrc.json, with the same content that fallow init writes. --dry-run shows the change as a unified diff. This sample leaves out the lines between $schema and ignoreExports:
Would create .fallowrc.json with 2 ignoreExports rule(s):
--- .fallowrc.json (does not exist)
+++ .fallowrc.json (proposed)
@@ -0,0 +1,33 @@
+{
+ "$schema": "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json",
+ "ignoreExports": [
+ {
+ "file": "src/ui/button/index.ts",
+ "exports": ["*"]
+ },
+ {
+ "file": "src/ui/card/index.ts",
+ "exports": ["*"]
+ }
+ ]
+}
The JSON fix entry has the same diff in proposed_diff, and created_files names the new file.
Fallow does not create a config file in a package of a monorepo, so that the config does not split over the packages. A directory is in a monorepo when a directory above it has pnpm-workspace.yaml, turbo.json, lerna.json, rush.json, a Deno workspace, or a package.json with workspaces. Fallow then prints this message, and the JSON fix entry has skip_reason: "monorepo_subpackage":
Skipped duplicate-export config fix: no fallow config file at packages/ui and the directory is inside a monorepo (workspace root: /repo). Run `fallow init` at the workspace root, or invoke `fallow fix` from /repo instead of from a subpackage.
--no-create-config stops the creation of a config file in each case. Use it in a pre-commit hook, a CI job and fallow watch. Fallow then skips the config change, and makes the source changes as usual.
Output
fallow fix --dry-run
Would remove export from src/services/orders.ts:18 `cancelOrder`
Would remove export from src/lib/index.ts:1 `formatPercent`
Would remove export from src/lib/format.ts:3 `formatPercent`
Would remove `left-pad` from dependencies in package.json
Dry run complete. No files were modified.
Each line names one planned change, its file and its line. Without --dry-run, fallow writes the changes and prints one count line, for example Fixed 4 issue(s).
With --format json, the output has these top-level fields:
| Field | Content |
|---|---|
dry_run | true for a run with --dry-run. |
fixes | One object for each change: type, path, line, name. A skipped change also has applied: false, skipped: true and a skip_reason. |
total_fixed | The number of changes that fallow wrote. |
skipped | The number of catalog and YAML changes that fallow did not write. |
skipped_content_changed | Files that changed on disk after the analysis. |
skipped_mixed_line_endings | Files with both CRLF and LF line endings, or with a line that ends in a bare CR. |
skipped_low_confidence_exports | Exports that fallow did not remove, because their file is in a fixture, mock or e2e directory, has an unresolved import, or has incomplete evidence. |
skipped_low_confidence_dependencies | Dependencies that fallow did not remove, because of incomplete evidence. |
skipped_low_confidence_members | Class and enum members that fallow did not remove, because of incomplete evidence. |
skipped_kept_re_exports | Exports that a kept re-export still names. |
skipped_shared_declarations | Unused names that share one export keyword with a used name. |
skipped_test_importers | Exports that a test, story or fixture file imports, in a run with --production. |
created_files | The config files that the run creates. Present only when fallow creates a file. |
incomplete_analysis_diagnostics | The diagnostics that hold back the low_confidence_incomplete_analysis changes. Each object has the fields of a workspace_diagnostics entry and an action, the step that unblocks the change. Present only when a change is held back for this reason. |
A config change also has a proposed_diff field with the unified diff. A catalog change has entry_line, the line of the entry, next to line, the first line that fallow removes, which can be a comment line. The JSON output reference has each field.
Skipped changes
A skipped change has skipped: true and a skip_reason. The human output prints a line on stderr for each skipped file.
skip_reason | Cause | Exit code |
|---|---|---|
content_changed | The file changed on disk after the analysis, for example from an editor or a rebase. | 2 |
mixed_line_endings | The file has both CRLF and LF line endings, or a line that ends in a bare CR (\r without \n). A new run gives the same skip, until you change the file to one form, for example with dos2unix. | 2 |
low_confidence_off_graph | A directory of the path is __mocks__, __fixtures__, fixtures, e2e, e2e-tests, cypress, playwright, examples, evals or golden. Code that fallow does not see can import these files. test, tests and __tests__ are not in the list. | 0 |
low_confidence_unresolved_imports | The file has an import that fallow cannot resolve, so its use of names is not complete. | 0 |
low_confidence_incomplete_analysis | The finding has reachability_caveats, because a file did not parse, could not be read, or was skipped. The help of the change and incomplete_analysis_diagnostics name the path and the step. See Changes that an incomplete analysis holds back. | 0 |
kept_re_export | A re-export that the run keeps still names the export. See Exports that a kept re-export names. | 0 |
shared_declaration_in_use | The same export keyword also exports a name that is in use. See Declarations that export more than one name. | 0 |
generated_source | The file is generated code. Its path has a generated or __generated__ folder or a .generated. or .gen. name part, or its leading comment has @generated, or names the generator together with "do not edit", as in // Generated by <tool>. Do not edit. The generator writes the file again, so fallow keeps its exports, enum members and class members. Change the input of the generator, or add the file to ignoreExports. | 0 |
test_importers | A test, story, fixture or other file that --production leaves out imports the export. See Exports that test files import. | 0 |
Changes that an incomplete analysis holds back
When fallow skips a hidden folder with sources, a large or minified file, or a file that it cannot read or parse, it does not see the imports of that file. A change that rests on those imports is held back. The output names each path and the step that unblocks the change:
Fixes were held back because fallow did not fully analyze this path:
- .claude (skipped-source-dotdir): Fallow skips hidden folders. To analyze this one, add `!.claude/**` to `ignorePatterns` in the fallow config.
Then run `fallow fix --dry-run` and review the new preview.
The human output prints this list also with --quiet. A diagnostic that degrades the analysis but holds back no change, for example undeclared-workspace, is not in this list.
A low-confidence skip is a choice, not an error, so fallow dead-code still reports the finding, and you can remove the code by hand. Check the skipped_* counters also when the command exits with code 0.
Fallow writes each changed file to a temporary file next to it first, and moves the temporary files to their paths after all are written. When a write fails, for example on a full disk, each file keeps its old content. Fallow reads package.json and pnpm-workspace.yaml again before it changes them, so an entry that is already gone changes nothing.
Fallow edits UTF-8 files only. When a file starts with a byte order mark, fallow removes it before the analysis, so the line numbers do not move, and writes it back with the change.
Exit codes
| Code | Meaning |
|---|---|
0 | The run completed. A skip of a low-confidence change does not change the code. |
2 | Invalid input (for example a workspace that does not exist), a missing --yes without a terminal, a write error, or a file that fallow skipped because it changed on disk or has mixed line endings. |
See Exit codes.
Examples
# Show the planned changes and write nothing
fallow fix --dry-run
# Show the planned changes as JSON
fallow fix --dry-run --format json
# Apply the changes without a prompt
fallow fix --yes
# Apply the changes, and never create a config file
fallow fix --yes --no-create-config
# Fix only the findings in one directory
fallow fix src/services --yes
# Show the changes for the files that changed since main
fallow fix --changed-since main --dry-run
Related
- Auto-fix: what each fix changes, and the cases that fallow skips.
fallow dead-code: the findings thatfallow fixacts on.fixconfig: thefix.catalog.deletePrecedingCommentssetting.