Skip to navigation

CLI commands and flags

This page documents every Doc Detective command and flag. The primary invocation is npx doc-detective.

Synopsis

npx doc-detective [command] [options]

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.

OptionAliasTypeDefaultDescription
--config-cstringPath to a config.json or config.yaml file.
--input-istring.Path to test specifications and documentation source files. May be paths to specific files or to directories to scan for files. - reads a spec or document from stdin. Give one comma-separated list, once. Repeating the flag is a usage error.
--output-ostringPath of the JSON results file. It’s overwritten on each run. - prints the results to stdout, the same as --json. Beats config output. With --dry-run, the file gets the test plan. A folder isn’t valid here: use --output-dir.
--output-dirstring.Path of the folder that holds the run folder (.doc-detective/runs/<runId>/) and the html, junit, markdown, and cucumber reports.
--reporters-rstring["terminal","runFolder"]Reporters to use for output. Built-in reporters: terminal, json, html, runFolder (archives results in <outputDir>/.doc-detective/runs/<runId>/, beside any screenshots from the run), junit (JUnit XML written as junit.xml in the output directory), markdown (a run summary written as doc-detective-summary.md in the output directory), cucumber (Cucumber JSON written as cucumber.json in the output directory). Give one comma-separated list, once (e.g. —reporters terminal,html). Repeating the flag is a usage error.
--test-tstringRun only tests whose testId matches the given regex (case-insensitive). Give one comma-separated list of patterns, once; a test passes if any pattern matches.
--spec-sstringRun only specs whose specId matches the given regex (case-insensitive). Give one comma-separated list of patterns, once; a spec passes if any pattern matches.
--dry-run-nbooleanfalseResolve tests fully (file detection, inline-test extraction, config merge) and emit the resolved test plan as JSON, but do not execute any steps.
--compare-tostringThe earlier run’s results to compare failures with: previous (the default, the newest other run folder under <outputDir>/.doc-detective/runs/), a results JSON file, or a folder that holds testResults.json. A relative path resolves against the current directory. Beats config compareTo. --no-compare-to turns comparison off. Not with --dry-run.
--fail-onstringanyWhich failures exit 1: any (the default) or new, only failures that weren’t failing in the run this one was compared with. With no comparison, every failure counts as new. --no-exit-on-fail still wins. Beats config failOn. --fail-on new needs a comparison, so it doesn’t combine with --no-compare-to.
--plainbooleanPrint one line per test context, with four tab-separated columns: result, spec ID, test ID, and platform and browser, such as linux/chrome.
--no-exit-on-failbooleanExit 0 even when tests fail or nothing was tested, including when every spec skipped, and skip invalid specs with a warning. Usage errors, invalid config, and crashes still exit 2.
--allow-unsafebooleanAllow execution of potentially unsafe tests
--concurrent-runnersstring1Number of test contexts to run concurrently (default 1). Pass a number (for example, —concurrent-runners 4), or auto (or true, as in config) to use the CPU core count (capped at 4). With more than 1 runner, log lines from different contexts interleave and cross-context variable dependencies are unsupported.
--browser-fallbackstringautoHow to handle a context whose browser cannot start a driver session. auto (default): fall back to any other available browser (a fallback away from an explicitly requested browser reports WARNING). explicit: fall back only for auto-selected browsers; a broken explicitly-requested browser is skipped with a diagnostic reason. off: never fall back across browsers. Drivers are validated by execution, so a present-but-broken driver (e.g. a partially downloaded geckodriver) no longer silently skips coverage.
--shellstringbashDefault shell for runShell steps: bash (default), cmd, or powershell. cmd and powershell only work on Windows. Steps can override this value with their own shell field.
--auto-screenshotbooleanOn by default. Capture a screenshot after every step that drives a browser, native app, or device. Images are saved in the per-run artifact folder (<output>/.doc-detective/runs/<runId>/) under the nested resource tree specs/<specId>/tests/<testId>/contexts/<contextId>/screenshots/, named with each step’s order, action, and ID, so the same step lands on the same relative path in every run’s folder for run-over-run comparison. While it’s on, the runFolder reporter runs even if —reporters leaves it out. Use —no-auto-screenshot to turn it off; it sets the config level, so a spec’s or test’s autoScreenshot: true still wins.
--auto-recordbooleanOn by default, and off by default in CI (when the CI environment variable is non-empty). Record a video of every context that drives a browser, native app, or device, in addition to any explicit record steps: headless Chrome with the browser engine, headed browsers and desktop apps with the ffmpeg engine, and Android and iOS devices on the device. Headless Firefox runs headed so it can be recorded, when the host can capture the screen. Passing —auto-record makes it strict: a recording the host can’t make is SKIPPED, and one that fails to start fails. Videos are saved in the per-run artifact folder (<output>/.doc-detective/runs/<runId>/) under specs/<specId>/tests/<testId>/contexts/<contextId>/recordings/. While it’s on, the runFolder reporter runs even if —reporters leaves it out. Use —no-auto-record to turn it off; it sets the config level, so a spec’s or test’s autoRecord: true still wins.
--verificationstringexistingWhat to write back into source files after a run: existing (default) fills only the verified-by entries and badge tests a page declares, true also declares them on passing pages and inline tests, false writes nothing back. Overrides verification.write.
--overwrite-screenshotsstringSet overwrite for every screenshot step in the run, including automatic screenshots that compare against a reference: true replaces every reference, false never replaces one, and aboveVariation replaces a reference only when the capture differs by more than maxVariation, or maxDiffPixels when set. Given with no value, it means true. Beats config overwriteScreenshots, which beats each step’s own overwrite. Any other value exits 2 with error: option '--overwrite-screenshots [mode]' argument 'maybe' is invalid. Allowed choices are true, false, aboveVariation.
--cache-dirstringDirectory for lazy-installed runtime assets (heavy npm packages, browser binaries, ffmpeg). Beats DOC_DETECTIVE_CACHE_DIR and config cacheDir. Defaults to $XDG_CACHE_HOME/doc-detective (%LOCALAPPDATA%\doc-detective on Windows), or an existing ~/.doc-detective.
--no-env-filebooleanDon’t load a .env file from the current directory. Variables already set in the shell always win over .env.
--no-hintsbooleanDon’t show a post-run hint. Hints are on by default, and show one applicable tip with code samples and links after a run in an interactive shell.
--no-auto-updatebooleanDon’t check the npm registry on startup for a newer 5.x and self-update before running. Self-update never crosses a major version, and never runs in CI.
--no-telemetrybooleanDon’t send anonymous usage data for this run. DO_NOT_TRACK and telemetry.send: false do the same.
--exit-on-fail-ebooleantrueExit 1 when any spec’s result is FAIL. [deprecated: now the default]
--quiet-qbooleanShow only errors and a one-line verdict.
--debug-dbooleanShow debugging output. Also DEBUG and DOC_DETECTIVE_DEBUG.
--log-level-lstringinfoDetail level of logging events. Accepted values: silent, error, warning, info (default), debug
--logLevelstringinfoDetail level of logging events. [deprecated: use —log-level]
--jsonbooleanPrint one JSON document to stdout.
--no-colorbooleanTurn off color. Also NO_COLOR.
--no-inputbooleanNever prompt; fail and name the flag to pass

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 the runFolder reporter and the built-in output formats.
  • --cache-dir: see the cache directory guidance.
  • --shell: runShell documents 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 --plain with --json, --output -, or --dry-run exits 2.
  • --no-input: also available as DOC_DETECTIVE_NO_INPUT=1.
  • --auto-update: skipped automatically when the CI environment 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 set CI), set autoUpdate: false in config or pass --no-auto-update.
  • --test and --spec: patterns match if they appear anywhere in the ID; anchor a pattern with ^ and $ to require an exact testId or specId match. 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 into step{1 and 3}).

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.

npx doc-detective --input ./docs

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.

npx doc-detective run ./docs a.spec.json
cat a.spec.json | npx doc-detective 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.

npx doc-detective audit docs/ --json

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.

OptionTypeDefaultDescription
--stdiobooleantrueUse stdio, the only transport. Accepted because LSP clients add it
npx doc-detective lsp

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.

OptionTypeDefaultDescription
--include-envbooleanfalseAlso print every environment variable, redacted
npx doc-detective debug --include-env

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 }.

CodeMeaning
0At least one test was found, and every test is valid
1At least one spec or inline test is invalid
2A usage error, invalid config, or no tests found
npx doc-detective validate docs/
npx doc-detective validate --json docs/ tests/login.spec.json

Exit codes

A test run exits with these codes. validate has its own codes, listed under validate.

CodeMeaning
0No spec failed (with --fail-on new, no failure is new), and at least one spec ran
1At least one spec failed (with --fail-on new, at least one failure is new)
2Nothing valid was tested, or the CLI couldn’t proceed: a usage error, invalid config, no specs, every spec skipped, an invalid spec, a declined install, or a crash
130, 143Interrupted by SIGINT or SIGTERM

--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.

#Layer (highest first)Merge
1Flags, such as --cache-dir, -l, -q, and -dReplace
2The shell’s environment: DOC_DETECTIVE_CONFIG, then the single-purpose variables DOC_DETECTIVE_CACHE_DIR (cacheDir), DOC_DETECTIVE_DEBUG and DEBUG (logLevel: debug), DO_NOT_TRACK (telemetry.send: false), and DOC_DETECTIVE_SKIP_AUTO_UPDATE (autoUpdate: false), which win over itDeep
3A .env file in the current directory. It only fills variables the shell left unset. --no-env-file skips it—
4The project config: the file --config names, or else the first of .doc-detective.json, .doc-detective.yaml, and .doc-detective.yml. A config-level loadVariables file also only fills unset variablesDeep
5Your user config, at $XDG_CONFIG_HOME/doc-detective/config.json (%APPDATA%\doc-detective\config.json on Windows)Deep
6Schema defaults—

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:

SourceA relative path resolves against
The project configIts folder. With relativePathBase: "cwd", or for a config loaded from a URL, the current directory
Your user configIts folder, even with relativePathBase: "cwd"
DOC_DETECTIVE_CONFIG and DOC_DETECTIVEThe current directory
Flags and single-purpose variablesThe current directory

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.

VariableValuesDefaultWhat it does
DOC_DETECTIVE_CONFIGA JSON config objectUnsetConfig, above the project config. See Configuration precedence.
DOC_DETECTIVE_CACHE_DIRA path$XDG_CACHE_HOME/doc-detective, %LOCALAPPDATA%\doc-detective on Windows, or an existing ~/.doc-detectiveWhere browsers and runtime dependencies are installed. Sets cacheDir. --cache-dir beats it.
DOC_DETECTIVE_DEBUGBooleanOffShows debugging output, like -d.
DEBUG1, true, *, or a comma-separated list with doc-detective or doc-detective:*UnsetShows debugging output, like -d. A pattern for another package leaves it off.
DOC_DETECTIVE_SKIP_AUTO_UPDATEBooleanOffSets autoUpdate: false. --auto-update beats it.
DOC_DETECTIVE_SKIP_BROWSER_UPDATEBooleanOffKeeps outdated cached browsers and drivers instead of replacing them with the latest build. A missing browser still installs, and install browsers --force still reinstalls.
DO_NOT_TRACKAny valueUnsetSets telemetry.send: false.
DOC_DETECTIVE_NO_COLORBooleanOffTurns off color, like --no-color. NO_COLOR and FORCE_COLOR keep their usual meaning.
DOC_DETECTIVE_NO_INPUTBooleanOffNever prompts, like --no-input.
DOC_DETECTIVE_ALLOW_LOCAL_URLSBooleanOffLets a public screenshot reference image or OpenAPI description redirect or refer to a private or loopback address. Local URLs work without it. Setting it with DOC_DETECTIVE_BLOCK_LOCAL_URLS exits 2. See Refuse local URLs on shared runners.
DOC_DETECTIVE_BLOCK_LOCAL_URLSBooleanOffRefuses every private and loopback address for screenshot reference images and OpenAPI $refs, including direct ones. For shared runners.
DOC_DETECTIVE_REUSE_APPIUMBooleanOffKeeps the Appium server running after a run, so the next run with the same setup skips its startup.
DOC_DETECTIVE_NO_ANDROID_AUTOINSTALLBooleanOffSkips an Android context instead of installing the Android toolchain on first use.
DOC_DETECTIVE_NO_IOS_AUTOINSTALLBooleanOffLeaves the WebDriverAgent build to Appium during the session instead of building it into the cache on first use. The iOS context still runs.
DOC_DETECTIVE_IOS_WDA_DERIVED_DATA_PATHA pathUnsetUses the WebDriverAgent build in this DerivedData directory instead of the managed build, and turns off the first-use build.
DOC_DETECTIVE_AUTOINSTALLBooleanOnOff stops npm install from also installing browsers and runtime dependencies.
DOC_DETECTIVE_SKIP_AGENT_PROMPTBooleanOffStops npm install from asking to install agent tools.
XDG_CONFIG_HOME, XDG_CACHE_HOMEPathsPlatform defaultsWhere the user config and the cache live.
DOC_DETECTIVE{"config": {...}}UnsetDeprecated: use DOC_DETECTIVE_CONFIG.
DOC_DETECTIVE_RUNTIME_DEBUGBooleanOffDeprecated: use DOC_DETECTIVE_DEBUG. Setting both, with either one on, exits 2.

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, so docker run <image> --input ... passes flags straight to the default run command. See Docker and headless runs.

Examples

Run tests over a directory:

npx doc-detective --input ./docs

Preview the resolved plan without running:

npx doc-detective --input ./docs --dry-run

Run a filtered subset with specific reporters:

npx doc-detective --input ./docs --test "smoke" --reporters terminal,json

Start the language server:

npx doc-detective lsp