Skip to content

PreToolUse omits the effective shell for exec_command #44836

Open

Description

@MaksymShostak

PreToolUse for exec_command exposes command text but omits the effective shell. On Windows this prevents a policy hook from selecting the matching shell grammar safely.

The inspected release source is rust-v0.153.4, exec_command.rs: pre_tool_use_payload constructs the canonical Bash tool name and a command-only input. The shell argument used by execution is absent.

A real downstream consequence is recorded in Universal Ontology #48: a read-only PowerShell query compares pending approval records with literal Git command strings. DCG 0.14.1 rejects the protected dispatch as core.git:branch-force-delete; no Git operation is executed by the query. On 2026-09-11, repeating that exact read-only query with shell: "C:/Program Files/PowerShell/7/pwsh.exe" still produced the same native denial before execution.

The retained inert native classifier comparison uses the unchanged DCG binary: the full original text is denied with unknown dialect and allowed with explicit PowerShell. Actual deletion/invocation/removal syntax remains denied in those diagnostics. These comparisons do not execute any specimen.

DCG's pinned hook source explicitly documents the missing Codex shell metadata. Its Windows handling cannot assume that canonical Bash means POSIX or that every Windows request is PowerShell, so ambiguous requests retain conservative multi-dialect handling.

Please expose the shell resolved for the actual pending execution through a supported hook contract. Preserve existing matching semantics and command rewrite behavior; use the same shell resolution as execution. Requested shell text alone is insufficient if resolution can fall back or select another environment. Regression coverage should show that PowerShell and POSIX execution of shell-sensitive text produce distinguishable, accurate hook metadata, while hook denials still prevent execution.

Limits: the producer omission is directly visible in the tagged source. The live observation is a native host denial, not a captured raw hook envelope or proof that this Desktop binary exactly matches that tag. No wrapper, forced DCG dialect, allowlist, hook change or guard patch was used. This report does not claim a security bypass or an installed fix.

Related metadata reports #32360 and #37251 concern effective cwd, not effective shell. Searches for PreToolUse/shell/Windows, hook/dialect and hooks/selected shell found no matching shell-metadata report. Written by Codex during the owner's authorized SDLC integration work.

Activity

  1. added
    bug
    app
    windows-os
    hooks
    on Sep 11, 2026
  2. jimy-r commented on Sep 12, 2026

    @jimy-r

    Same gap on the Claude Code side, and the way I live with it may be useful until the field exists. My PreToolUse guard sees only the command string, so it matches raw text across both dialects at once. The blocklist carries the PowerShell and the POSIX spellings of each destructive shape, plus the exec-hijacking prefixes (GIT_SSH_COMMAND=..., core.hooksPath=...). It fails open on its own bugs, because a broken guard must never wedge the session, and fails closed on a match. The cost is exactly what your third-party tool hit, false positives on read-only commands whose text resembles a write. I accept those, name around them, and re-issue a blocked compound command as separate steps, since a blocked compound ran nothing.

    What the resolved-shell field would buy is parsing instead of pattern-matching. A guard that knows the grammar can tell Get-Content from rm without a dialect union, and the false-positive rate drops to the parser's error rate. So +1 to exposing it, and I'd add one item to the ask. Also expose the working directory the command will resolve relative paths against, since path-substring guards have the same ambiguity.

    I maintain a reference architecture that documents the hook at https://github.com/jimy-r/agent-workspace-architecture/blob/main/PATTERNS.md#7-a-cheap-hook-beats-a-careful-agent

  3. NOTgithub commented on Oct 5, 2026

    @NOTgithub

    I reproduced the missing shell metadata on Windows with Codex CLI 0.160.0.

    In a separate test workspace, I trusted a minimal informational PreToolUse hook through the normal Codex interface. The prompt explicitly requested exec_command with shell: "pwsh.exe" and this harmless command:

    Write-Output TOOLBOX_SHELL_PROBE_302

    The command succeeded. The hook reported:

    {
      "tool": "Bash",
      "input_fields_present": ["command"],
      "other_input_field_count": 0,
      "input_shell": {},
      "event_shell": {},
      "cwd_present": true
    }

    This is minimized diagnostic output, not the raw hook payload. The hook found no shell identity in the inspected fields. Consequently, our policy hook cannot reliably select the correct shell parser.

    No production guard was disabled or bypassed. The test session has ended and the temporary workspace has been removed.

  4. thereisno-tomorrow commented on Oct 22, 2026

    @thereisno-tomorrow

    Independent downstream reproduction on native Windows with the unchanged DCG v0.15.3 release binary (3eec165ae64a56bfbb2cecaa2510d82076010851).

    This small, harmless PowerShell command is enough to expose the cost of missing shell metadata:

    @'
    print('hello')
    '@ | python -

    Submitting that text to DCG as data, without executing it:

    DCG evaluation Observed
    dcg test --stdin --dialect unknown --format json deny: heredoc.posix:pipeline-consumer
    Same input, --dialect ps allow
    Synthetic Codex PreToolUse envelope with tool_name: "Bash" and a nonempty turn_id deny
    Same synthetic envelope with tool_name: "PowerShell" allow

    Minimal downstream reproducer (Python; executes only DCG):

    import json, shutil, subprocess
    dcg = shutil.which("dcg")
    assert dcg, "Put the installed DCG executable on PATH"
    command = "@'\nprint('hello')\n'@ | python -"
    for dialect in ("unknown", "ps"):
        result = subprocess.run(
            [dcg, "test", "--stdin", "--dialect", dialect, "--format", "json"],
            input=command, text=True, capture_output=True,
            # DCG returns exit 1 for a deny; still parse its JSON verdict.
        )
        data = json.loads(result.stdout)
        print(dialect, data["decision"], data.get("rule_id"))

    The current Codex producer, inspected on 2026-10-22, still constructs HookToolName::bash() with tool_input: {"command": args.cmd}. The DCG v0.15.3 handling explains why a Windows guard cannot safely infer the executor from this label.

    Please expose the resolved execution shell, including fallback resolution, while retaining existing hook matching and deny semantics. Globally relabeling Windows calls as PowerShell would miss cases that actually execute under Bash or CMD.

    Scope: this is a classifier reproduction plus source inspection, not a new capture of a raw Codex hook event. The PowerShell pipeline was never executed. No private command history, user paths, credentials, or raw session payloads are included.

  5. barad1tos commented on Nov 19, 2026

    @barad1tos

    Confirmed on macOS with Codex CLI 0.169.0. In one isolated codex exec --ephemeral session, I used a local model replay to send two exec_command calls with identical command text. The only argument that changed was shell.

    {"cmd":"printf 'Bash=%s zsh=%s\\n' \"$BASH_VERSION\" \"$ZSH_VERSION\"","shell":"/bin/bash","login":false}
    {"cmd":"printf 'Bash=%s zsh=%s\\n' \"$BASH_VERSION\" \"$ZSH_VERSION\"","shell":"/bin/zsh","login":false}

    Both calls exited 0. Their output confirmed which shell ran.

    Bash=3.2.57(1)-release zsh=
    Bash= zsh=5.9
    

    The PreToolUse hook logged the same tool_name and tool_input for both calls.

    {"tool_name":"Bash","tool_input":{"command":"printf 'Bash=%s zsh=%s\\n' \"$BASH_VERSION\" \"$ZSH_VERSION\""}}

    Exposing the effective shell in PreToolUse would let hooks select the correct parser when exec_command.shell changes within a session.

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

    appbughookswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions