Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.159.2
What subscription do you have?
Not specified
Which model were you using?
gpt-6-sol (reasoning effort high)
What platform is your computer?
Windows 11 Pro (10.0.26200), x64
What terminal emulator and version are you using (if applicable)?
Windows Terminal / PowerShell
Codex doctor report
n/a
What issue are you seeing?
A user-level PreToolUse hook whose matcher covers spawn_agent is never invoked when the model spawns a sub-agent in an interactive session, so a permissionDecision: "deny" from the hook cannot block the spawn.
Other hooks in the same ~/.codex/hooks.json do run in the same session (a UserPromptSubmit hook and a PostToolUse hook both fire and their additional_context shows up in the rollout as hooks.additional_context developer messages), so hooks are loaded and trusted. Only the PreToolUse hook for spawn_agent never runs.
This looks like the same bug class as #23411 (Code Mode exec doesn't fire PreToolUse) and #18391 (apply_patch): the spawn_agent handler (namespace: "collaboration") apparently doesn't provide a pre-tool-use payload, so run_pre_tool_use_hooks is never called for it.
What steps can reproduce the bug?
- In
~/.codex/hooks.jsonadd:
{
"hooks": {
"PreToolUse": [
{
"matcher": "^(Agent|(.*[._:/])?spawn_agent)$",
"hooks": [{ "type": "command", "command": "python /path/to/guard.py" }]
}
]
}
}where guard.py appends one line to a log file and prints:
{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "blocked by test hook"}}- Start a new interactive
codexsession and ask it to spawn a sub-agent (e.g.spawn_agentwithagent_type= a configured role, message "say hello"). - The rollout contains the
function_callspawn_agent(namespace: "collaboration") and the sub-agent runs and answers. - The hook's log file gets no line and the rollout shows no hook output for that call. Piping the same payload (
{"hook_event_name":"PreToolUse","tool_name":"spawn_agent","tool_input":{...}}) intoguard.pyby hand does produce the log line and the deny.
What is the expected behavior?
PreToolUse hooks run for spawn_agent (and the other collaboration tools) like they do for Bash/apply_patch, and a deny decision prevents the sub-agent from starting. This is needed to enforce policies such as "only these agent roles / models may be spawned".
Additional information
- The sub-agent was started with the role's configured reasoning effort even though the call requested a different one, so role config is applied; only the hook is skipped.
- Related: Code Mode
execdoesn't firePreToolUsehooks (fix patch attached) #23411, fix(core): emit hooks for apply_patch edits #18391.
Activity