> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fallow.tools/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto-fix

> Automatically remove unused exports and dependencies from your TypeScript and JavaScript codebase. Supports dry-run preview and non-interactive agent workflows.

`fallow fix` removes unused exports and unused dependencies from your codebase.

In agent workflows, `fallow fix --yes --format json` cleans up dead code non-interactively after code generation.

<Tip>
  Always commit your changes before running `fallow fix`. Git lets you undo if needed.
</Tip>

## Recommended workflow

<Steps>
  <Step title="Preview changes">
    Run a dry run to see exactly what would be removed without making any changes.

    ```bash theme={null}
    fallow fix --dry-run
    ```

    ```bash title="$ fallow fix --dry-run" theme={null}
    Would remove export from src/components/Card/index.ts:1 `CardFooter`
    Would remove export from src/providers/trpc-provider/index.tsx:12 `TRPCProvider`
    Would remove export from src/server/jobs/queue.ts:61 `enqueueJobDelayed`
    Would remove export from src/server/jobs/queue.ts:206 `sweepStuckProcessingJobs`
    Would remove export from src/server/jobs/queue.ts:276 `getDeadLetterJobs`
    Would remove `@trpc/react-query` from dependencies

    6 fixes available (5 exports, 1 dependency). Run without --dry-run to apply.
    ```
  </Step>

  <Step title="Review the output">
    Check that every proposed removal is safe. Pay attention to exports consumed by external packages or dynamic imports that fallow can't detect statically.

    ```bash theme={null}
    fallow fix --dry-run --format json
    ```
  </Step>

  <Step title="Apply fixes">
    After reviewing the preview, apply the changes. In interactive terminals, fallow asks for confirmation before writing.

    ```bash theme={null}
    fallow fix
    ```

    In CI or non-TTY environments, use `--yes` to skip confirmation:

    ```bash theme={null}
    fallow fix --yes
    ```

    <Info>
      Agents typically use `fallow fix --yes --format json` to apply fixes non-interactively. The JSON output confirms exactly what was changed, so the agent can verify the result.
    </Info>
  </Step>

  <Step title="Verify the result">
    Run your build and tests to confirm nothing broke.

    ```bash theme={null}
    npm run build && npm test
    ```
  </Step>
</Steps>

## What gets fixed

* **Unused exports**: the `export` keyword is removed, keeping the declaration. For exported enums where the enum itself is never referenced outside its body in the file, the entire `enum` block is deleted.
* **Unused dependencies**: removed from `package.json` when they are not imported by another workspace
* **Unused enum members**: removed from the enum declaration. When every member of an exported enum is unused, the whole declaration is deleted in one pass instead of leaving behind an empty `export enum X {}` shell. Importers in other files now reference a name that no longer exists, so run your TypeScript build to find and clean them up.
* **Unused pnpm catalog entries**: removed from `pnpm-workspace.yaml` by line-aware deletion so comments and stylistic choices in the file survive. Object-form entries are removed as one block. When the last entry of a catalog group is removed, the header is rewritten to `catalog: {}` (or `<name>: {}`) instead of leaving bare `catalog:`, because pnpm rejects null-valued catalogs with `Cannot convert undefined or null to object` at install time. Entries whose `hardcoded_consumers` is non-empty (a workspace package still pins a hardcoded version of the same package, where removing the catalog entry would break `pnpm install`) are skipped; the skip is reported in the fix output so you can migrate the consumer first and rerun. After a successful catalog edit fallow reminds you to run `pnpm install` so `pnpm-lock.yaml` stays in sync.

<Warning>
  Auto-fix does not delete entire files or remove unused class members. Use `fallow dead-code` to find those and remove them manually.
</Warning>

## JSON output

For scripting, CI, and agent workflows:

```bash theme={null}
fallow fix --dry-run --format json
```

```json theme={null}
{
  "changes": [
    {
      "type": "remove-export",
      "file": "src/components/Card/index.ts",
      "symbol": "CardFooter",
      "line": 1
    },
    {
      "type": "remove-export",
      "file": "src/providers/trpc-provider/index.tsx",
      "symbol": "TRPCProvider",
      "line": 12
    },
    {
      "type": "remove-export",
      "file": "src/server/jobs/queue.ts",
      "symbol": "enqueueJobDelayed",
      "line": 61
    },
    {
      "type": "remove-export",
      "file": "src/server/jobs/queue.ts",
      "symbol": "sweepStuckProcessingJobs",
      "line": 206
    },
    {
      "type": "remove-export",
      "file": "src/server/jobs/queue.ts",
      "symbol": "getDeadLetterJobs",
      "line": 276
    },
    {
      "type": "remove-dependency",
      "package": "@trpc/react-query"
    }
  ],
  "summary": {
    "total_changes": 6,
    "exports_removed": 5,
    "dependencies_removed": 1
  }
}
```

## See also

<CardGroup cols={2}>
  <Card title="CLI: fix" icon="terminal" href="/cli/fix">
    Full reference for the `fallow fix` command and its flags.
  </Card>

  <Card title="Dead Code Analysis" icon="skull-crossbones" href="/analysis/dead-code">
    Understand what fallow detects before auto-fixing.
  </Card>
</CardGroup>
