OpenClaw Code Mode
The two-tool surface, the hidden catalog, how it differs from Codex Code Mode, and when to turn it on
Code Mode changes what an OpenClaw model sees when it works. Instead of every enabled tool schema, it sees two control tools, exec and wait, plus the few direct-only tools whose results cannot cross a JSON-only bridge, and it writes a small JavaScript or TypeScript program that searches, describes and calls the hidden tool catalog. It is experimental and off by default. Here is what it does, why the docs say it helps, the guardrails, the switch, and the clarification the docs open with: this is not Codex Code Mode.
What changes
- The model-visible tool list becomes exec, wait, and direct-only tools such as the computer tool or the native-vision image loader, whose image result cannot survive the guest bridge.
- Every catalog-eligible enabled non-MCP tool, core, plugin or client, is hidden as a standalone tool and exposed inside the guest program as an async global function; MCP tools stay under an MCP namespace and are discoverable by task through catalog search.
- The exec description carries a bounded quick index of callable names with compact input and output hints, never full schemas; a handle exposes bounded metadata and a describe call, but never the exact internal catalog id, and calls use the same execution path as normal turns, so policy, approvals, hooks and telemetry all still apply.
- Wait resumes a suspended run when nested tool calls are still pending, and only when the outer result says it is waiting; a background shell operation returned inside a cell has its own session id, which is not a Code Mode run id.
Both are JavaScript execution surfaces, not shell-command surfaces.
Not Codex Code Mode
The two features share a name and the same control-tool names, but they are separate implementations. Codex Code Mode runs inside the Codex coding harness: its exec tool is a freeform-grammar tool where the model writes raw JavaScript source, optionally prefixed by a pragma line, executed in Codex’s in-process V8 runtime. OpenClaw Code Mode runs in the generic agent runtime, is enabled through global, agent or model activation settings, and its exec takes a JSON payload of code and language, executed in a QuickJS-WASI worker. In OpenClaw’s version, command is an alias for code rather than a shell command, recognisable shell commands are rejected before execution with actionable guidance, and shell or file work goes through the async tool globals from guest code. Source validation, TypeScript compilation and execution run in a bounded pool of warm worker threads that scales with CPU cores, each cell gets an isolated VM, tool permissions, approvals and session ownership stay with the Gateway, and cancellation stops an active worker before the call settles.
Why use it, and when not to
- Smaller prompt surface: two control tools, a bounded native-tool index and only the required direct tools instead of dozens or hundreds of full schemas; better orchestration, since loops, joins, transforms, conditional logic and parallel nested calls fit in one cell; fewer round trips when a declared output contract lets the model call and transform a result in one exec.
- Provider neutral, since it works for core, plugin, MCP and client tools without provider-native code execution; and it fails closed: if Code Mode is enabled but the QuickJS-WASI runtime is unavailable, the run fails instead of silently falling back to broad direct tool exposure.
- Most useful for agents with a large enabled tool catalog or workflows that search, combine and call several tools before answering. Keep direct exposure for a small catalog or a model that does not reliably write short programs, and use Tool Search for a compact catalog with structured search, describe and call controls instead of the guest.
OpenClaw Swarm is the fan-out layer built on top of Code Mode scripts, and OpenClaw and MCP explains the servers that appear under the MCP namespace.
Turning it on
The Labs switch under the agents and tools settings writes the auto tier, which engages only for models marked as preferred Code Mode performers; that is the global default, and agent and model overrides take precedence. Code Mode changes the model-facing orchestration surface only: it does not replace tools, plugin tools, MCP tools, auth, approval policy, channel behavior or model selection, and the docs split the rest across eight pages, quickstart, configuration, tool surface, guest API, output, internals, troubleshooting and maintainer notes. OpenClaw models and providers covers the model choice the auto tier keys on.
On Diali
On Diali the runtime ships with Code Mode at its upstream default, off; the Labs switch is where an assistant opts in, and everything the guest program calls still passes the same approvals. Hosted OpenClaw on Diali is the assistant.
- Two control tools instead of every schema.
- A JavaScript surface, never a shell surface.
- Fails closed when the runtime is missing.
Stop reading about it, build one
Set up an agent, pick a channel, and have it working inside the app you already keep open.
