CLI commands and flags
This page documents every Doc Detective command and flag. The primary invocation is npx doc-detective.
Synopsis
A bare invocation with no command runs tests; the available commands are run, audit, install, validate, lsp, debug, and help. Use --version to print the installed version, and --help or -h to print usage. For one command’s usage, add --help after it or name it after help, including nested commands (for example, npx doc-detective help install browsers). The CLI is strict: unknown flags cause an error instead of being ignored.
Run flags
These flags apply when you run tests, with no command or with run. Each has a config-file equivalent; see Configuration precedence.
The global flags --quiet, --debug, --log-level, --json, --no-color, and --no-input work with every command except lsp and the hidden runner command. Other commands take only their own flags and the global flags, and reject anything else with an unknown option error. lsp speaks the language server protocol on stdout, so it takes only --stdio.
Negating boolean flags
Boolean run flags can be negated with --no-, which overrides a config file. The ones you’ll typically reach for are: --no-auto-screenshot and --no-auto-record.
Notes on individual flags:
--reporters: see reporters and artifacts for therunFolderreporter and the built-in output formats.--cache-dir: see the cache directory guidance.--shell:runShelldocuments its steps, and shell selection covers how the default is chosen.--dry-run: the resolved test plan is printed to stdout, so you can pipe it (for example,npx doc-detective --dry-run | jq).--json,--plain, and--output -: stdout holds only results, and everything else goes to stderr. Only one mode can write stdout, so--plainwith--json,--output -, or--dry-runexits2.--no-input: also available asDOC_DETECTIVE_NO_INPUT=1.--auto-update: skipped automatically when theCIenvironment variable is set, which GitHub Actions, GitLab CI, CircleCI, and most CI systems do—so CI pipelines usually don’t need--no-auto-update. To pin the version deterministically everywhere (including runners that don’t setCI), setautoUpdate: falsein config or pass--no-auto-update.--testand--spec: patterns match if they appear anywhere in the ID; anchor a pattern with^and$to require an exacttestIdorspecIdmatch. Each value is split on commas before the parts are compiled as regexes, so a pattern can’t contain a literal comma (for example,--test "step{1,3}"is split intostep{1and3}).
There is no flag to select the platform, browser, or headless mode for a run—those are contexts defined in your config (--browser-fallback only controls what happens when a selected browser can’t start). For containerized and headless runs, see Docker and headless runs.
Commands
Doc Detective runs tests when you invoke it without a command, and exposes named commands for setup, editor integration, and diagnostics.
Default (run tests)
With no command, doc-detective runs tests and takes no positional arguments; control its behavior with the flags in the Run flags section. To pass file and folder paths as arguments, use run.
run
Run tests as the bare command does, with file and folder paths as arguments. The paths are added to any --input values. A - argument reads a spec or document from stdin. runTests and runtests still work, but print a deprecation warning on stderr, which --quiet, -l error, and -l silent hide. Replace them with run.
audit
Report which procedure steps, code blocks, links, and images in your docs have a test step. It runs no tests.
audit takes files and folders as arguments, like run, with - to read a document from stdin. It also accepts --config, --input, --no-env-file, and the global flags. It exits 0 whenever it prints a report, and 2 for bad usage, a bad config, or no files to audit. For what it counts, see Audit test coverage.
install
The install command group manages Doc Detective’s lazy-installed runtime assets—npm packages, browser binaries, ffmpeg, agent tools, and mobile toolchains. Its subcommands are all, browsers, runtime, bash, android, ios, status, and agents. For every subcommand, option, and example, see the install reference.
lsp
Start the language server over stdio, for editors and AI agents. You normally don’t run this yourself: your editor or agent starts it. Press Ctrl-C to stop.
This is distinct from install agents: the language server (lsp) exposes editor and AI-agent integrations over the LSP protocol, while install agents installs the Agent Skills and slash commands documented in the agent tools overview.
debug
Print diagnostics about your system, install, and config, without running tests. Secrets are redacted on a best-effort basis, so review the output before sharing it.
debug also accepts --config, --input, --no-env-file, and the global flags.
validate
Check that spec files and inline tests are valid, without running them. validate finds files the same way a run does, from positional inputs, --input, and --config, and also accepts the global flags.
For each invalid file, stdout names the file and each problem. The last line counts the files checked. With --json, stdout carries one JSON document instead: valid, and a files array of { path, valid, errors }.
Exit codes
A test run exits with these codes. validate has its own codes, listed under validate.
--no-exit-on-fail and exitOnFail: false turn failed, empty, and all-skipped runs into 0, and skip invalid specs with a warning. Usage errors, invalid config, and crashes still exit 2. A WARNING result never fails a run. Neither does a SKIPPED result, unless every spec skipped, which exits 2 without these options.
Configuration
Config auto-discovery
When you omit --config, the CLI looks for a config file in the current directory in this order: .doc-detective.json, then .doc-detective.yaml, then .doc-detective.yml. If none exists, it runs with defaults. When you pass --config, that path is authoritative—a mistyped path fails rather than falling back.
Configuration precedence
Doc Detective layers configuration in one order. A higher layer wins. Where a layer merges deeply, objects merge key by key and arrays replace.
A loadVariables step still replaces variables that are already set, because a step sets them on purpose.
A relative path resolves against the source that set it. That covers every path key, such as input, output, outputDir, cacheDir, loadVariables, beforeAll, afterAll, apiKeyFile, and apiTokenFile:
A path no source sets, such as the default input and outputDir of ., resolves the way the project config’s paths do, or against the current directory without one.
Each config source is validated against the config_v3 schema on its own, and an invalid one exits 2 with an error that names it. Flags override the validated config; they don’t bypass it.
DOC_DETECTIVE is a deprecated spelling of DOC_DETECTIVE_CONFIG. Its config object still applies, just below DOC_DETECTIVE_CONFIG, and Doc Detective warns until you move it. Its other keys, such as container, do nothing.
Environment variables
Boolean variables are on for 1, true, yes, or on, and off when unset, empty, or 0, false, no, or off, in any case. Doc Detective ignores any other value, and warns once.
Invocation
npx doc-detective ...is the primary invocation.- Global or local install: install with npm, then call
doc-detective .... See installation. - Docker: the images use the entrypoint
npx doc-detective, sodocker run <image> --input ...passes flags straight to the default run command. See Docker and headless runs.
Examples
Run tests over a directory:
Preview the resolved plan without running:
Run a filtered subset with specific reporters:
Start the language server: