Run the closeout fingerprint through sh
Problem and behavior
On Windows, the Claude Code Stop hook scripts/agent-closeout-check.py raised at the end of every turn instead of printing its once-per-tree reminder:
File "scripts\agent-closeout-check.py", line 48, in tree
OSError: [WinError 193] %1 is not a valid Win32 application.
tree() executed scripts/tree-fingerprint.sh directly, which Windows cannot do, and a checkout without the executable bit fails the same way. scripts/test.sh took the fingerprint its receipts are matched against the same way, so such a checkout wrote no receipt for the hook to match, and two tests in tests/test_agent_workflow_hooks.py executed a script directly too. With this change the hook computes the fingerprint and prints its reminder, the gate writes a receipt it can match, and the suite passes in such a checkout. The hook runs only under Claude Code with a working python3, so it stayed silent wherever python3 resolves to the Microsoft Store stub.
Approach
Every caller of scripts/tree-fingerprint.sh runs it through sh, as check-pr-text.py and commit-draft.py already run git-commit-msg.sh: tree() in the hook, the receipt_tree= line where scripts/test.sh takes the start tree, and the tests. The test that runs the hook as a process runs it through sys.executable, as .claude/settings.json runs it through python3. With no sh on PATH, as in a PowerShell session outside Git Bash, tree() still raises FileNotFoundError; the module docstring now says so instead of promising an exit status of 0. Claude Code runs the hook under Git Bash, where sh is present, so this change leaves that case alone.
Validation
- In a
python:3.12container (Linux 6.6, Python 3.12.16, git 2.47.3),test_the_closeout_check_runs_the_fingerprint_through_shandtest_the_start_tree_is_taken_without_the_executable_bitpass. Withshremoved fromtree(), the first fails withPermissionError: [Errno 13] Permission denied; with it removed from thereceipt_tree=line inscripts/test.sh, the second fails with'' != '8d3a0beb...'. - In the same container, with the executable bit removed from both
scripts/tree-fingerprint.shandscripts/agent-closeout-check.py, the previous head failedtest_a_directory_that_is_not_a_work_tree_has_no_fingerprintandtest_stop_hook_never_blocks_and_ignores_a_reentrant_stopwithPermissionError.scripts/run-python-tests.py tests/test_agent_workflow_hooks.py tests/test_gate_receipt.pynow runs 36 tests there, all passing. - On Windows 11 with Python 3.12.3, the hook test fails with WinError 193 without the fix, and
tests/test_agent_workflow_hooks.pynow passes in full, 14 tests. The receipt test passes on Windows either way, since Git Bash runs a script that starts with#!whatever its mode, so it is the Linux run above that shows it. Four other cases intests/test_gate_receipt.pyfail on Windows onmainas well and pass in the container. - The hook test loads its own copy of the module, as the receipt test above it does, because
scripts/run-python-tests.pyruns cases in parallel and other cases patchtreeon the shared one. A probe holding that patch in another thread failed the shared-module version and passes this one. - With the change in the working tree, the Stop hook in Claude Code on Windows stopped printing the traceback.
ruff format --checkandruff checkpass with ruff 0.15.2, the version CI pins;shfmt -d scripts/test.shis clean with shfmt 3.8.0, the version Ubuntu 24.04 ships to CI, andsh -n scripts/test.shparses.
Summary by cubic
Fixes the Claude Code Stop hook scripts/agent-closeout-check.py crashing at the end of every turn on Windows instead of printing its once-per-tree reminder.
The hook, scripts/test.sh, and the test helpers now run scripts/tree-fingerprint.sh through sh instead of executing it directly, which Windows cannot do and which also fails when a checkout lacks the executable bit. A checkout without the executable bit previously wrote no receipt to match, so scripts/test.sh and the stop hook now take their fingerprints the same way. Tests now invoke each script through its interpreter as well, and the hook's docstring notes it still raises with no sh on PATH. New regression tests cover both.