Code Mode puts your agent's tool calls inside a scriptWhat approvals, hooks and sandboxes still see
Claude Code shipped Code Mode on November 12, and every model in the catalog Codex downloads now runs code_mode_only. In both, the model writes a JavaScript program that makes the tool calls, so a classifier or reviewer that reads the program cannot see the values it computes at run time. Rules, hooks and the shell sandbox still apply to each call, with gaps you have to close yourself.
-
01
Source
One script
model writes JavaScript, not single tool calls
Claude Code REPL, Codex exec -
02
Channel
Fan-out
script runs shell, file, web and MCP calls
results feed the next call -
03
Exposure
Partial review
classifier reads the code, not run-time values
rules, hooks and sandbox per call
TL;DR· the answer, in twenty seconds
What happened: Claude Code v2.1.323 (November 12, 2026) added Code Mode as an opt-in, and Codex already runs it by default because its server-delivered model catalog marks every model code_mode_only. The model writes JavaScript, and the harness runs the tool calls that program makes.
The minimum fix: In Claude Code, set onFailure: "block" on policy hooks, add ask rules for the commands you must see, keep OTEL_LOG_TOOL_DETAILS unset, and block Code Mode in managed settings if you cannot review it yet. In Codex, keep the OS sandbox on and audit the exec scripts in ~/.codex/sessions.
The lesson: A check that reads the program is weaker than a check on each call. Put the controls that matter on the call, on the process, and on the credential itself.
On November 12, Claude Code v2.1.323 added Code Mode, in which the model writes a JavaScript program and Claude Code runs the tool calls that program makes, and Codex already does the same by default for every model in the catalog OpenAI serves it.
Four days earlier, Letta co-founder Sarah Wooders posted that "Codex now defaults to programmatic tool calling (i.e. code mode) while Claude Code doesn't even support it." The post drew 514 likes and 65,000 views. The second half went stale within the week. The first half is right, and you cannot see it in the Codex settings most people check. codex features list on codex-cli 0.171.0 reports code_mode as "under development" and false, and the configuration reference says the feature is "off by default." Yet every Codex session on the machine I checked for this guide ran in code mode.
This matters for anyone who relies on approval prompts, an auto-mode classifier, hooks or a sandbox. Vendors designed those controls around one tool call at a time. A script that greps, picks a path from the output, edits it and pushes is one program to a reviewer and five calls to the harness. Some controls follow the calls. Others stop at the program. This guide covers which is which in each tool, what I verified, and the settings that close the gaps.
How each tool turned it on
Claude Code's changelog entry for 2.1.323 calls Code Mode "an experimental opt-in in which Claude writes JavaScript to call its tools." npm shows that version published on November 12. Through 2.1.331 on November 23, the changelog has 68 entries that mention Code Mode. You turn it on with an environment variable in your shell or in ~/.claude/settings.json, then confirm a prompt:
{
"env": { "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1" }
}
The Code Mode docs say Claude Code ignores the variable in a project's settings files, "so a repository you clone can't turn on Code Mode for you." It works only in an interactive terminal session, with Opus 5.5, Sonnet 5.5, Haiku 5.5 or Fable 5.2. A new tool, REPL, runs the code. The conversation shows the tool calls the code made, such as an edit's diff. It does not show the code itself. You press Ctrl+O and expand a collapsed Code row to read it.
Codex took a different path. The switch is in the model catalog that Codex downloads from OpenAI and caches at ~/.codex/models_cache.json. On November 24 the cache on my machine, fetched that morning, listed 12 models. All 12, from gpt-5.6-luna to gpt-6.2-sol, carried "tool_mode": "code_mode_only". The local feature flag never enters into it. You can check your own copy:
# Which tool mode does each model in your cached catalog use?
jq -r '.models[] | "\(.slug)\t\(.tool_mode)"' ~/.codex/models_cache.json
# Did your recent sessions call tools from scripts? Count rollouts with exec scripts.
grep -l '"name":"exec","input"' ~/.codex/sessions/2026/11/*/*.jsonl | wc -l
# Read the JavaScript the model wrote in one session
jq -r 'select(.payload.type=="custom_tool_call" and .payload.name=="exec")
| .payload.input' ~/.codex/sessions/2026/11/24/rollout-*.jsonl
On my machine, 305 rollout files from November 13 to 24, across codex-cli 0.169.0 to 0.172.0, all held exec calls whose input was JavaScript. None held a direct exec_command call. A typical script wraps several shell commands in Promise.allSettled([tools.exec_command({cmd: ...}), ...]). The machine held no older rollouts, so I cannot date the switch there. OpenAI's changelog shows steady Code Mode work through the period: interrupting a turn stops "active Code Mode cells and their nested tool calls" (October 15), host output truncation on by default (November 13), and gRPC for all Code Mode host connections (November 24).
The config reference still documents features.code_mode.enabled as off by default. It does not mention tool_mode. If your threat model depends on Codex making one tool call per model turn, it no longer describes your Codex.
What each control sees when the model writes the program
Split the controls into two groups. The first group applies to each tool call the code makes. The second reviews the code as a whole, before it runs.
In Claude Code, the docs put these in the first group:
- Deny and ask permission rules, written under the tool's usual name, such as
Bash(git push *)or an MCP tool's name. - PreToolUse hooks, which fire for each call the code makes.
- The Bash sandbox, for the shell commands the code runs.
- Prompts in the permission modes that ask. "You're prompted for each tool call that would prompt you in that mode."
The second group has one member, and it is the one many people lean on: auto mode's classifier. The Code Mode docs say "the classifier reviews each piece of code before it runs, not each tool call. It doesn't see values computed at run time, such as a path taken from search output, so keep rules or hooks for calls you must control." In the example the docs give, Claude finds a file with rg -l, takes the first line of the output and edits it. The classifier approves a program that edits whatever the search returns. It never sees which file that turns out to be.
The same limit cuts through the sandbox. The docs say: "The JavaScript itself and its file, web, and MCP tool calls run outside the sandbox." The sandbox wraps the shell commands. File reads through the Read tool, web fetches and MCP calls follow permission rules instead, as they do outside Code Mode. To isolate the whole thing, the docs point you to a container or a virtual machine.
Hooks hold a quieter trap. Before 2.1.329, released November 19, a PreToolUse hook that errored inside Code Mode refused the call. That release changed it to match the behavior outside Code Mode: an erroring hook "no longer refuses a script's tool call." The Code Mode docs now say to expect "a refused tool call when a PreToolUse hook doesn't finish, and a call that can still run when the hook fails another way." The hooks reference spells out "fails another way": a script path that does not exist, an exit code other than 0 or 2, invalid JSON. "A policy hook with a wrong path or a crashing script then lets everything through." With one call per turn, a hook error notice lands next to the call it let through. A program that makes 200 calls in one step can bury it among the rest.
Hooks also see commands in a different shape. Anthropic warns that "a git push in a folder named app can reach your hook as cd 'app' && git push." A hook that matches the start of the command string misses that. Bash rules split compound commands before they match. Your hook has to do the same.
The last gap is data flow. A program can read a token from one call and pass it to the next without the model printing it. The docs flag this for telemetry: "code can read a value, such as a token in a file, and pass it to another call. Leave OTEL_LOG_TOOL_DETAILS unset if your backend shouldn't receive those values." The same holds for anything that logs tool inputs. The secret moves between calls inside the runtime, and every logger on the path gets a copy.
Codex documents far less of this. The approvals page describes sandbox modes and approval policies per command and never mentions Code Mode. I tested the one thing I could test without an MCP server. In a scratch directory I ran:
codex exec --skip-git-repo-check -s read-only -c approval_policy='"never"' --json \
"Run exactly this shell command once: touch /tmp/ng-codex-test/probe.txt"
The rollout shows the model wrote await tools.exec_command({cmd:"touch /tmp/ng-codex-test/probe.txt"}), and the command failed with Operation not permitted. The OS sandbox applied to a shell command issued from inside a script. The --json event stream reported a command_execution item with the command and never showed the JavaScript. If you build audit tooling on that stream, you see the calls and miss the program that chose them. The program lives only in the rollout file.
I did not test whether Codex's approval prompts or its automatic reviewer fire per nested call in the on-request policy, and the docs do not say. The changelog has a November 18 entry, "Reserve Guardian context budget for selected Code Mode exec results," and the cached catalog sets an undocumented node_repl_auto_review_required field to true on six of the 12 models. Both suggest the reviewer looks at scripts. Neither tells you what it can see at run time. Treat Codex's reviewer the way Anthropic tells you to treat its classifier, as a check on the program that cannot see run-time values.
Harden Claude Code's Code Mode
If nobody on your team has turned it on, the first decision is whether anyone may. Managed settings cannot turn Code Mode on, but they can block it:
{
"env": { "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "0" }
}
A 0 anywhere wins over a 1 anywhere. Teams that use cloud providers face one caveat. A user who sets CLAUDE_CODE_USE_BEDROCK or a similar provider variable in their own shell "can start Code Mode without receiving server-managed settings." Deliver the block through MDM or a managed settings file on disk, not only through server-managed settings.
If you allow Code Mode, make your controls fail closed and per call. This is the user-level ~/.claude/settings.json I would start from:
{
"permissions": {
"ask": ["Bash(git push *)", "Bash(npm publish *)", "Bash(kubectl *)"],
"deny": ["Read(~/.aws/**)", "Read(~/.ssh/**)"]
},
"sandbox": {
"enabled": true,
"allowUnsandboxedCommands": false,
"failIfUnavailable": true,
"credentials": {
"files": [
{ "path": "~/.aws/credentials", "mode": "deny" },
{ "path": "~/.ssh", "mode": "deny" }
],
"envVars": [
{ "name": "GITHUB_TOKEN", "mode": "deny" },
{ "name": "NPM_TOKEN", "mode": "deny" }
]
}
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "node",
"args": ["/Users/you/.claude/hooks/check-command.js"],
"onFailure": "block"
}
]
}
]
}
}
What each piece does:
- The
askrules prompt for those commands in auto and bypassPermissions modes too, for the forms the rule matches. That is the documented way to make a script stop atgit pushafter auto mode has approved the program around it. - The
Readdeny rules cover the Read tool, which runs outside the sandbox. The sandboxing docs say sandboxed commands can read "most of the machine, including credential files such as~/.aws/credentials" unless you deny them.sandbox.credentialscovers the shell side and unsets the named variables before each sandboxed command. allowUnsandboxedCommands: falseis strict sandbox mode. Without it, code can ask to run a command outside the sandbox. The Code Mode docs say "the command has no separate review" in auto mode beyond the classifier's look at the program.failIfUnavailablestops Claude Code from running commands unsandboxed when the sandbox cannot start.onFailure: "block"turns a crashed or missing hook into a refusal. It needs v2.1.295 or later for command and http hooks, and v2.1.328 formcp_toolhooks. Test it the way the hooks reference suggests: point it at a script that does not exist, ask forls, and confirm that Claude Code refuses the call.
Make the hook script split compound commands on &&, ;, | and newlines before it matches anything. To read the program itself, write a PreToolUse hook that matches REPL. It receives the JavaScript in tool_input.code. That lets you log every program, or refuse ones that reach for paths you never want touched. It is still a check on the program, with the same run-time blind spot as the classifier.
For a human read of each program, add "REPL" to the ask list. Expect friction. The prompt does not include the code, so you press Ctrl+O, expand the row and come back. The docs warn of a side effect in auto mode: once you approve, "the code starts even when the classifier would have blocked it, and its project edits and read-only commands run without a prompt." Approving a program you skimmed is a wider grant than approving one command.
Two output controls round this out. A PostToolUse hook on REPL can redact what the code returns before Claude reads it, by returning an updatedToolOutput copy. It fails open: "If the hook crashes, times out, or prints invalid JSON, Claude gets the original output," and the refusedCalls field can repeat a refused call's input unchanged. Use it as a speed bump for tokens in output. It will not stop a secret from reaching the model. For telemetry, Code Mode's calls arrive with tool_use_id values starting repl_ or toolu_cc_. Keep OTEL_LOG_TOOL_DETAILS unset unless your telemetry backend is cleared to store secrets.
Harden Codex when every model runs code mode
Codex gives you fewer levers, and the main one, the catalog, is not yours to set by default. Start with what holds no matter how the model calls tools.
Keep the OS sandbox on and narrow. My test showed the sandbox blocks a nested shell command in read-only. The default for a version-controlled folder is workspace-write with on-request approvals. The approvals docs say that in this mode, "commands allowed by the sandbox can run without approval, read accessible files, and use network access if enabled." A script can chain many such commands in one model step. Leave network access off unless the task needs it. Never run danger-full-access or --dangerously-bypass-approvals-and-sandbox on a machine that holds credentials. The approvals docs already warn that in that mode "a malicious project can exfiltrate anything available inside the devcontainer, including Codex credentials."
Remember which traffic the network proxy never sees. The approvals page says it "does not filter web search, app or connector tool calls, MCP server connections, browser or Computer Use activity." A script that mixes shell commands with connector or MCP calls gets the egress allowlist on the first kind only.
Push sensitive MCP tools out of scripts. The config reference documents features.code_mode.direct_only_tool_namespaces, "Tool namespaces code mode can use only through direct tool calls." Put the namespace of a tool that can deploy, pay or delete there, and each call to it becomes a discrete tool call instead of a line inside a program. I have not tested this key, and the reference does not say whether it applies when the catalog sets code_mode_only while the local code_mode flag reads false. Set it, run a session that uses the tool, and check the rollout with the jq command above for a direct call to it.
# ~/.codex/config.toml
sandbox_mode = "workspace-write"
approval_policy = "on-request"
[sandbox_workspace_write]
network_access = false
[features.code_mode]
direct_only_tool_namespaces = ["mcp__deploy", "mcp__billing"]
Replace the namespaces with the ones your MCP servers register. Codex also documents model_catalog_json, a path to a local catalog loaded at startup, and model_catalog_url. Those are the only documented way I found to change what the catalog says. The reference does not list valid tool_mode values, and I did not try a catalog with a different value. Pinning your own catalog also freezes model metadata OpenAI would otherwise update, so treat it as a last resort and test it in a scratch environment first.
Audit from the rollouts, not the event stream. codex exec --json shows commands. ~/.codex/sessions/**/rollout-*.jsonl shows the programs. If you ship Codex logs to a SIEM, ship the custom_tool_call entries named exec. They are the record of what the model decided to do, and they will contain whatever the program read, secrets included, so store them as sensitive.
What this means for your stack
Today: in Codex, run the commands from the first section against your own ~/.codex and confirm what your sessions are doing. In Claude Code, block Code Mode in managed settings until you have reviewed it, or turn it on with onFailure: "block" on every policy hook, ask rules for the commands you must see, Read and sandbox.credentials denies for your credential files, and strict sandbox mode. Keep OTEL_LOG_TOOL_DETAILS unset in Claude Code.
The larger shift is that per-call review is losing ground to per-program review, and per-program review cannot see data. A classifier that approves "edit the file the search returns" has approved an edit to a file it never saw. A script that reads a token and passes it to the next call moves a secret the transcript may never show. Controls that survive this attach to the call, as rules and fail-closed hooks do, or to the process, as the OS sandbox does. The most durable one attaches to the credential: the agent's processes never hold a standing secret, and a broker injects a scoped value into the one command that needs it at the moment it runs.
hasp is one working implementation of that runtime brokering. Install with curl -fsSL https://gethasp.com/install.sh | sh, run hasp setup, and the broker hands secrets to the specific commands an agent runs instead of leaving them in the environment or on disk where a script can read them. Source-available (FCL-1.0), local-first, macOS and Linux, no account.
Whatever you run, retest your controls after every harness upgrade. Claude Code shipped nine releases in the 11 days after Code Mode landed, and Codex runs code mode because of a catalog field its configuration reference does not mention. Your hooks, rules and sandbox should get the same regression test as your code.
Sources· cited above, in one place
- Anthropic Run tool calls from code with Code Mode: permission checks, sandbox scope and hooks
- Anthropic Claude Code changelog
- Anthropic Claude Code hooks reference: ConfigChange and InstructionsLoaded
- Anthropic Configure the sandboxed Bash tool: read defaults, credential entries and security limits
- Anthropic Claude Code permission modes: what auto mode blocks, allows and sends to the classifier
- OpenAI Codex configuration reference: features.code_mode and model_catalog_json
- OpenAI ChatGPT and Codex changelog
- OpenAI Codex agent approvals and security: sandbox modes and approval policies
- Sarah Wooders on X Codex now defaults to programmatic tool calling (code mode)
Stop handing the agent your real keys.
hasp keeps secrets in one local encrypted vault, brokers them into the child process at exec, and never lets the agent read the value.
- Local, encrypted vault — no account, no cloud, no telemetry by default.
- Brokered run — agent gets a reference, the child process gets the value.
- Pre-commit + pre-push hooks catch managed values before they ship.
- Append-only HMAC audit log answers "did the agent touch the prod token?" in seconds.
macOS & Linux. Source-available (FCL-1.0, converts to Apache 2.0). No account.