@@ -24,7 +24,7 @@ separate implementations:
2424 prefixed by a ` // @exec: {...} ` pragma line for execution options), executed
2525 in Codex's in-process V8 Code Mode runtime.
2626- OpenClaw code mode runs in the generic OpenClaw agent runtime and is
27- disabled unless ` tools.codeMode.enabled: true ` is configured . Its ` exec `
27+ disabled unless ` tools.codeMode.enabled ` is ` true ` or ` "auto" ` . Its ` exec `
2828 tool takes a JSON ` { code, language } ` payload, executed in a QuickJS-WASI
2929 worker.
3030
@@ -112,7 +112,21 @@ Shorthand:
112112```
113113
114114Code mode stays off when ` tools.codeMode ` is omitted, ` false ` , or an object
115- without ` enabled: true ` .
115+ without ` enabled: true ` or ` enabled: "auto" ` .
116+
117+ To engage code mode only for models whose catalog marks them as strong code-mode
118+ performers, use the ` "auto" ` tier instead of ` true ` :
119+
120+ ``` json5
121+ {
122+ tools: {
123+ codeMode: " auto" ,
124+ },
125+ }
126+ ```
127+
128+ See [ Automatic per-model activation] ( #automatic-per-model-activation ) for the
129+ exact semantics and the shipped model list.
116130
117131If you use sandboxed agents with configured MCP servers, also allow the
118132bundled MCP plugin in the sandbox tool policy, for example
@@ -238,7 +252,7 @@ enable the feature on its own.
238252
239253| Field | Default | Clamp |
240254| --------------------- | ------------------------------ | ----------------------------------------------- |
241- | ` enabled ` | ` false ` | boolean; only ` true ` enables code mode |
255+ | ` enabled ` | ` false ` | ` false ` , ` true ` , or ` "auto" ` (per-model) |
242256| ` runtime ` | ` "quickjs-wasi" ` | only supported value |
243257| ` mode ` | ` "only" ` | exposes control/direct tools, catalogs the rest |
244258| ` languages ` | ` ["javascript", "typescript"] ` | any subset of the two |
@@ -252,7 +266,75 @@ enable the feature on its own.
252266| ` maxSearchLimit ` | ` 50 ` | ` 1 ` -` 50 ` |
253267
254268If code mode is enabled but QuickJS-WASI cannot load, OpenClaw fails closed
255- for that run; it does not silently expose normal tools as a fallback.
269+ for that run; it does not silently expose normal tools as a fallback. This
270+ holds for ` true ` and for ` "auto" ` runs where the model resolves as preferred:
271+ an engaged run never silently falls back to broad direct tool exposure.
272+
273+ ## Automatic per-model activation
274+
275+ ` tools.codeMode.enabled ` accepts three values:
276+
277+ - ` false ` (default): code mode is off for every run.
278+ - ` true ` : code mode engages for every tool-capable run, regardless of model.
279+ - ` "auto" ` : code mode engages only when the run's model is flagged as a
280+ preferred code-mode performer in its provider catalog.
281+
282+ ` false ` and ` true ` behave exactly as before the ` "auto" ` tier existed; ` "auto" `
283+ is purely additive.
284+
285+ ### The ` compat.codeMode ` catalog flag
286+
287+ Provider catalogs can tier a model with ` compat.codeMode ` on its model entry,
288+ next to flags like ` compat.supportsTools ` :
289+
290+ - ` "preferred" ` : the model reliably writes short orchestration programs and
291+ benefits from the compact code-mode surface; ` "auto" ` engages code mode.
292+ - ` "capable" ` (or absent): the model can run code mode when forced with
293+ ` enabled: true ` , but ` "auto" ` keeps normal tool exposure.
294+
295+ Models without tool support cannot use code mode at all; there is no separate
296+ "unsupported" tier. The flag is capability metadata owned by the provider
297+ plugin's catalog; core only reads the generic compat field.
298+
299+ ### Shipped preferred models
300+
301+ Bundled provider catalogs currently flag these models as ` "preferred" ` :
302+
303+ | Provider | Models |
304+ | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
305+ | anthropic | ` claude-fable-5 ` , ` claude-opus-5 ` , ` claude-sonnet-5 ` , ` claude-mythos-5 ` , ` claude-opus-4-8 ` , ` claude-haiku-4-5 ` |
306+ | deepseek | ` deepseek-v4-pro ` , ` deepseek-v4-flash ` |
307+ | google | ` gemini-3-flash-preview ` , ` gemini-3.1-pro-preview ` , ` gemini-3.1-flash-lite ` , ` gemini-3.5-flash ` , ` gemini-3.5-flash-lite ` , ` gemini-3.6-flash ` |
308+ | minimax | ` MiniMax-M3 ` |
309+ | moonshot | ` kimi-k3 ` |
310+ | openai | ` gpt-5.6 ` , ` gpt-5.6-sol ` , ` gpt-5.6-terra ` , ` gpt-5.6-luna ` , ` gpt-5.5 ` , ` gpt-5.5-pro ` |
311+ | xiaomi | ` mimo-v2.5 ` |
312+ | zai | ` glm-5.2 ` , ` glm-5.1 ` |
313+
314+ Everything else, including all Ollama-served local models, stays unflagged and
315+ keeps normal tool exposure under ` "auto" ` .
316+
317+ For OpenAI models, the flag matters only when the run resolves to the OpenClaw
318+ embedded agent runtime. Default OpenAI routing uses the Codex-style harness
319+ surface, where OpenClaw code mode does not apply; the catalog flag never
320+ changes that routing decision.
321+
322+ ### Choosing when to enable
323+
324+ In A/B evaluations on the preferred models above, code mode reduced total
325+ token usage by roughly 30-50% at equal-or-better task pass rates, mostly by
326+ replacing many full tool schemas and per-tool round trips with one compact
327+ program surface. Models below the preferred tier showed no consistent win and
328+ sometimes regressed, which is why ` "auto" ` leaves them on direct tools.
329+
330+ Use ` "auto" ` when agents switch between models: strong models get the compact
331+ surface, weaker or local ones keep the exposure they handle best. Use ` true `
332+ when you have verified a specific unflagged model performs well with code
333+ mode; global force-on is most predictable for single-model deployments. For
334+ open-weight or uncached serving where every prompt token is billed or
335+ recomputed, prefer enabling per model (via ` "auto" ` or a per-agent override)
336+ rather than globally, since the token savings depend on the model actually
337+ using the program surface well.
256338
257339## Activation
258340
@@ -264,7 +346,8 @@ final model request is assembled:
2643462 . Build the effective OpenClaw tool list, adding eligible plugin, MCP, and
265347 client tools.
2663483 . Apply allow/deny policy.
267- 4 . If ` tools.codeMode.enabled ` is false, continue with normal tool exposure.
349+ 4 . If ` tools.codeMode.enabled ` is ` false ` , or is ` "auto" ` and the run's model
350+ is not catalog-preferred, continue with normal tool exposure.
2683515 . If enabled and tools are active for the run, retain required direct-only
269352 tools and register every catalog-eligible effective tool in the code-mode
270353 catalog.
0 commit comments