The OpenAI-compatible runner

A second agent runner drives any OpenAI-compatible chat endpoint (POST <base>/chat/completions) in a tool-use loop over the same six tools Claude Code has: Bash, Read, Edit, Write, Glob, Grep. The default is unchanged: without the switch below every run uses Claude Code.

Switch it on, in the forge's environment (only there: a run's env, where granted secrets land, is never read for these, and a secret cannot be named OPENAI_*):

Without a base URL and a model a run ends as an error saying so. Read it as the run's result.

The endpoint's redirects are refused, so the key goes to the configured host or nowhere.

What it does: the file tools resolve every path inside the run's clone, following symlinks, and refuse anything outside, or a path through a link to nothing; a write never follows a link at its last name. Bash runs under bubblewrap held to the run's sandbox policy (src/crew/openai_jail.ts): every denied path is covered, only the clone, its temp directory and its install cache are writable, and the shell has a network of its own whose one way out is the forge's egress proxy (HTTPS_PROXY), which passes the policy's hosts alone; loopback, its own namespace's listeners, goes direct (NO_PROXY), so an app's tests reach the server they start. It needs an enforced sandbox: where the host cannot enforce one, Bash answers with a refusal and the model uses the file tools. The shell sees only PATH, HOME, TMPDIR and the run's env less anything named like a secret (OPENAI_*, FORGE_*, KEY, TOKEN, SECRET, PASSWORD). Bounds: an endpoint answer over 4 MB ends the run, a turn runs at most 16 tool calls, Bash is killed at 120 s and its output cut at 30 000 bytes, Grep skips files over 1 MB, reads 1 000 characters of a line and refuses a pattern with a repeated group that can backtrack without bound. A run ends at 60 turns.

Not carried over from the Claude runner: resuming a session (each run starts fresh), steering a run while it works, and images. Each answer is asked for as a stream (stream: true, with stream_options.include_usage): text reaches the page as it is written and a tool call is put together from its pieces; an endpoint that answers in one body is read the same.

Talk runs on it too. With FORGE_AGENT_RUNNER=openai, a Talk turn reaches the forge's own MCP (src/crew/openai_mcp.ts): the tools Talk is offered are listed to the model as OpenAI tools, named as Claude Code names them (mcp__forge__tell), and each call goes to the forge, which decides as it always does. A call it holds for your yes answers needs_confirm, to the model as the call's result and to the thread as the Do it and Not now buttons; nothing is skipped. There is no session to resume: the forge hands the stored turns of the conversation to the model with each message. A call whose arguments are not JSON is answered with how to mend it, once; a second in a row ends the turn. A Talk turn on a model the price table does not know has no cost to state, so none is stored or shown (never $0); a crew run keeps the dearest row so its budget holds. Pinned by test/openai-talk.test.ts.

A local model (Ollama, LM Studio, llama.cpp's server): Talk's prompt and its tools come to about 7,000 tokens before the history, so the model needs a context of 32,768 tokens or more. Ollama's default is 4,096, of which it reads about half of a longer prompt, without an error; set OLLAMA_CONTEXT_LENGTH=32768 where ollama serve runs (its /v1 endpoint takes no context size per request), and point the forge at it with OPENAI_BASE_URL=http://127.0.0.1:11434/v1. A prompt the endpoint read less than half of is said once in the turn and the run log, naming that setting, so a cut prompt never passes quietly. A small model that writes a tool call out as text (<function-call>…, <tool_call>…, or a JSON object naming a function) instead of calling it has run nothing: it is told so and gets the one retry a call with broken arguments gets, and its text is never kept as the answer. Measured with qwen3:4b on a MacBook (2026-11-25): a tool question, a held close and a follow-up from the history all answered right, at 70 to 220 seconds a turn, most of it thinking, which OPENAI_REASONING_EFFORT=low shortens.

A picked subscription is what the run spends (#15198). When the forge picks an account for the run, its token goes to that account's gateway (<gateway>/v1/chat/completions, through the forge's door for a crew run), never to OPENAI_BASE_URL with the operator's key. An account with no gateway (a bare Anthropic token) cannot drive this runner, so the run ends as an error saying so rather than spending the operator's key on it.

Cost and the cap. An endpoint reports tokens, not dollars, so the forge prices them from the table in src/crew/openai_price.ts: cost = tokens in × in/1e6 + tokens out × out/1e6, at the providers' list prices in USD per million tokens. It errs high: cached input is charged as fresh, a model pays the price of the longest name it starts with, and a model the table does not know pays its dearest row, $15/$75. The running cost reaches the crew through onUsage and the outcome's costUsd, and a turn that brings it to the run's budget ends the run with max_budget_reached, as a Claude run does; that turn's tool calls are not run. The run log's first line names the price used.

Pinned by test/openai-runner.test.ts and test/openai-runner-escape.test.ts; the code is src/crew/openai_runner.ts.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs