Repository navigation
Description
Summary
Every shell-form hook row (no args key) is passed to a shell before its own interpreter starts: sh -c on macOS and Linux, Git Bash on Windows (hooks doc, "Exec form and shell form"). Exec form (an args array, even empty) spawns the executable directly with no shell and substitutes ${CLAUDE_PLUGIN_ROOT} into command and each args element as plain strings. On this fleet 51 of the 52 always-on rows measured by the hook-performance program are shell form; only context-budget's node row is exec form. That row was the cheapest per-tool-call hook in the final run (81 ms against 1,360 ms and up for the bash-scripted rows), though it also does the least work, so the shell spawn's share is unmeasured.
Why it is bigger than the shebang hop (#3684)
Two spawns disappear per fire, not one: the Git Bash bash.exe that shell form starts, and the env the shebang adds. A peer session's host measurement adds a third cost: C:\Program Files\Git\usr\bin\bash.exe carries a signer certificate that expired 2026-05-05 and msys-2.0.dll is unsigned, and Microsoft documents that Defender real-time protection scans every launch of an unsigned binary (learn.microsoft.com, defender-endpoint troubleshoot-performance-issues). That fits the steady MsMpEng share the peer observed; exec form on a signed interpreter avoids the scan too. The machine-side remedy (a Defender performance recording, then a narrow process exclusion or a Git for Windows update with a re-signed bash) is outside this repo.
What blocks it
The hook-performance program deferred exec form on purpose (its constraint 8): upstream anthropics/claude-code#90495, open, last updated 2026-08-29, reports that on Windows exec-form args are dropped and the hook is still routed through bash.exe, crashing on stdin. The program's phase 3 live probe under claude --debug-file did show the context-budget exec-form row firing and returning ask on this host, which is one data point against the bug reproducing here, but it never exercised a bash-scripted hook in exec form.
Ask
- A live probe on this Windows host: one throwaway hook row in exec form (
"command": "bash", "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/x.sh"]) underclaude --debug-file, confirming the args arrive and the script reads its stdin payload. That decides whether #90495 applies. - If it works: a paired fan-out harness run (
--runs 3, one host) on a representative row set, then a fleet sweep ofhooks.jsoncommands to exec form, one plugin per PR, every touched plugin bumped. Rows that need shell features (pipes,&&) stay shell form. The harness itself must learn to spawn exec-form rows the way Claude Code does, or its numbers will not reflect the change. - If #90495 reproduces: subscribe to it and keep this issue open as the tracker.
Related
- Invoke hook scripts through bash to skip the env shebang hop on every fire #3684 (the
envshebang hop; subsumed by exec form on any row that adopts it) - guardrails dispatcher is the whole per-tool-call budget miss after the hook-performance program #3685 (guardrails dispatcher; its row is the single largest beneficiary)
- Hook performance program: measure and cut every runtime-cost surface on the Windows host #3623 (program tracking issue)
Activity
kyle-sexton commentedon Sep 3, 2026
Live exec-form probe, as requested. Result: on this host, exec form works for bash-scripted rows, including a bare
bashcommand name, with args intact and the JSON payload delivered on stdin. anthropics/claude-code#90495 did not reproduce.Host: melo-lap-001 class (Windows 11 Pro 26200), Claude Code 2.1.259, Git for Windows 2.55.0.3 (bash 5.3.15), WSL 2 installed (so
System32\bash.exeexists on PATH as a competing resolution target).Setup: a throwaway directory with no project settings; hooks supplied via
--settings <file>so nothing touched a plugin row. Three PreToolUseBashhandlers pointing at the same probe script, which reads fd 0 with a barecat(not/dev/stdin, which MSYS cannot resolve for a Win32 pipe) and writes a marker file:{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "C:\\Program Files\\Git\\usr\\bin\\bash.exe", "args": ["<abs>/probe-hook.sh", "fullpath"], "timeout": 20 }, { "type": "command", "command": "bash", "args": ["<abs>/probe-hook.sh", "bare"], "timeout": 20 }, { "type": "command", "command": "bash \"<abs>/probe-hook.sh\" shellform", "timeout": 20 } ] } ] } }Run:
claude -p 'Run exactly this bash command and reply with its output: echo probe-ok' --model sonnet --settings <file> --debug-file <file>. Two runs; identical outcome both times.Markers (all three written, every run):
fullpathbashbareshellformThe 540-byte stdin payload was the normal PreToolUse JSON (
session_id,transcript_path,cwd,tool_name,tool_input, ...). The barebashrow resolved to Git Bash, not the WSL relay:unamereports MINGW64 and the process image is the MSYS one. Each hook exited 0 and the tool call proceeded (probe-okprinted).Debug file: it records
if-gated skips (Skipping hook due to if condition "Bash(*hygiene.py*)" not matching, etc.) and acompleted with status 0line for the SessionEnd command hook, but no per-hook completion line for these PreToolUse handlers, so the markers are the evidence of execution rather than the log. No error, timeout, or stdin-related line appears anywhere in either debug file.What this does and does not show: two bash-scripted exec-form rows, one with an absolute image path and one relying on PATH resolution of
bash, fired correctly with args and stdin on 2.1.259 with WSL present. It does not cover${CLAUDE_PLUGIN_ROOT}expansion insideargs(the probe used literal absolute paths) or the fleet's hook-utils stdin buffering; those are the next things a plugin-row conversion should check.kyle-sexton commentedon Sep 3, 2026
Thank you; that clears gate 1 for bare
bashon this host (2.1.259, WSL present). Two things still stand between the probe and a fleet sweep, so the issue stays open and unassigned rather than moving to a PR: (1)${CLAUDE_PLUGIN_ROOT}expansion insideargsis untested, and every plugin row depends on it; the doc says it is substituted as a plain string, so one more marker probe withargs: ["${CLAUDE_PLUGIN_ROOT}/hooks/x.sh"]under a real plugin install (a throwaway local marketplace or a fork of one small plugin) decides it. (2) The fan-out harness spawns rows the way shell form does; before any before-and-after number is trusted the harness needs an exec-form branch that readsargsand spawns without a shell, otherwise the sweep measures nothing. The guardrails dispatcher row (#3685) is the first candidate once both are in hand.kyle-sexton commentedon Sep 3, 2026
Gate 2 probe:
${CLAUDE_PLUGIN_ROOT}substitution inside exec-formargsunder a real plugin load. Same host and Claude Code 2.1.259 as the previous comment; the plugin was a throwaway loaded with--plugin-dir <dir>(its own.claude-plugin/plugin.jsonandhooks/hooks.json), so the substitution path is the plugin one, not--settings.Three PreToolUse
Bashrows on the same probe script:CLAUDE_PLUGIN_ROOTin env"command": "bash", "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/probe.sh", "args-pluginroot"]C:\Users\<user>\...\plugin/hooks/probe.shC:\Users\<user>\...\plugin"command": "${CLAUDE_PLUGIN_ROOT}/hooks/probe.sh", "args": ["command-pluginroot"]bash "${CLAUDE_PLUGIN_ROOT}/hooks/probe.sh" shellform-pluginrootC:/Users/<user>/.../plugin/hooks/probe.shC:/Users/<user>/.../pluginSo the sweep pattern that works is
"command": "bash"with the script path inargs; substitution happens before spawn and the payload arrives on fd 0. Putting the script itself incommanddoes not work in exec form on Windows: there is no shell to honour the shebang, and the spawn fails at the libuv layer. Exact stderr Claude Code recorded (surfaced by the claude-ops Stop hook as a failure record forPreToolUse:Bash [${CLAUDE_PLUGIN_ROOT}/hooks/probe.sh command-pluginroot]):Failed to run: EFTYPE: inappropriate file type or format, uv_spawn, exit 1. The tool call itself proceeded, so this failure mode is silent unless something audits hook exits.One difference worth carrying into the sweep: in exec form the substituted root uses backslashes (
C:\Users\...\pluginplus the row's own/hooks/...suffix), while shell form hands the script a forward-slash root. MSYS bash resolves the mixed form for$0and for${BASH_SOURCE[0]%/*}, so the probe ran, but any hook that comparesCLAUDE_PLUGIN_ROOTtextually, feeds it to a regex, or strips with a backslash pattern will see a different string than it sees today. Worth a grep acrosshooks/before converting a row.kyle-sexton commentedon Sep 3, 2026
Gate 3: the dotfiles harness now has an exec-form branch, and here is a first before-and-after through it.
Harness change: melodic-software/dotfiles#628 (branch
perf/hook-fanout-exec-form).hook_rowsreads the form off each hooks.json row (exec whenargsis present, an empty array included),resolve_execrebuilds the argument vector with${CLAUDE_PLUGIN_ROOT}substituted, andtime_commandletstimeoutexec the program directly instead ofbash -c. Such rows report asRAN(exec). 56/56 harness assertions pass, 13 of them new.Measurement: laptop under five-session load, both runs valid (spawn floor S = 20 ms before, 19 ms after),
--runs 3. The installed eol-normalizer (shell form) versus a copy whose single row was rewritten to"command": "bash", "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/eol-normalizer.sh"], measured through--plugin-root eol-normalizer=<copy>on the same event set:Medians move 96 ms and 237 ms in the expected direction (one fewer bash spawn plus the
envshebang hop), but three samples per row with this spread is not a sweep-grade number;--runshigher and an interleaved pair of runs would be, and the harness now supports both. Everything else in the two reports is the fleet's existing shell-form baseline and matches the earlier capture.Sweep pattern confirmed across gates 1-3:
"command": "bash"(bare, resolves to Git Bash with WSL present) with the script path inargs,${CLAUDE_PLUGIN_ROOT}substituted before spawn, JSON on fd 0, and a backslash root in the substituted path and in the exported variable. Script-as-commandfails withEFTYPE ... uv_spawnand should not be used.kyle-sexton commentedon Sep 4, 2026
Correction: the sweep pattern this issue's gate probes recommended is one this repo already bans
I need to retract the conclusion in my gate 2 and gate 3 comments above. They state that the sweep pattern is
"command": "bash"with the script path inargs. That shape is empirically correct on this host, and it is also the exact shapescripts/check-hook-exec-form.shexists to reject. I found this by writing the guardrails conversion and running the repo's own gates against it.All four guardrails rows fail.
EXEC_NAME_ALLOWLISTis(node).That gate is not a stylistic preference. Its doc-block records the defect class shipping three times (#1006 fixed it, #1504 reintroduced it, #2570 fixed it again) and cites #1416, where the disk-hygiene destructive guard logged 73 runs that were every one a
hook_non_blocking_errorwhile the guard was believed live. A failed hook launch is non-blocking, so a PreToolUse guard wired to a name that does not resolve silently enforces nothing.The specific hazard it names is the one my probe host cannot see. On Windows a bare
bashresolves to the WSL relay atSystem32\bash.exe. My gate 1 comment reported that barebashworks here and explicitly noted WSL is installed, which is precisely the condition that makes the relay succeed instead of failing. A fleet host without a distro providing/bin/bashgetsexecvpe(/bin/bash) failed, and the guard goes quiet rather than erroring visibly. I proved the pattern on the one configuration where the bug is invisible and generalised from it.Both branches are closed for a bash-scripted row
commandshapecheck-hook-exec-form.sh?bash(bare), script inargs${CLAUDE_PLUGIN_ROOT}/hooks/probe.sh, args afterEFTYPE: inappropriate file type or format, uv_spawnbash.exeThe middle row is the one recorded in the gate 2 table above: exec form has no shell to honour the shebang, so libuv refuses to spawn a text file. So there is no shape that is both launchable on Windows and acceptable to the gate, unless a row's interpreter is already an allowlisted executable such as
node. That is exactly why context-budget'snoderow is the one exec-form row in the fleet, and it explains the single data point the program had.What this means for the sweep
Ask item 2 should not proceed for bash-scripted rows as written. Options, none of them free:
nodetoday, and it retires most of the projected benefit, since the expensive rows are the bash dispatchers.bashstops meaning the WSL relay. This is a change to the gate's contract and should be argued on its own issue, not smuggled in through a sweep.nodeentrypoint that execs the guards would clear the gate, but that is a rewrite rather than a config change.I am not opening a guardrails PR. The branch I built to test this is discarded. Gates 1 through 3 stand as measurements; it is their conclusion that was wrong, and the fleet-sweep instruction in this issue should be treated as blocked until one of the options above is chosen.
kyle-sexton commentedon Sep 4, 2026
Filed #3708 for option 2 from my correction above: the gate-contract question of whether there can be a Windows-safe, gate-legal way to name Git Bash. That issue carries the two closed branches, the honestly-scoped payoff (roughly 100-240 ms per fire on the eol-normalizer rows, and nothing off the guardrails body cost), and four candidate directions each with its objection, including why the userConfig route runs into
check-hook-userconfig-argv.sh.This issue's sweep stays blocked until #3708 is decided. Nothing else needed here.
perf(guardrails): drop leftover git probes on a benign Bash call (#3820)
perf(hooks): fuse stdin jq completeness with field extract (#3838)
kyle-sexton commentedon Sep 23, 2026
This was generated by AI during triage.
Blocked by #3708 decision. This item waits on the decision tracked in #3708; resolving it there unblocks this one.
19 remaining items
chore(hooks): merge main into the launcher fix branch
ci: re-pin gitleaks composite, extend the Windows lane, wire unwired …
docs(guardrails): declare and probe node; setup apply follows the rec…
kyle-sexton commentedon Sep 29, 2026
Owner decision (2026-09-29): Run the paired A/B hook fan-out measurement once on melo-lap-001, informational only (it feeds the k and S figures in docs/conventions/hook-budget/README.md and is not a revert gate), then close this issue. The credentialed CI lane (making the Windows live probe a required lane) is decided as a separate item.
Next: the owner runs the Windows steps in sections 3 and 4 above (A/B for eol-normalizer, typos-format and guardrails; the live probe; the skill-frontmatter probe; the CLAUDE_PLUGIN_ROOT textual-compare check) and posts the medians and S per arm. An agent then pastes them into the hook-budget convention and closes this issue. It keeps needs-human until then.
fix(hooks): resolve bash from PATH in the exec-form launcher and name…
docs(guardrails): date exec form to 0.41.3 and probe the launcher's bash
test(guardrails): accept the PATH bash in the launcher tests
fix(guardrails): judge more shell shapes, declare node, correct docs (#…
kyle-sexton commentedon Oct 1, 2026
Owner decision (2026-10-01): approved the recommendation ("go with recommended", the owner's reply to the batch decision page that listed this question and its recommendation).
Question: can an agent run the section 3 A/B part over ssh instead of the owner doing every Windows step?
Chosen option A: an agent runs the paired A/B through /fleet:reach windows-shell on melo-lap-001 while it is on AC and idle, for eol-normalizer, typos-format and guardrails in the order A,B,A,B,A,B with --runs 3, discarding any INVALID RUN (S over 160 ms). It opens a PR adding the medians and S per arm to docs/conventions/hook-budget/README.md with
Refs #3686. The section 4 checks that need a signed-in console session (the EXEC_FORM_WINDOWS_PROBE_LIVE probe, the skill-frontmatter probe, the CLAUDE_PLUGIN_ROOT textual-compare check) move to one new needs-human issue. #3686 then closes. This supersedes the 2026-09-29 "owner runs every step" wording.Next: an agent confirms melo-lap-001 is on AC and idle, runs the A/B, opens the draft PR, files the section 4 follow-up issue, and closes this issue. Labels now: needs-human removed, agent-ready added.
kyle-sexton commentedon Oct 1, 2026
The paired A/B ran on melo-lap-001 on 2026-10-01, following the owner decision of that day. The laptop was on AC and idle, and the agent reached it through
/fleet:reach. The harness ran in Git Bash as the console account, from the Windows dotfiles checkout, with--runs 3.b7c8a6221, and onlyhooks/hooks.jsondiffers between them.The launcher costs about 1 to 3 S per fire. Per-row medians, raw runs and method are in draft PR #5691, which records them in
docs/conventions/hook-budget/README.md(Refs: #3686).The section 4 checks that need a signed-in console session are in #5692 (
needs-human):EXEC_FORM_WINDOWS_PROBE_LIVEprobe;CLAUDE_PLUGIN_ROOTtextual-compare check.Closing as completed, per the decision.
docs(hook-budget): state the S divisor in the launcher A/B table
docs(hook-budget): record the paired node-launcher A/B from melo-lap-…