Skip to content
DocsStar33Playground

rax run

ReferenceLast updated 2026-12-02 · 6ecf6193fQuickstart

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.

Terminal window
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:

Terminal window
echo "List the files in this folder" | rax run --tools

Runs an agent file (Open Agent Spec or AgentConfig JSON). --provider, --model and --name override the file. See Run an agent 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.

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.

LLM provider. Default anthropic.

Model identifier.

Agent name. Default cli-agent.

Enables the built-in tools (files, web, code), equivalent to .withTools({ builtins: true }).

Enables reasoning strategies (.withReasoning()).

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.

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.

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.

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.

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

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.

Records the run durably (.withDurableRuns()), so rax ps and rax attach see it. The run id is printed on stderr.

A JSON array of scripted turns ({ "text" }, { "json" }, { "toolCall" }, { "toolCalls" } or { "error" }) for --provider test. With any other provider it is a usage error.

Sends run lifecycle events to a local Cortex studio (.withCortex()).

Streams tokens to the terminal and turns off the live status line.

Prints only the output and turns off the live status line.

Shows phase-by-phase execution details, including when output is piped (not a TTY).

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.

Terminal window
rax run --tools --workspace ./my-app --terminal --allow-command gh --approve ask "Fix the failing test"

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 ask asks y/N on the terminal and fails closed: with no terminal to ask on, when the answer does not arrive before the policy’s timeoutMs, 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 deny refuses every gated call.
  • --approve always sets mode: "block" (decided in this process). To pause a run and decide later (mode: "detach"), set approvalPolicy.mode in the agent file and leave out --approve. With --durable, the paused run exits 4. See Human-in-the-Loop Approval.

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.

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.

The run completed with an answer.

The run failed, was cancelled, or ended without a result. Also: the agent failed to build (for example an MCP server that cannot connect).

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

The agent abstained: it declined to answer instead of guessing. The reason is printed on stderr.

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

Terminated by SIGINT.

Terminated by a second SIGTERM.

The code comes from the run’s typed outcome, never from the answer text.

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.

Terminal window
rax run --agent helper.agent.json "Plan a trip"
rax run --agent helper.agent.json "Plan a trip" --model gpt-4o-mini

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

Terminal window
rax run "Explain quantum computing" --provider anthropic --model claude-sonnet-4-6 --cortex

Install

Bun (recommended)bun add reactive-agents
Node 22.5+npm install reactive-agents

Get notified on new releases

Release notes, about once a month.