rax run
Run an agent with a one-shot prompt. Part of the CLI reference. The process follows the agent process contract: the answer goes to stdout, logs go to stderr, signals control the run, and the exit code says how it ended.
rax run [prompt] [--agent <file> [--trust-file] [--allow-file-endpoint]] [--provider anthropic|openai|gemini|groq|xai|ollama|litellm|test] [--model <model>] [--name <name>] [--tools] [--reasoning] [--mcp-config <path>] [--workspace <dir>] [--workspace-context] [--terminal [--allow-command <cmd>]...] [--approve ask|deny] [--events jsonl] [--durable] [--test-scenario <path>] [--stream] [--cortex] [--verbose|-v] [--quiet|-q]The prompt is every word that is not a flag. Without one, rax run reads the prompt from stdin when stdin is piped:
echo "List the files in this folder" | rax run --toolsOptions
Section titled “Options”--agent <file>
Section titled “--agent <file>”Runs an agent file (Open Agent Spec or AgentConfig JSON). --provider, --model and --name override the file. See Run an agent file.
--trust-file
Section titled “--trust-file”Runs an agent file or MCP config (.rax/mcp.json, --mcp-config) that starts local commands (stdio MCP servers), calls remote agents (agentTools[].remoteUrl), gives the model a shell (tools.terminal) or reads values from your environment. Without it, rax asks on a terminal and exits 2 elsewhere. It also keeps the file’s telemetry and Cortex URL, which are dropped otherwise (a y at the prompt does not keep them). See Files that run commands.
--allow-file-endpoint
Section titled “--allow-file-endpoint”Lets the agent file’s llm_config.url receive your API key. Without it, rax exits 2 when a key would be sent there. See The file’s model endpoint.
--provider <name>
Section titled “--provider <name>”LLM provider. Default anthropic.
--model <model>
Section titled “--model <model>”Model identifier.
--name <name>
Section titled “--name <name>”Agent name. Default cli-agent.
--tools
Section titled “--tools”Enables the built-in tools (files, web, code), equivalent to .withTools({ builtins: true }).
--reasoning
Section titled “--reasoning”Enables reasoning strategies (.withReasoning()).
--workspace <dir>
Section titled “--workspace <dir>”Keeps the file tools, and the shell when it is on, inside <dir>: .withTools({ workspace }). Overrides the agent file’s tools.workspace. A missing directory or a path that is not a directory exits 2. See Working directory.
--workspace-context
Section titled “--workspace-context”Adds the workspace’s file listing, manifest scripts and AGENTS.md (or CLAUDE.md) to the system prompt: .withTools({ workspaceContext: true }). Overrides tools.workspaceContext. Anyone who can write that instructions file can instruct your agent; read Describe the workspace to the model before using it on a directory you do not control.
--terminal
Section titled “--terminal”Gives the model shell-execute (allowlisted commands, run in the workspace, or in a temporary sandbox directory without one): .withTools({ terminal: true }). Off by default. Overrides tools.terminal; when the agent file sets tools.terminal as an options object, those options are kept.
--allow-command <cmd>
Section titled “--allow-command <cmd>”Adds <cmd> to the shell allowlist. Repeatable. Needs --terminal; without it, rax run exits 2. Replaces the agent file’s tools.terminal.additionalCommands and keeps the file’s other shell options.
--approve ask|deny
Section titled “--approve ask|deny”Gates mutating tool calls (file-write, file-edit, code-execute, shell-execute and any other tool that requires approval) with .withApprovalPolicy({ mode: "block" }). ask asks y/N on the terminal, one call at a time. deny refuses every gated call. Overrides the agent file’s approvalPolicy.mode and keeps its other fields, such as tools and timeoutMs. An unknown mode exits 2. See Approval.
--mcp-config <path>
Section titled “--mcp-config <path>”MCP server config JSON. Without it, rax run loads .rax/mcp.json from the current directory when that file exists. Either file’s stdio servers need --trust-file or a y at the terminal prompt; off a terminal without the flag, rax run exits 2 and starts nothing. Nothing is remembered between runs. HTTP and SSE servers need no trust. See Files that run commands.
--events jsonl
Section titled “--events jsonl”Writes every run event to stdout as one JSON line, ending with the terminal event (StreamCompleted, StreamError or StreamCancelled). Implies --quiet. jsonl is the only format. Cannot be combined with --stream.
--durable
Section titled “--durable”Records the run durably (.withDurableRuns()), so rax ps and rax attach see it. The run id is printed on stderr.
--test-scenario <path>
Section titled “--test-scenario <path>”A JSON array of scripted turns ({ "text" }, { "json" }, { "toolCall" }, { "toolCalls" } or { "error" }) for --provider test. With any other provider it is a usage error.
--cortex
Section titled “--cortex”Sends run lifecycle events to a local Cortex studio (.withCortex()).
--stream
Section titled “--stream”Streams tokens to the terminal and turns off the live status line.
--quiet, -q
Section titled “--quiet, -q”Prints only the output and turns off the live status line.
--verbose, -v
Section titled “--verbose, -v”Shows phase-by-phase execution details, including when output is piped (not a TTY).
Workspace, terminal and approval flags
Section titled “Workspace, terminal and approval flags”Each of --workspace, --workspace-context, --terminal, --allow-command and --approve maps to one builder option. With --agent, a flag replaces only the agent file field it shadows (tools.workspace, tools.workspaceContext, tools.terminal, tools.terminal.additionalCommands, approvalPolicy.mode); the file’s other fields stay, for example its shell timeout or its approval tool list.
A flag is your own consent, so it needs no --trust-file. Instead, --terminal and --approve each print one line on stderr naming what they enabled (with --terminal, the directory the shell runs in and any extra commands). These lines print even with --quiet.
rax run --tools --workspace ./my-app --terminal --allow-command gh --approve ask "Fix the failing test"Approval
Section titled “Approval”rax run never asks for approval on the terminal unless you pass --approve ask. An agent file’s approval policy stays deny by default: a gated call that nothing in the process decides is refused. A file that sets approvalPolicy in mode: "block" therefore refuses every gated call, because a file cannot carry an onApprove decider.
--approve askasksy/Non the terminal and fails closed: with no terminal to ask on, when the answer does not arrive before the policy’stimeoutMs, or when the prompt fails, the call is refused with a reason. It also turns off the live status line so the question stays readable.--approve denyrefuses every gated call.--approvealways setsmode: "block"(decided in this process). To pause a run and decide later (mode: "detach"), setapprovalPolicy.modein the agent file and leave out--approve. With--durable, the paused run exits4. See Human-in-the-Loop Approval.
stdout and stderr
Section titled “stdout and stderr”stdout carries only the answer, or the token stream with --stream, or the event lines with --events jsonl. Status, warnings, errors and the metrics summary go to stderr, so rax run "..." > answer.txt captures the answer alone.
Signals
Section titled “Signals”While the run is going, rax run maps OS signals onto the run’s controls:
| Signal | Effect |
|---|---|
SIGTERM |
Stops gracefully: the agent answers with what it has, and the process exits with the run’s outcome. |
SIGTERM a second time |
Terminates the run now. Exits 143. |
SIGINT (Ctrl-C) |
Terminates the run now. Exits 130. |
SIGTSTP / SIGCONT |
Pauses at the next iteration / resumes. |
SIGUSR2 |
Prints a JSON snapshot of the run (status and inspection) on stderr. The run continues. |
SIGTSTP, SIGCONT and SIGUSR2 are POSIX only. If a terminated run does not end within 5 seconds, the process exits anyway with 130 or 143.
Exit codes
Section titled “Exit codes”Code 0
Section titled “Code 0”The run completed with an answer.
Code 1
Section titled “Code 1”The run failed, was cancelled, or ended without a result. Also: the agent failed to build (for example an MCP server that cannot connect).
Code 2
Section titled “Code 2”Usage or configuration error, before the run starts: an unknown flag or value, a missing value, --stream with --events, a missing provider API key, no prompt, an unreadable --mcp-config or --test-scenario, an unknown --approve mode, --allow-command without --terminal, a --workspace that does not exist or is not a directory, or any --agent file problem (including a file that needs --trust-file off a terminal, and a file endpoint that would receive your key without --allow-file-endpoint).
Code 3
Section titled “Code 3”The agent abstained: it declined to answer instead of guessing. The reason is printed on stderr.
Code 4
Section titled “Code 4”A --durable run paused, awaiting approval or an answer to a question. It is not a failure: the run is checkpointed, and stderr prints the command to continue it, rax attach <runId>.
Code 130
Section titled “Code 130”Terminated by SIGINT.
Code 143
Section titled “Code 143”Terminated by a second SIGTERM.
The code comes from the run’s typed outcome, never from the answer text.
API keys
Section titled “API keys”rax run reads the provider’s key from its environment variable (ANTHROPIC_API_KEY, OPENAI_API_KEY, …) first, else from the key saved with rax keys set <provider>. With neither, it exits 2 and names both fixes.
Run an agent file
Section titled “Run an agent file”rax run --agent helper.agent.json "Plan a trip"rax run --agent helper.agent.json "Plan a trip" --model gpt-4o-miniAn agent file is untrusted input. Before the agent is built, rax checks what the file runs (--trust-file) and where your API key would go (--allow-file-endpoint). Every agent file problem exits 2 before the agent is built. Overrides, warnings and both checks: Run a file from the CLI.
Cortex
Section titled “Cortex”--cortex enables .withCortex() on the builder so run lifecycle events are sent to a local Cortex companion studio (WebSocket ingest). Cortex is available as a public npm package (@reactive-agents/cortex). For npm-installed CLI: bun add @reactive-agents/cortex && rax cortex. For repo contributors: bun cortex (runs from source with hot reload). Set CORTEX_URL to the HTTP base (default http://127.0.0.1:4321).
rax run "Explain quantum computing" --provider anthropic --model claude-sonnet-4-6 --cortexInstall
Bun (recommended)bun add reactive-agentsNode 22.5+npm install reactive-agentsGet notified on new releases
Release notes, about once a month.