You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PreToolUse matcher bypassed for namespaced MultiAgentV2 spawn_agent #36519
CLIIssues related to the Codex CLIbugSomething isn't workinghooksIssues related to event hookssubagentIssues involving subagents or multi-agent features
PreToolUse matcher bypassed for namespaced MultiAgentV2 spawn_agent
Codex version
Reproduced on codex-cli 0.146.0 and 0.147.0-alpha.4.
Problem
A managed PreToolUse hook whose matcher is spawn_agent (or its Agent
alias) blocks the non-namespaced/v1 native spawn path, but does not block the
MultiAgentV2 tool exposed as collaboration.spawn_agent. The namespaced spawn
executes even though the managed requirements and hook are loaded.
This makes a blanket native-subagent deny policy bypassable whenever
MultiAgentV2 is enabled.
Root cause
MultiAgentV2NamespaceOverride in codex-rs/core/src/tools/spec_plan.rs
forwards execution to the wrapped handler but does not forward pre_tool_use_payload. The default runtime payload therefore uses the exposed
namespaced tool identity rather than the canonical hook identity expected by
the existing spawn_agent/Agent matcher mapping.
Minimal correction
Implement pre_tool_use_payload on MultiAgentV2NamespaceOverride, delegate
to the wrapped handler, and normalize the V2 spawn payload to HookToolName::spawn_agent(). A regression test can construct the namespaced
V2 spawn handler and assert that its pre-tool payload has canonical tool name spawn_agent and preserves the decoded input.
Verification
With that narrow patch applied to tag rust-v0.146.0:
the focused Rust regression test passes;
a real TUI call to collaboration.spawn_agent reaches the managed PreToolUse hook;
the hook returns a blocked function-call result; and
no child session is created.
Without the patch, equivalent live attempts on 0.146.0 and 0.147.0-alpha.4
create child sessions.
Reproduced a related failure on Codex Desktop for macOS, bundled codex-cli 0.155.0-alpha.16, with hooks, multi_agent, and multi_agent_v2 all enabled.
A user-level, synchronous PreToolUse command hook uses matcher ^(Agent|spawn_agent|collaboration\.spawn_agent)$. A fresh app-server hooks/list reports it as enabled: true, trustStatus: trusted, with no warnings or errors. The hook script logs only the event's session ID, tool name, and task name for this probe. Feeding the script a local control event writes one receipt. A real Desktop collaboration.spawn_agent call with explicit model, reasoning_effort, and fork_turns: "none" created a child, but wrote no hook receipt. The receipt instrumentation was removed after the probe.
This does not isolate whether the V2 tool skipped the local hook path or supplied a different matcher name (for example, the flattened name reported in #33284). It does establish that the trusted hook above did not enforce policy on this real dispatch. Please normalize the V2 spawn's hook identity or provide another documented synchronous pre-dispatch policy surface. A SubagentStart notification cannot replace this because the child has already been created.
Concrete acceptance case: a hook inspects the visible model, reasoning_effort, and fork_turns fields and denies a spawn when reasoning_effort is omitted or fork_turns is not "none"; the denial prevents child creation. Explicit valid values pass. This requires no access to the encrypted task message. Please cover the namespaced V2 path with an end-to-end regression test, including a fresh Desktop/app-server session.
CLIIssues related to the Codex CLIbugSomething isn't workinghooksIssues related to event hookssubagentIssues involving subagents or multi-agent features
Activity
Yinghai75 commentedon Sep 23, 2026
Reproduced a related failure on Codex Desktop for macOS, bundled
codex-cli 0.155.0-alpha.16, withhooks,multi_agent, andmulti_agent_v2all enabled.A user-level, synchronous
PreToolUsecommand hook uses matcher^(Agent|spawn_agent|collaboration\.spawn_agent)$. A fresh app-serverhooks/listreports it asenabled: true,trustStatus: trusted, with no warnings or errors. The hook script logs only the event's session ID, tool name, and task name for this probe. Feeding the script a local control event writes one receipt. A real Desktopcollaboration.spawn_agentcall with explicitmodel,reasoning_effort, andfork_turns: "none"created a child, but wrote no hook receipt. The receipt instrumentation was removed after the probe.This does not isolate whether the V2 tool skipped the local hook path or supplied a different matcher name (for example, the flattened name reported in #33284). It does establish that the trusted hook above did not enforce policy on this real dispatch. Please normalize the V2 spawn's hook identity or provide another documented synchronous pre-dispatch policy surface. A
SubagentStartnotification cannot replace this because the child has already been created.Concrete acceptance case: a hook inspects the visible
model,reasoning_effort, andfork_turnsfields and denies a spawn whenreasoning_effortis omitted orfork_turnsis not"none"; the denial prevents child creation. Explicit valid values pass. This requires no access to the encrypted task message. Please cover the namespaced V2 path with an end-to-end regression test, including a fresh Desktop/app-server session.