Skip to content

Report the local command working directory in PreToolUse hooks - #57198

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/97f71f6d3e21a5d95a7abf5384f06f4993241797
Oct 26, 2026
Merged

copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/97f71f6d3e21a5d95a7abf5384f06f4993241797

Conversation

@copyberry

@copyberry copyberry Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Report the local command working directory in PreToolUse hooks

Why

PreToolUse hooks receive the host working directory even when a local
exec_command call specifies a different workdir. This prevents hooks from
seeing the directory in which the command will execute.

What changed

  • Share working-directory resolution between command execution and hook input,
    using the selected environment and the command's workdir.
  • Report the resolved local directory in the hook input's cwd. Keep hook
    processes in the host directory and retain the host cwd for remote commands.
  • Reject invalid environment selections or paths before running hooks and record
    failures in tool-result telemetry.

Testing

Add unit and integration coverage for default, empty, relative, and absolute
working directories; Windows path conventions; remote commands; hook denial and
input rewriting; and invalid arguments that fail without running hooks.

## Why

`PreToolUse` hooks receive the host working directory even when a local
`exec_command` call specifies a different `workdir`. This prevents hooks from
seeing the directory in which the command will execute.

## What changed

- Share working-directory resolution between command execution and hook input,
  using the selected environment and the command's `workdir`.
- Report the resolved local directory in the hook input's `cwd`. Keep hook
  processes in the host directory and retain the host `cwd` for remote commands.
- Reject invalid environment selections or paths before running hooks and record
  failures in tool-result telemetry.

## Testing

Add unit and integration coverage for default, empty, relative, and absolute
working directories; Windows path conventions; remote commands; hook denial and
input rewriting; and invalid arguments that fail without running hooks.

GitOrigin-RevId: 97f71f6d3e21a5d95a7abf5384f06f4993241797
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/97f71f6d3e21a5d95a7abf5384f06f4993241797 branch from 0aa52ea to fe15bd3 Compare October 26, 2026 19:11
@copyberry
copyberry Bot merged commit fe15bd3 into main Oct 26, 2026
1 check passed
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-26T19:11:43.040082Z 0aa52ea PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/97f71f6d3e21a5d95a7abf5384f06f4993241797 branch October 26, 2026 19:11

@vrnrn vrnrn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head fe15bd3. No demonstrable correctness or security issues found in this diff. Static review only; no builds or tests were run.

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants