Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

feat(openai-codex): enable code mode when /models reports code_mode_only

Jack Rudenko2751a1b791b9
diff --git a/ai-docs/architecture/code-mode.md b/ai-docs/architecture/code-mode.md
index 7f9e0715..29fbeb06 100644
--- a/ai-docs/architecture/code-mode.md
+++ b/ai-docs/architecture/code-mode.md
@@ -1,7 +1,7 @@
# Code mode — Codex models driven the way their own client drives them
`--code-mode <auto|on|off>` (> `CLAUDISH_CODE_MODE` > `codeMode` in the project `.claudish.json`
-> `codeMode` in the global config > the default `off`) changes how the claudish provider
+> `codeMode` in the global config > the default `auto`) changes how the claudish provider
`openai-codex` (the ChatGPT Codex backend, `cx@`) is asked to call tools. Instead of Claude
Code's ~90 tools as classic function tools, the request carries ONE freeform tool, `exec`, whose
input is a JavaScript script that calls `tools.<Name>(args)`; claudish runs the script in a QuickJS
@@ -9,9 +9,13 @@ sandbox and relays every nested call to Claude Code as an ordinary `tool_use` bl
Codex client has driven these models this way since `tool_mode: code_mode_only`; claudish was the
only client still sending them classic parallel function calls.
-The default is `off` until the Phase 7 live validation passes; a separate change then makes `auto`
-the default (on where the account's dynamic models catalog reports `code_mode_only`). With code
-mode off, everything code mode added is skipped (5r returns at once, 5d returns at the
+The default is `auto`: code mode is on only where the account's dynamic models catalog (the Codex
+`/models` endpoint) reports `tool_mode: "code_mode_only"` for the model, and only for `openai-codex`
+on the OAuth arm with tools declared; every other claudish provider is unaffected. It became the
+default after Phase 7 iteration 2 passed on Claude Code 2.1.303 and 2.1.304 (`[email protected]`):
+the real `auto` path 20/20 answers with 39/39 relayed exec ids resumed and 0 lost-state notes,
+edit + Bash 6/6, a claudish restart mid-script 2/2, and the compiled binary 1/1. `--code-mode off`,
+`CLAUDISH_CODE_MODE=off` or `codeMode: "off"` turns it off. With code mode off, everything code mode added is skipped (5r returns at once, 5d returns at the
`setting-off` gate, apart from one `[CodeMode] off (setting-off)` log line per session). The
request is NOT byte-for-byte what it was before this work, for one deliberate reason: commit
`d6629064` sends `filterIdentity(system)` as the Responses `instructions` of EVERY `cx@` and
@@ -49,7 +53,7 @@ be in code mode pays no discovery wait, creates no store and loads no sandbox:
| # | Gate | Off reason | Why |
|---|---|---|---|
| 1 | claudish provider is `openai-codex` | `not-openai-codex` | the only backend measured |
-| 2 | setting is not `off` | `setting-off` | the default |
+| 2 | setting is not `off` | `setting-off` | the user's opt-out |
| 3 | the binding's arm is `oauth` | `metered-arm` | the api-key arm reaches api.openai.com, which publishes no `tool_mode` |
| 4 | the login has a ChatGPT account id | `no-account-id` | every record is keyed by account (below); a login without one never gets code mode |
| 5 | the wire API is Responses | `not-responses` | |
@@ -378,9 +382,9 @@ model, never an HTTP error.
## Not proven yet
-- Phase 7 live validation (the real `auto` path ×10, edit + Bash, a mixed classic → code-mode
- history after `claude --resume`, Esc on a nested permission prompt, `--resume` across a claudish
- restart mid-script, the compiled-binary smoke). The default stays `off` until it passes.
+- Not run live in Phase 7: a mixed classic → code-mode history after `claude --resume`, and Esc
+ on a nested permission prompt. `openai@` was BLOCKED (V3: the account had no credits); gate 3
+ keeps the api-key arm out of code mode whatever the setting.
- Reasoning replayed before a first nested call after a switch to non-code-mode (remembered under
`toolu_cx_<hex>_0`, the A3 `_p0` rule) was never observed live.
- A login without a ChatGPT account id never gets code mode; if real logins lack it, a fallback
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts
index 9f57bc2c..0974c207 100644
--- a/packages/cli/src/cli.ts
+++ b/packages/cli/src/cli.ts
@@ -1160,7 +1160,7 @@ export async function parseArgs(args: string[]): Promise<ClaudishConfig> {
}
// codeMode precedence: --code-mode flag > CLAUDISH_CODE_MODE env > project
- // ./.claudish.json > global config.json > off. An env value other than
+ // ./.claudish.json > global config.json > auto. An env value other than
// auto/on/off states nothing and falls through to the config files.
if (config.codeMode === undefined) {
config.codeMode =
@@ -2341,7 +2341,7 @@ ${h("OPTIONS")}
${green("--effort-override")} ${yellow("<level>")} Pin reasoning effort verbatim, skipping the per-model clamp
${green("--pro-on-ultracode")} Apply the model's catalog preset while in ultracode (opt-in)
${green("--no-pro-on-ultracode")} Force that off for this run (when enabled in config/env)
- ${green("--code-mode")} ${yellow("<auto|on|off>")} cx@ tools as one exec script tool (default off; env CLAUDISH_CODE_MODE)
+ ${green("--code-mode")} ${yellow("<auto|on|off>")} cx@ tools as one exec script tool (default auto; env CLAUDISH_CODE_MODE)
${green("--accept-served-model")} Allow a reasoning-off that the connection serves with another model
${green("-y, --auto-approve")} Skip permission prompts (--dangerously-skip-permissions)
${green("--no-auto-approve")} Explicitly enable permission prompts (default)
diff --git a/packages/cli/src/code-mode/policy.ts b/packages/cli/src/code-mode/policy.ts
index fd07ef97..9097c04d 100644
--- a/packages/cli/src/code-mode/policy.ts
+++ b/packages/cli/src/code-mode/policy.ts
@@ -3,9 +3,9 @@
*
* Precedence: `--code-mode <auto|on|off>` > `CLAUDISH_CODE_MODE` > `codeMode`
* in the project `.claudish.json` > `codeMode` in the global config > the
- * default. The default is `off` until code mode has passed live validation;
- * `auto` then turns it on where the Codex `/models` endpoint reports
- * `tool_mode: code_mode_only`.
+ * default, `auto`: on where the Codex `/models` endpoint reports
+ * `tool_mode: code_mode_only`, and only for `openai-codex` on the OAuth arm
+ * with tools declared. `off` turns it off everywhere.
*
* Pure: no runtime imports from the request path (types only), so the CLI can
* read it without loading anything else of code mode.
@@ -23,7 +23,7 @@ export type CodeModeSetting = "auto" | "on" | "off";
export const CODE_MODE_SETTINGS: readonly CodeModeSetting[] = ["auto", "on", "off"];
/** The setting when nothing states one. */
-export const DEFAULT_CODE_MODE_SETTING: CodeModeSetting = "off";
+export const DEFAULT_CODE_MODE_SETTING: CodeModeSetting = "auto";
/** The env var that sets code mode when no flag does. */
export const CODE_MODE_ENV_VAR = "CLAUDISH_CODE_MODE";
diff --git a/packages/cli/src/handlers/composed-handler.ts b/packages/cli/src/handlers/composed-handler.ts
index 31e399fb..9526ac60 100644
--- a/packages/cli/src/handlers/composed-handler.ts
+++ b/packages/cli/src/handlers/composed-handler.ts
@@ -268,7 +268,7 @@ export interface ComposedHandlerOptions {
/**
* Code mode for `openai-codex` (`auto` | `on` | `off`), resolved by the CLI
* from `--code-mode` > `CLAUDISH_CODE_MODE` > `codeMode` config. Absent ⇒
- * `off`. Read only on the `openai-codex` request path.
+ * `DEFAULT_CODE_MODE_SETTING` (`auto`). Read only on the `openai-codex` request path.
*/
codeMode?: CodeModeSetting;
/**
@@ -1487,9 +1487,10 @@ export class ComposedHandler implements ModelHandler {
requestPayload = this.provider.transformPayload(requestPayload, claudeRequest, binding);
}
- // 5d. Code mode (`openai-codex` only; off unless `--code-mode` /
- // CLAUDISH_CODE_MODE / `codeMode` turns it on). After 5c, so the Codex
- // fields 5c added are kept; decided from THIS request's binding. A lite
+ // 5d. Code mode (`openai-codex` only; by default `auto`, on where
+ // discovery reports `code_mode_only`; `--code-mode` / CLAUDISH_CODE_MODE /
+ // `codeMode` override it). After 5c, so the Codex fields 5c added are
+ // kept; decided from THIS request's binding. A lite
// request's header joins `wireHeaders`, so every header fetch below
// carries it. Never throws: a failed decision or build leaves the request
// exactly as 5c produced it.
diff --git a/packages/cli/src/profile-config-code-mode.test.ts b/packages/cli/src/profile-config-code-mode.test.ts
index f9dbb27c..6df77db5 100644
--- a/packages/cli/src/profile-config-code-mode.test.ts
+++ b/packages/cli/src/profile-config-code-mode.test.ts
@@ -57,8 +57,8 @@ describe("T5 code-mode configuration", () => {
expect((await parseArgs(args)).codeMode).toBe("auto");
});
- test("REQ-16 TEST-26 an absent setting defaults to off", async () => {
- expect((await parseArgs(args)).codeMode).toBe("off");
+ test("REQ-16 TEST-26 an absent setting defaults to auto", async () => {
+ expect((await parseArgs(args)).codeMode).toBe("auto");
});
test.each(["auto", "on", "off"] as const)(
diff --git a/packages/cli/src/profile-config.ts b/packages/cli/src/profile-config.ts
index 1e68dc58..a3ec4dde 100644
--- a/packages/cli/src/profile-config.ts
+++ b/packages/cli/src/profile-config.ts
@@ -259,11 +259,11 @@ export interface ClaudishProfileConfig {
proOnUltracode?: boolean;
/**
- * Code mode for `openai-codex` (`auto` | `on` | `off`, default `off`): Claude
+ * Code mode for `openai-codex` (`auto` | `on` | `off`, default `auto`): Claude
* Code's tools are offered to the model as one freeform `exec` tool running
* a script, the protocol the official Codex client uses.
* Precedence: --code-mode flag > CLAUDISH_CODE_MODE env > project
- * `.claudish.json` > this field > off. The scoped read is `readCodeMode()`,
+ * `.claudish.json` > this field > auto. The scoped read is `readCodeMode()`,
* NOT this allowlist — same reason as `proOnUltracode`.
*/
codeMode?: CodeModeSetting;
diff --git a/packages/cli/src/proxy-server.ts b/packages/cli/src/proxy-server.ts
index 8ad848d6..08ecad32 100644
--- a/packages/cli/src/proxy-server.ts
+++ b/packages/cli/src/proxy-server.ts
@@ -165,7 +165,7 @@ export interface ProxyServerOptions {
proOnUltracode?: boolean;
/**
* `--code-mode`: code mode for `openai-codex` (`auto` | `on` | `off`).
- * Absent ⇒ `off`.
+ * Absent ⇒ `DEFAULT_CODE_MODE_SETTING` (`auto`).
*/
codeMode?: CodeModeSetting;
}
diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts
index f1ca0a40..873058a3 100644
--- a/packages/cli/src/types.ts
+++ b/packages/cli/src/types.ts
@@ -87,7 +87,7 @@ export interface ClaudishConfig {
modelParams?: Record<string, unknown>;
/** --pro-on-ultracode: apply the model's catalog provider-preset while in ultracode (opt-in) */
proOnUltracode?: boolean;
- /** --code-mode auto|on|off: code mode for `openai-codex` (resolved; default off) */
+ /** --code-mode auto|on|off: code mode for `openai-codex` (resolved; default auto) */
codeMode?: CodeModeSetting;
// Cost tracking