You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Settle Which Shell Runs a Claude Code Hook on Native Windows Before Changing How registered_launcher Splits a Command #4040
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.
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.
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.
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.
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).
Activity
Refuse a Malformed Launcher Probe and Check the Wrapper Probe's Exit …
ptr727 commentedon Nov 22, 2026
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_launcherchange. It lands in a round after #4317's PR merges, since both edithost-setup/agent-safety/claude/install.py.ptr727 commentedon Nov 22, 2026
Research result, 2026-11-22: which shell runs a Claude Code hook on Windows (from Anthropic's Claude Code docs; read-only).
args): per https://code.claude.com/docs/en/hooks.md, "Thecommandstring is passed to a shell:sh -con macOS and Linux, Git Bash on Windows, or PowerShell when Git Bash isn't installed. Set theshellfield to choose explicitly." The docs never namecmd.exefor hooks.shellfield: "Accepts"bash"or"powershell". Defaults to"bash", or to"powershell"on Windows when Git Bash isn't installed... Ignored whenargsis set."args): "Claude Code resolvescommandas an executable onPATHand spawns it directly withargsas the argument vector. There is no shell". "On Windows, exec form requirescommandto resolve to a real executable such as a.exe. The.cmdand.batshims... can't be spawned without a shell.""onFailure": "block"and"shell": "powershell".CLAUDE_CODE_GIT_BASH_PATH(Windows only) points atbash.exewhere it isn't found automatically.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, sincepy.exeis a real binary. The docs also don't say how Git Bash is invoked (login or non-login), or whether the hook'sPATHmatches 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 editshost-setup/agent-safety/claude/install.py, so it lands after #4317's PR merges, and its design goes to the maintainer for approval then.ptr727 commentedon Nov 22, 2026
Maintainer's decision, 2026-11-22: exec form everywhere. The installer registers each hook in exec form on Linux, macOS, and Windows:
commandis the absolute path to a real interpreter executable, andargsis[<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_launcherandruns_hookreadcommandandargsdirectly whenargsis present, and fall back to the currentshlex.splitonly for an older shell-form registration.#4317 is closed, so nothing blocks this. It is now work.
ptr727 commentedon Nov 22, 2026
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).Correct Two Statements the Exec-Form Change Left Inexact
Quote the Absolute Launcher in the Install Re-Check Hint
Keep a Venv's Own Interpreter as the Launcher of Last Resort
Require a Command in an Exec-Form Hook Registration
Say That names_hook Matches an Exec-Form Word by Its Own File Name
Read Only a -c Argument as Shell Code When Naming an Exec-Form Hook
Name an Exec-Form Hook Only by the File It Runs
Say What an Absolute Launcher Path Does and Does Not Pin
Register Claude Code Hooks in Exec Form and Rewrite Shell-Form Regist…