Skip to content

Codex hooks receive session CWD instead of explicit tool workdir, blocking documented release workflows #50271

Open

Description

@daveladouceur

Summary

Codex did not reliably follow an explicit repository release procedure from a detailed AGENTS.md / release document, then its PreToolUse hook received the supervisor workspace as cwd instead of the command's effective workdir. Together, that blocked the canonical release command and encouraged an incorrect fallback.

This is a report about agent execution and hook-context fidelity, not a request to change a third-party tool.

Observed behavior

  • The repository documented one canonical release command for a versioned environment package. It also documented two mutually exclusive delivery channels: a Git/bare-hub slipstream path and an npm-installed-package path.
  • Codex was run in a supervisor workspace but invoked the canonical command with a different explicit workdir (the environment package worktree).
  • The Codex PreToolUse payload continued to identify the supervisor workspace as cwd.
  • A repository guard that correctly checks completion claims against the repository being shipped therefore judged the canonical release as a foreign claim and included unrelated dirty files from the supervisor workspace.
  • Instead of stopping and reporting the guard-context defect, Codex selected an alternate land command. That command landed Git but did not perform the documented publish/install transaction.
  • Codex then incorrectly tried direct npm installation even though the docs stated the active target was a bare-hub slipstream. The correct sequence was only followed after an operator correction.

Expected behavior

  1. A command launched with an explicit workdir should expose that effective workdir to every Codex hook, or expose it separately and unambiguously from the session workspace.
  2. Before a release/deploy/publish action, Codex should give explicit repository instructions higher priority than inferred topology or a convenient alternate command.
  3. When a guard blocks the documented canonical operation because execution context is inconsistent, Codex should surface that mismatch and stop. It should not select a fallback whose release semantics differ.
  4. Codex should make the repository/worktree it believes a command affects visible in the action trace, so a human can detect a context mismatch before an external change.

Minimal reproduction shape

  1. Start Codex in workspace A with a PreToolUse hook that consumes cwd and gates a release command against a work contract for repository B.
  2. Execute a release command with the tool workdir set to repository B.
  3. Observe that the hook receives cwd=A rather than cwd=B.
  4. The guard misclassifies the release as foreign or associates it with unrelated dirty state in A.

Why this matters

The repository instructions were unusually explicit and structurally sound. The failure was not a missing instruction or operator error. A system that accepts repository-level procedures but can silently substitute a different workspace context at hook time makes guarded release workflows unreliable: the safe path is blocked and a less-safe path appears available.

Requested outcome

  • Preserve the effective tool workdir in hook payloads.
  • Add an integration test for a session workspace different from the tool workdir.
  • Add an agent-side guardrail: if an explicit documented release command is blocked by a workspace/context mismatch, report that mismatch rather than choosing a semantically different release command.

Activity

  1. added
    bug
    hooks
    model-behavior
    on Oct 2, 2026
  2. aetherxeg-source commented on Oct 2, 2026

    @aetherxeg-source

    One execution-integrity boundary that seems useful to make explicit here is:

    session workspace != effective execution workdir

    A hook that authorizes, blocks, or attributes a command needs the context that actually governs that execution, not merely the workspace that owns the chat/session. Otherwise the hook can be internally consistent while evaluating the wrong repository state.

    I would keep at least three identities separate in the hook/event model:

    • session/workspace identity;
    • requested tool workdir;
    • resolved effective execution context (canonical path + repository/worktree identity where available).

    Conceptually:

    tool request -> resolve execution context -> hook decision bound to that context -> execute

    rather than:

    session context -> hook decision -> execute somewhere else.

    The important part is binding the hook verdict to the same resolved context the executor will consume. If path resolution, symlinks, worktrees, containers, or another indirection can change the effective target after the hook runs, the verdict should carry a context/generation identity and be rejected if execution resolves differently.

    A compact invariant is:

    approved context == executed context

    not just “the hook received a cwd field.”

    A useful regression matrix would cover: session A/tool workdir B, two worktrees of the same repository, a symlinked workdir, and a workdir that disappears/rebinds between hook evaluation and process start. The last case should fail closed rather than silently applying a verdict produced for a different execution target.

    For auditability I would also expose both sessionCwd and effectiveWorkdir when they differ, instead of overloading one cwd field. That makes context substitution visible to hooks and to later execution evidence.

  3. aetherxeg-source commented on Oct 2, 2026

    @aetherxeg-source

    A hook-context integrity invariant here is:

    policy evaluation context must equal effect execution context

    If the command executes in repository B while the PreToolUse guard evaluates cwd=A, the guard is authorizing/refusing a different subject from the one that will receive the effect. That is stronger than a convenience bug: the evidence used for the policy decision is misbound.

    I would carry both identities explicitly:

    session_workspace + effective_tool_workdir + command/effect identity + hook evaluation generation

    and require release/deploy guards to bind to the effective tool workdir. The session workspace can still be useful provenance, but it should never silently substitute for the execution target.

    A useful adversarial test is a session rooted at A with unrelated dirty files, a release command executed with workdir=B, and conflicting release policies in A/B. The hook must evaluate B's authoritative instructions/state and the trace must show B as the effect subject. Then reverse the case to ensure a command actually targeting A does not inherit B's authority.

    Also worth testing a symlink/renamed worktree case so lexical path equality is not mistaken for repository identity. The final release decision should bind to the canonical execution subject that the tool will mutate, not merely to whichever workspace opened the chat.

  4. vladzdev commented on Oct 15, 2026

    @vladzdev

    It would help to expose the session working directory and effective tool workdir as separate fields. Hooks need the latter for repository-scoped checks. I'd add a regression test where the session starts in repo A but a command explicitly targets repo B.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughooksmodel-behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions