Skip to content

Settle Which Shell Runs a Claude Code Hook on Native Windows Before Changing How registered_launcher Splits a Command #4040

Description

@ptr727

Question

Which shell runs a Claude Code hook command on native Windows: cmd.exe or CreateProcess, or Git Bash? registered_launcher in host-setup/agent-safety/claude/install.py splits a registered hook command to find its launcher, and the right split depends on the answer.

Why it matters

Copilot raised this on promotion #4039 against the launcher probe #4032 added. A constructed check showed which parts hold:

  • Not a defect today: for the double-quoted shape hook_command() writes, the POSIX shlex.split keeps the backslashes. A command such as "C:\Tools\py\python.exe" "D:\hooks\x.py" splits back intact.
  • Undecided: a UNC path and a bare, unquoted, hand-written registration. A cmd-style split (posix=False, one quote pair stripped) reads them the way cmd.exe would. If Git Bash runs the hook, the POSIX split already matches what runs, and a cmd-style split fails open. It would report a launcher healthy while the hook never runs, for example "\\host\share\python.exe", which bash runs as \host\share\python.exe.

Done when

The executor is established from Claude Code's hook documentation, or from a native Windows hook that echoes its argv. registered_launcher then splits the way that executor runs the command, and a test pins it. If the executor is Git Bash, the UNC spelling hook_command() writes is checked as well.

Activity

  1. added
    bug
    on Nov 10, 2026
  2. ptr727 commented on Nov 22, 2026

    @ptr727
    OwnerAuthor

    Maintainer's answer, 2026-11-22: a read-only seat now establishes, from Claude Code's hook documentation, which shell runs a hook on Windows, and records it here. The maintainer then approves the registered_launcher change. It lands in a round after #4317's PR merges, since both edit host-setup/agent-safety/claude/install.py.

  3. ptr727 commented on Nov 22, 2026

    @ptr727
    OwnerAuthor

    Research result, 2026-11-22: which shell runs a Claude Code hook on Windows (from Anthropic's Claude Code docs; read-only).

    • Shell form (no args): per https://code.claude.com/docs/en/hooks.md, "The command string is passed to a shell: sh -c on macOS and Linux, Git Bash on Windows, or PowerShell when Git Bash isn't installed. Set the shell field to choose explicitly." The docs never name cmd.exe for hooks.
    • shell field: "Accepts "bash" or "powershell". Defaults to "bash", or to "powershell" on Windows when Git Bash isn't installed... Ignored when args is set."
    • Exec form (with args): "Claude Code resolves command as an executable on PATH and spawns it directly with args as the argument vector. There is no shell". "On Windows, exec form requires command to resolve to a real executable such as a .exe. The .cmd and .bat shims... can't be spawned without a shell."
    • Failure semantics without Git Bash: "any exit code other than 0 or 2 from that hook counts as a failure, even when it prints JSON that doesn't deny the call." For guard hooks the docs suggest "onFailure": "block" and "shell": "powershell".
    • Git Bash discovery: CLAUDE_CODE_GIT_BASH_PATH (Windows only) points at bash.exe where it isn't found automatically.
    • Paths: a PreToolUse path "arrives with backslash separators, even when your hook runs under Git Bash".

    What the docs don't settle: Python as a hook on Windows. There is no mention of py, python3, or the WindowsApps alias. It's inferred, not documented, that exec form with "command": "py" works, since py.exe is a real binary. The docs also don't say how Git Bash is invoked (login or non-login), or whether the hook's PATH matches the launching terminal's.

    Implication for the fix: a registered launcher that doesn't depend on which shell is present would use exec form (command + args) pointing at a real interpreter .exe. It would not use a shell-form string that runs under Git Bash on one host and PowerShell on another. The change edits host-setup/agent-safety/claude/install.py, so it lands after #4317's PR merges, and its design goes to the maintainer for approval then.

  4. ptr727 commented on Nov 22, 2026

    @ptr727
    OwnerAuthor

    Maintainer's decision, 2026-11-22: exec form everywhere. The installer registers each hook in exec form on Linux, macOS, and Windows: command is the absolute path to a real interpreter executable, and args is [<hook path>]. No shell is involved, so it no longer matters whether Git Bash or PowerShell would run a shell-form string.

    • hook_command() emits the exec-form pair instead of the "<launcher>" "<path>" string.
    • registered_launcher and runs_hook read command and args directly when args is present, and fall back to the current shlex.split only for an older shell-form registration.
    • The installer rewrites an existing shell-form registration to exec form the next time it runs.
    • A test pins both readings: the exec form, and the shell-form fallback.

    #4317 is closed, so nothing blocks this. It is now work.

  5. ptr727 commented on Nov 22, 2026

    @ptr727
    OwnerAuthor

    Released (2026-11-22): the branch merged as #4350 and was cleaned up, so this claim holds no files.

    Backlog burndown claim (round 4, group 4, 2026-11-22): branch burndown/r4-hook-exec-form, issues #4040.

    Predicted files: host-setup/agent-safety/claude/install.py, host-setup/agent-safety/claude/test_install.py, host-setup/agent-safety/claude/README.md. Generated trees .github/skills/ and .claude-plugin/ follow any .agents/skills/ edit.

    Grown set granted (2026-11-22): host-setup/agent-safety/claude/tool-containment.py (module docstring only).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions