# CLI reference

Run React Doctor from the command line:

```bash
react-doctor [paths...] [options]
```

Pass one project directory or a list of source file paths. With no paths, React Doctor scans the current directory.

## Common commands

```bash
npx react-doctor@latest
npx react-doctor@latest --verbose --scope changed
npx react-doctor@latest --category Security --json
npx react-doctor@latest ci install
npx react-doctor@latest rules list
npx react-doctor@latest install
```

## Options

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <code>-v, --version</code>
      </td>
      <td>Print the installed version</td>
    </tr>
    <tr>
      <td>
        <code>--lint, --no-lint</code>
      </td>
      <td>Skip lint diagnostics</td>
    </tr>
    <tr>
      <td>
        <code>--supply-chain, --no-supply-chain</code>
      </td>
      <td>Enable or skip Socket.dev dependency checks</td>
    </tr>
    <tr>
      <td>
        <code>--verbose</code>
      </td>
      <td>Show every rule and per-file details</td>
    </tr>
    <tr>
      <td>
        <code>--debug</code>
      </td>
      <td>Print the Sentry trace ID for a bug report</td>
    </tr>
    <tr>
      <td>
        <code>--output-dir &lt;dir&gt;</code>
      </td>
      <td>Write the full diagnostics dump to a directory</td>
    </tr>
    <tr>
      <td>
        <code>--score</code>
      </td>
      <td>Output only the numeric score</td>
    </tr>
    <tr>
      <td>
        <code>--json</code>
      </td>
      <td>Output a structured JSON report</td>
    </tr>
    <tr>
      <td>
        <code>--category &lt;category&gt;</code>
      </td>
      <td>
        Show findings from one diagnostic category. Repeat the flag to include
        more categories
      </td>
    </tr>
    <tr>
      <td>
        <code>--json-compact</code>
      </td>
      <td>
        Emit compact JSON with <code>--json</code>
      </td>
    </tr>
    <tr>
      <td>
        <code>--json-out &lt;path&gt;</code>
      </td>
      <td>
        With <code>--json</code>, write the report to a file
      </td>
    </tr>
    <tr>
      <td>
        <code>-y, --yes</code>
      </td>
      <td>Skip prompts and scan all detected workspace projects</td>
    </tr>
    <tr>
      <td>
        <code>--no-parallel</code>
      </td>
      <td>Lint serially with one worker</td>
    </tr>
    <tr>
      <td>
        <code>--project &lt;name&gt;</code>
      </td>
      <td>
        Select projects to scan, comma-separated. Accepts workspace package
        names or directory paths; <code>*</code> selects every workspace project
      </td>
    </tr>
    <tr>
      <td>
        <code>--scope &lt;value&gt;</code>
      </td>
      <td>
        Choose <code>full</code>, <code>files</code>, <code>changed</code>,{" "}
        <code>lines</code>, or <code>contextual</code>
      </td>
    </tr>
    <tr>
      <td>
        <code>--base &lt;ref&gt;</code>
      </td>
      <td>Set the base ref for a partial scope</td>
    </tr>
    <tr>
      <td>
        <code>--include-untracked</code>
      </td>
      <td>
        Include ordinary untracked files in a partial scope, respecting{" "}
        <code>.gitignore</code>
      </td>
    </tr>
    <tr>
      <td>
        <code>--no-score</code>
      </td>
      <td>
        Skip the score API, share URL, and crash reporting. React Doctor also
        accepts <code>--no-telemetry</code>
      </td>
    </tr>
    <tr>
      <td>
        <code>--staged</code>
      </td>
      <td>Scan staged files for pre-commit hooks</td>
    </tr>
    <tr>
      <td>
        <code>--blocking &lt;level&gt;</code>
      </td>
      <td>
        Severity that fails CI: <code>error</code> (default),{" "}
        <code>warning</code>, or <code>none</code> (advisory)
      </td>
    </tr>
    <tr>
      <td>
        <code>--warning-exit-code &lt;code&gt;</code>
      </td>
      <td>
        Exit with a code from 2 to 255 for non-blocking warnings. See the{" "}
        <a href="/https/www.react.doctor/docs/ci-and-prs/other-ci-providers#gitlab-warning-status">
          GitLab warning status example
        </a>{" "}
        for settings that override this code
      </td>
    </tr>
    <tr>
      <td>
        <code>--max-duration &lt;seconds&gt;</code>
      </td>
      <td>Set a time budget and report partial results when it expires</td>
    </tr>
    <tr>
      <td>
        <code>--no-respect-inline-disables</code>
      </td>
      <td>Audit mode for inline disables</td>
    </tr>
    <tr>
      <td>
        <code>--warnings, --no-warnings</code>
      </td>
      <td>Show or hide warning-severity diagnostics</td>
    </tr>
    <tr>
      <td>
        <code>--color, --no-color</code>
      </td>
      <td>Force or disable colored output</td>
    </tr>
  </tbody>
</table>

## Scan scopes

Choose one scan scope with `--scope`:

- `full`: scan the entire project and report every finding
- `files`: scan changed files and report every finding in them
- `changed`: compare with the base and report only introduced findings
- `lines`: report findings whose source range touches a changed line
- `contextual`: report findings in modified functions, JSX elements, or files, using each rule's `diffScope`

The default is `full`. React Doctor detects the base ref for partial scopes. Pass `--base main` when you need a specific ref. The older `--diff` flag still works as a deprecated alias for `--scope changed`.

Maintainability analysis compares repeated JSX against the full source corpus in every scope. Partial scopes report only findings connected to the selected files or changed lines.

## Report findings in modified contexts

Use `contextual` to catch existing findings while you edit the code that owns them:

```bash
npx react-doctor@latest --scope contextual --base origin/main --blocking none
```

React Doctor analyzes the changed files, then filters findings using each rule's `diffScope`. The diagnostic still points to the exact problem. This scope can report existing findings; `changed` reports only findings introduced compared with the base.

<table>
  <thead>
    <tr>
      <th>
        <code>diffScope</code>
      </th>
      <th>When an existing finding is reported</th>
      <th>Initial rules</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <code>line</code>
      </td>
      <td>The diagnostic's source range intersects a changed line</td>
      <td>All rules without an explicit wider scope</td>
    </tr>
    <tr>
      <td>
        <code>jsx-element</code>
      </td>
      <td>The owning JSX element changes</td>
      <td>
        <code>button-has-type</code>,{" "}
        <code>no-img-lazy-with-high-fetchpriority</code>
      </td>
    </tr>
    <tr>
      <td>
        <code>function</code>
      </td>
      <td>The owning function changes</td>
      <td>
        <code>rerender-lazy-state-init</code>,{" "}
        <code>no-eager-new-in-use-state-initializer</code>
      </td>
    </tr>
    <tr>
      <td>
        <code>file</code>
      </td>
      <td>The file changes</td>
      <td>
        <code>only-export-components</code>, <code>nextjs-no-head-import</code>
      </td>
    </tr>
  </tbody>
</table>

An edit inside a nested function or child JSX element does not expand to its parent owner. Deletion-only edits count when their position is inside the surviving owner. File rules also apply to renamed files. Unknown rules, unreadable files, invalid syntax, and unsupported source formats keep line filtering when an owner cannot be resolved. Function and element expansion supports JavaScript, TypeScript, JSX, and TSX.

Use `--staged --scope contextual` to apply the same policy to staged source. `--include-untracked` also works with contextual working-tree scans. The score still uses the findings from the scanned files before this reporting filter, as it does for `lines`.

Start with `--blocking none` to review the additional findings before making them block CI. Findings outside the diff remain in the report and summary; inline review comments are still limited by the review API's diff positions.

## Scan selected files

Pass file paths to scan only the files that another CI step selected:

```bash
npx react-doctor@latest src/a.tsx src/b.tsx
```

## Multi-project scans

Use `--project` to score each project in a monorepo separately. Each entry resolves as a workspace package name first, then as a directory path relative to the scan root:

```bash
npx react-doctor@latest --project modules/billing,modules/payroll
```

Directory paths cover monorepos whose modules are not workspace packages. `--project "*"` selects every discovered workspace project. Unknown entries fail the run before scanning starts.

Each project scans with its own `doctor.config.*` layered onto the root config: `rules` and `categories` merge per key, and `ignore` lists union. A module can override one rule without discarding the shared base config.

Output shows one score line per project plus a worst-of aggregate. JSON reports list each project in the `projects` array.

To score the same projects on every run without passing the flag, set [`projects` in the root config file](/docs/configuration/config-files). An explicit `--project` flag overrides the config list.

## Install command

```bash
npx react-doctor install [options]
```

Interactive setup installs the `/react-doctor` skill for selected coding agents and offers optional local hooks. Manage CI separately with `react-doctor ci`.

<table>
  <thead>
    <tr>
      <th>Option</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <code>-y, --yes</code>
      </td>
      <td>Skip prompts and install the skill for all detected agents</td>
    </tr>
    <tr>
      <td>
        <code>--dry-run</code>
      </td>
      <td>Show what would be installed</td>
    </tr>
    <tr>
      <td>
        <code>--agent-hooks</code>
      </td>
      <td>Install native Claude Code and Cursor hooks</td>
    </tr>
    <tr>
      <td>
        <code>--cwd &lt;cwd&gt;</code>
      </td>
      <td>Project root for install</td>
    </tr>
  </tbody>
</table>

## CI commands

Use the `ci` command group to manage a GitHub Actions workflow or GitLab CI scaffold:

```bash
npx react-doctor@latest ci install
npx react-doctor@latest ci config
npx react-doctor@latest ci upgrade
```

`ci install` accepts `--provider`, `--pr`, `--blocking`, `--scope`, reporting toggles, `--yes`, and `--cwd`. `ci config` accepts the same settings except `--pr`. `ci upgrade` accepts `--provider`, `--pr`, `--yes`, and `--cwd`.

Reporting toggles are `--comment`, `--review-comments`, and `--commit-status`, with a `--no-*` form for each one. GitHub Actions supports every toggle. GitLab CI produces a gate-only scaffold.

## Rules commands

Inspect and configure the effective rule set:

```bash
npx react-doctor@latest rules list
npx react-doctor@latest rules explain react-doctor/no-array-index-as-key
npx react-doctor@latest rules set react-doctor/no-array-index-as-key error
npx react-doctor@latest rules disable react-doctor/no-danger
npx react-doctor@latest rules enable react-doctor/no-danger
npx react-doctor@latest rules category Performance warn
npx react-doctor@latest rules ignore-tag design
npx react-doctor@latest rules unignore-tag design
```

Filter `rules list` with `--category`, `--tag`, `--framework`, or `--configured`. Add `--json` to `rules list` or `rules explain` for structured output. Every rules subcommand accepts `--cwd`.

## JSON output

Use `--json` when another tool needs to parse the scan:

```bash
npx react-doctor@latest --json
```

Human-readable output is suppressed. Errors still produce JSON with `ok: false`, so stdout remains parseable.

Use `--category` when you want a report for one part of the diagnostic set:

```bash
npx react-doctor@latest --json --category Performance
```

Repeat `--category` to include more than one category:

```bash
npx react-doctor@latest --category Performance --category Accessibility
```

Category filters narrow normal output, verbose output, workspace summaries, handoff prompts, and JSON reports. They do not change which files React Doctor scans. Unknown categories fail before report output.

## Explain a diagnostic

Use the `why` subcommand when a diagnostic or suppression is confusing:

```bash
npx react-doctor@latest why src/App.tsx:42
```

The output reports what React Doctor sees at that location and why a nearby suppression did or didn't apply.

To learn what a rule means in general, use `rules explain`:

```bash
npx react-doctor@latest rules explain react-doctor/no-array-index-as-key
```

## Runtime performance traces

Record a Chrome DevTools performance trace while you interact with a running React app:

```bash
npx react-doctor@latest scan http://localhost:3000
```

React Doctor opens the installed Chrome browser in a separate, temporary profile. It records until you press Enter or five minutes pass. Purple outlines show component names as React renders.

The command returns a summary and the path to a compressed DevTools trace. Use `--format json` or `--format jsonl` for coding agents.

In an interactive terminal, you can run `react-doctor scan` without a URL. Select a detected localhost app or enter another URL. Coding agents and CI must pass the URL explicitly.

### Use an authenticated session

React Doctor leaves your existing browser session unchanged. To reuse an authenticated session:

1. Start a dedicated Chrome profile with remote debugging.
2. Sign in to the app.
3. Close all non-blank tabs in that profile.
4. Pass its endpoint with `--cdp`:

```bash
npx react-doctor@latest scan https://app.example.com --cdp http://127.0.0.1:9222
```

Chrome performance tracing covers all pages in the browser. React Doctor rejects attached profiles with open pages and closes blank startup tabs before tracing. After tracing, it closes its scan tab and leaves the attached browser open.

React Doctor stores the trace locally and never uploads it. It can contain page URLs, source paths, and React profiling details. Treat it as sensitive application data.
