---
title: "Cache and speed"
description: "The analysis cache, worker threads, the long-lived Doctor process, and watch mode."
canonical_url: "https://vite-doctor.onmax.me/cli/cache"
---
# Cache and speed

> The analysis cache, worker threads, the long-lived Doctor process, and watch mode.

The persistent analysis cache is on by default. Pass `--no-cache` to run without reading or writing it.

```bash
pnpm vite-doctor cache status
pnpm vite-doctor cache status --format json
pnpm vite-doctor cache clean
```

`cache status` prints the store path, whether the current Doctor build wrote it, entry counts, and what the run that last wrote it read, parsed, reused, and computed. `cache clean` removes it.

## What the cache keeps

The cache is one file, `store.json`, in `.vite-doctor/cache` (`.nuxt/doctor/cache` for Nuxt projects). It keeps File Facts and each Rule's Diagnostics per file, with the Rule inputs each Rule read: other files, directory listings, and path checks made through `ctx.fs`.

Doctor reuses a cached result only when the file content, the Rule implementation, the Project Inventory, the Rule config, and every recorded input are unchanged. It compares file size, modification time, change time, and inode before reading a file, so a warm run with no changes reads no source file. Rules that declare `cacheScope: "none"` or a non-deterministic `determinism` always run.

Agent rerun commands repeat `--cache` or `--no-cache` only when the original run passed one.

## Worker threads

Set `VITE_DOCTOR_WORKERS` to split file Rules across worker threads when a run covers the whole project and the cache has no results for them yet, such as a first run or `--no-cache` in CI.

- A number starts that many workers.
- `auto` starts one worker per 150 files, up to 4 and never more than your CPU count minus one, and none below 300 files.

Workers run only built-in Rules whose result depends on the file they analyze and the inputs they record. If any extension file Rule is enabled, every file Rule stays on the main thread to keep their execution order. The report is the same either way, and peak memory roughly doubles while workers run. The `workers` run option does the same from the API.

## Long-lived Doctor process

Each CLI call loads Doctor and reads the cache again. When an agent or script runs Doctor many times in one project, opt in to a long-lived Doctor process that keeps the loaded Rule Packs and the parsed cache in memory:

```bash
export VITE_DOCTOR_SERVER=1      # every Doctor Run in this shell
pnpm vite-doctor . --server      # one Doctor Run
pnpm vite-doctor . --no-server   # run in this process even when enabled
```

The first run starts one Doctor process per project root. Later runs reuse it, one at a time, and get the same stdout, stderr, and exit code as a direct run. Doctor replaces the process when the Doctor version, Node.js, `doctor.config.json`, `vite.config.*`, or the CI and color environment differ from the client's. It exits after 15 minutes without runs; `VITE_DOCTOR_SERVER_IDLE_MS` changes the timeout.

Interactive terminals, `--config`, `--host-extensions`, `--watch`, and commands other than a Doctor Run always run directly. The Doctor process never loads executable configuration or host-registered Doctor Extensions.

```bash
pnpm vite-doctor server status   # pid, memory, runs, and whether this CLI reuses it
pnpm vite-doctor server stop
```

The socket, state file, and log live in a directory private to your user under the system temporary directory. `server status` prints their paths.

## Watch mode

`vite-doctor . --watch` runs Doctor, then reruns it whenever a project file changes, reusing the loaded Rule Packs and the cache. Each rerun prints a full report. Stop it with Ctrl+C; the exit code is the last run's. `--watch` can't be combined with `--fix`, `--unsafe-fix`, or `--update-baseline`.

## Stuck cache locks

On a system without Linux PID namespaces, such as macOS or Windows, Doctor cannot check who owns a cache store lock. A lock left by an interrupted run, or held by another run, then blocks cache writes. Doctor warns when that happens. Diagnostics still use the current source, but cache updates and pruning stop until you clean up:

1. Stop every Doctor process that shares the cache, including dev servers that use a Plugin Surface and processes in other containers.
2. From the project root, run `pnpm vite-doctor cache clean` with the same `--config` and `--framework` options as the original run. For a Plugin Surface with an in-memory custom cache directory, stop the hosts and call `cleanCache(root, config)` from `vite-doctor` with that configuration.
3. Restart Doctor. The next run rebuilds the cache, and later runs with no changes reuse it.

A lock claim without a recognized owner namespace can't prove whether a writer is still active, so Doctor never deletes one based on age or a PID lookup. When Doctor can tell that the owner exited in the same PID namespace, it recovers the lock by itself.


## Sitemap

See the full [sitemap](https://vite-doctor.onmax.me/sitemap.md) for all pages.
