Skip to content

CLI and exit codes

Install the umbrella package to get the termwright executable:

Terminal window
npm install --save-dev termwright
npx termwright --help
termwright doctor [--json]

Verifies the current Node.js version, the project’s Vitest resolution, a real PTY spawn/output/exit cycle, UTF-8 locale, artifact-directory access, and the host platform. Warnings describe reduced portability; failed checks produce exit code 1. Use --json in agents and environment diagnostics.

termwright test [--runs N] [--resource-profile <name>]
[--tags <expression>] [-- <vitest args>]

Runs the project tests once. --runs N repeats the complete selected suite in one Termwright process and returns the worst result. An infrastructure failure stops later repetitions. Skipped, empty, and filtered-zero runs remain visible but do not count as a passing suite.

passed-with-skips is a distinct amber result. It exits 0 only when the exact skip policy matches. Undeclared or ambiguous skips and missing required skips exit 1. JSON output includes the skipped test identities and policy issues.

Profiles are explicit: local, ci, windows-ci, or stress. Arguments after -- are test selection and runner options such as a file path, -t, or --retry. --tags filters Gherkin scenarios with a Cucumber tag expression. Any fail-then-pass result is flaky and exits non-zero.

termwright watch [--resource-profile <name>]
[--tags <expression>] [-- <vitest args>]

Runs an initial suite, then reruns after source changes. A change that arrives during a run is queued until that run finishes. The process returns the worst observed result when interrupted. --tags and arguments after -- have the same meaning as for test.

termwright ui [--resource-profile <name>] [--trace <file>] [--tags <expression>] [--port N] [--host H] [--no-watch] [--browser | --no-open] [-- <vitest args>]
termwright ui --record [--out-file <file>] -- <command>

Starts the Runner and test watch mode. Interactive use opens the Termwright desktop app by default.

OptionBehavior
--browserOpen the Runner in the system browser.
--no-openStart the server without opening a window.
--no-watchDo not start the test watcher.
--trace <path>Open an existing .twtrace path.
--tags <expression>Select physical Gherkin cases with a Cucumber tag expression.
--recordStart recorder mode for the command after --.
--out-file <file>Set the generated test destination in recorder mode.
--host <host>Bind the Runner server to this host.
--port <port>Bind to this port; 0 selects an available port.

Arguments after -- are passed to the embedded test runner:

Terminal window
npx termwright ui -- src/login.test.ts --retry=2

The Runner discovers TypeScript tests and physical Gherkin scenarios. You can then run a directory, file, or individual case from its catalog.

termwright report --trace <file> [--out-file <file>]

Writes a self-contained HTML report containing the React viewer and one trace. The result can be opened directly from disk or stored as a CI artifact.

termwright screenshot --trace <file> [--at <ms> | --step N] [--out-file <file>] [--scale N]

Renders one trace moment to PNG. With no time or step, the command selects the crash, the end of the last step, or the final useful frame.

termwright codegen [--out-file <file>] -- <command>

An alias for using ui --record when recording is the only task.

termwright mcp [--http] [--port N]
termwright mcp usage
termwright agent-context
termwright usage
termwright skill [--out <dir>]
CommandResult
termwright mcp [args]Run the MCP server; remaining arguments are forwarded.
termwright agent-contextPrint versioned JSON for MCP tools and exit codes.
termwright usagePrint the short command reference.
termwright skill [--out <dir>]Generate an agent skill package.
OptionBehavior
--help, -hPrint help for the selected command.
--version, -vPrint the installed version.
--jsonProduce machine-readable output and errors.

JSON output, CI, and non-interactive stdout suppress automatic window opening.

CodeMeaning
0Success.
1Test run failed, was flaky, or did not meet the accepted skip policy.
2Invalid command-line usage.
3No active session.
4IPC or transport failure.
5Internal failure.

Machine-readable errors include a kind, message, and applicable suggestion or candidates. Library errors include stable kinds such as timeout, ambiguous-locator, probe-attach-failed, capability-unavailable, not-actionable, input-mode-disabled, protocol-violation, process-exited, and session-closed.

See Runner UI, Traces and reports, and MCP tools.