Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.155.0-alpha.16.3, bundled with VS Code extension openai.chatgpt-26.917.62051-darwin-arm64. The source trace below is pinned to 4b1c0c30dabd08fed7d6523844f9156d982eb297.
What subscription do you have?
ChatGPT Enterprise
Which model were you using?
gpt-6-sol
What platform is your computer?
Darwin 25.6.0 arm64 arm (uname -mprs).
What terminal emulator and version are you using (if applicable)?
VS Code extension. The terminal emulator version was not recorded.
Codex doctor report
Not captured for the extension-bundled binary.What issue are you seeing?
A Bash PermissionRequest hook can approve or deny an exec_command escalation, but its input omits the selected execution directory and environment. For commands with relative paths, the hook cannot determine which directory an approval would affect.
At the pinned revision, exec_command resolves workdir against the selected environment. The resulting ApprovalAction::ExecCommand retains cwd and environment_id. Its PermissionRequest projection passes only the command and justification to a serializer that emits command and optional description.
The top-level hook cwd cannot supply the missing context. Codex sets it from the host-local hook directory, and the Hooks documentation defines it as the session working directory. This is a missing permission-payload capability, not a claim that the documented cwd value regressed.
A policy that denies unknown directories rejects a valid approval for another worktree. A policy that treats top-level cwd as the command directory can approve an operation in the wrong location. This report does not claim that hooks replace Codex's sandbox.
What steps can reproduce the bug?
- Create
/tmp/codex-hook-cwd/aand/tmp/codex-hook-cwd/b. Start Codex with the session directory set toa. - In a disposable Codex home, configure and trust a
PermissionRequestcommand hook with matcher^Bash$. Have it append its stdin JSON to a file and return no decision, so the normal approval prompt remains in control. - Use
on-requestapproval and a read-only permission profile. Invokeexec_commandwith arguments equivalent to:
{
"cmd": "pwd",
"workdir": "/tmp/codex-hook-cwd/b",
"sandbox_permissions": "require_escalated",
"justification": "check permission hook context"
}- Repeat with the same command and justification, but set
workdirto/tmp/codex-hook-cwd/a. - Compare each hook event's
cwdandtool_input. If the requests are approved, compare the twopwdoutputs.
The pinned repository has an integration test that invokes a real Bash PermissionRequest hook. Giving that test two workdirs and checking the recorded hook input would make this a deterministic regression test. The PermissionRequest omission reported here follows from the pinned producer code; I have not captured this specific event from the installed binary.
What is the expected behavior?
PermissionRequest should expose the pending command's resolved execution directory and selected environment identity in explicit fields. A relative workdir must resolve using the selected environment's path semantics.
Keep top-level cwd as the host-local session or hook directory. Keep the existing allow, deny, and normal approval behavior.
The same approval projection also drops retained context for Execve and managed-network Bash requests. Those sibling routes should expose the context available for their own pending operation.
Additional information
A separate live PreToolUse probe on the installed binary supplied an explicit workdir. The command ran there, but the captured hook input contained only tool_input.command and the session cwd. This supports the related reports below. The PermissionRequest finding above is based on the pinned source and its existing integration path.
I have a candidate branch, based on 4b1c0c30, with the implementation in commit 9b31c45e. It could serve as a base for a maintainer fix. The patch carries the selected execution directory and environment identity through:
PreToolUsefor unifiedexec_command;- applicable Bash
PermissionRequestpaths; - immediate
PostToolUsecompletion; and - terminal
PostToolUsecompletion afterwrite_stdin.
It may help resolve the unified-exec portions of these existing reports:
- #33986:
exec_commandPreToolUseloses per-callworkdir. - #32360:
PreToolUsereports the session directory instead of the execution directory. - #37251:
PreToolUseomits the effective directory for shell-like tools. - #40348:
PreToolUseandPostToolUseneed the effective directory, including delayed completion.
The branch does not change classic shell_command, which #32360 and #37251 also cover. Code-mode execution could not be verified on this macOS ARM64 host because its rusty_v8 build artifact was unavailable. Windows and remote execution remain unverified. On the preceding main revision, 105 focused host tests passed; the patch stayed byte-identical when moved to 4b1c0c30. just clippy -p codex-core and just fmt-check passed on 4b1c0c30. The broader codex-core suite was not all green, so this branch is a candidate base rather than a completed upstream validation.
Activity
argszero commentedon Sep 25, 2026
Your producer trace holds up on current
main, and there is a stronger piece of evidence than the one cited: the sameApprovalActionalready exposescwdandenvironment_idto the Guardian reviewer — with a dedicated rendering — andenvironment_ideven has an accessor. The hook is the one consumer of that action which never got the attribution fields. Details below, all line numbers verified onmain(58670eeac4);approvals.rs,sandboxing.rsandexec_command.rsare byte-identical to the revision your trace pins, so your analysis carries over unchanged.1. Where the context is dropped.
ApprovalAction::ExecCommandretainsenvironment_id,cwd: PathUri,sandbox_permissions,additional_permissions,tty(core/src/tools/approvals.rs:68-80). ItsPermissionRequestprojection destructures with..and forwards only the command and justification (:169-173) intoPermissionRequestPayload::bash, whose serializer has no field for anything else (core/src/tools/sandboxing.rs:134-148).Execve(:199-202) andNetworkAccess(:217-224) take the samebash()route with the same result.2. The tell is in the same
match. TheWriteStdinarm two branches below hand-buildstool_inputand does emitenvironment_id,cwd,tty,sandbox_permissions,additional_permissions(:174-197). So the payload type is not designed to be context-free — I could not read this as deliberate minimalism, and I'd be interested if a maintainer says otherwise. This was not an accident of one commit either: theWriteStdinkeys were added on purpose for the escalated-terminal approval path (#40978,a57b398351), so the hook projection has already been extended for one tool and simply never extended forexec_command.3. The pipeline grew the fields; the hook projection did not follow. Same file, ~400 lines down, the Guardian path consumes exactly those two fields to decide how a command's path must be interpreted: it resolves the selected environment and maps its OS to
PathConvention::{Windows,Posix}(:589-612), falling back to spelling-based inference only for legacy executors that report no OS. The Guardian's own action type then carriesenvironment_id,cwd: PathUriandguardian_cwd, documented as "Executor-native rendering sent to Guardian;cwdremains typed for attribution" (core/src/guardian/approval_request.rs:19-30), plus anenvironment_id()accessor over every variant (:95-104). Two consumers of one action, in the same approval, and only one can answer "which directory would this affect?" — using the word attribution for it. Since then the pipeline gained target-native paths (#42577,7a7c188682) and executor paths for Guardian reviews (#42838,773f0b081d) without the hook projection moving, which is the shape of lag rather than of a decision.4. Your PreToolUse siblings are the same root cause, reached differently. There the payload is built before any handler runs:
pre_tool_use_payloadreturnsfunction_hook_tool_input(arguments)— the model's raw argument JSON,Value::String-wrapped on parse failure (core/src/tools/registry.rs:133-142,:849-855), while the effective directory only exists later, afterworkdiris joined onto the environment cwd (core/src/tools/handlers/unified_exec/exec_command.rs:196-205). Note the escape hatch right above it:post_tool_use_payloadprefersresult.post_tool_use_input(...)and only falls back to the raw arguments (registry.rs:99-131). So the codebase already has a "let the tool supply richer hook-facing input" seam — post-execution only. Pre-execution events have no equivalent, which is why #33986, #32360, #40348 and #37251 all keep landing on the same wall. I'd treat that as a separate work item from this one (different event, different plumbing), but the family is real and worth tracking together.5. Minimal shape, and it needs no wire change. Because
tool_inputis an unconstrainedValuein both the struct and the published schema, the fields can be added nested insidetool_input: no new top-level field, noPermissionRequestCommandInputchange (codex-rs/hooks/src/schema.rs:301-318), no schema regeneration. Suggested keys, mirroringWriteStdinso the two arms agree:cwd(resolved, expressed under the selected environment's path semantics),environment_id, andsandbox_permissions/additional_permissions/ttywhere the variant has them. Top-levelcwdstays the host-local session/hook directory thattool_hook_cwdcomputes (core/src/hook_runtime.rs:248-253, used at:269). Two things worth knowing before anyone assumes the tests forbid this:assert_permission_request_hook_inputonly asserts absence at the top level of the hook input (core/tests/suite/hooks.rs:1213-1232), and Codex extensions inside this payload are established practice —turn_idis documented as one.6. A small independent fix in the same area. Top-level
cwdhas no description in the generated schema at all — it is only"type": "string", in both the PermissionRequest and PreToolUse input schemas, because descriptions in these files come from Rust doc comments (schema.rs:287and:310carry none whileturn_iddoes). Documenting it there would put the session-directory semantics you had to look up in external docs into the artifact a hook author actually reads, and it is landable on its own.7. Test hook you already identified.
permission_request_hook_sees_raw_exec_command_input(core/tests/suite/hooks.rs:3286-3355) runs a real BashPermissionRequesthook through the mock server and asserts the loggedtool_input; giving it twoworkdirs and asserting the resolved directory plusenvironment_idturns your report into a deterministic regression test using existing fixtures.I'm not claiming a
cwdregression or that hooks should replace the sandbox — your framing is right and the failure mode is exactly the one you describe: a policy keyed on the top-levelcwdneither rejects the valid approval nor catches the wrong directory. The open question is whether the team wants these fields in the hook contract at all; if the answer is yes,tool_inputis the cheap place for them.