fix(claude-pty): Stop hook fails on Windows and on paths with spaces - #411
Open
Ivancheng7 wants to merge 1 commit into
Open
Ivancheng7 wants to merge 1 commit into
Ivancheng7 wants to merge 1 commit into
Conversation
The Stop hook command was generated as `cat > ${sentinelPath}` — an unquoted,
POSIX-only snippet:
- Windows has no `cat`, and hook commands are executed by `cmd` there. The
command fails, the sentinel file is never written, and the PTY watcher
waits forever for a turn that already completed — the reply never reaches
the chat.
- The path was interpolated without quoting, so any temp directory containing
a space (`C:\Temp Folder`, or a POSIX TMPDIR with a space) pointed the
redirect at the wrong target, and shell metacharacters in the path would be
interpreted.
Generate the command per-platform instead: PowerShell `Set-Content -LiteralPath`
on Windows, quoted `cat >` elsewhere, with each shell's own single-quote escaping.
The hook payload arrives on stdin but is not needed — the watcher only observes
that the sentinel changed.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PTY
Stophook command is generated as`cat > ${sentinelPath}`— an unquoted, POSIX-only snippet. That carries two independent defects.1. Windows has no
catPTY hook commands are executed by the host shell (
cmdon Windows). The command fails there, so the sentinel file is never written. The watcher in this same module then keeps waiting for a turn that has already completed, and the reply never reaches the chat — a stuck "working" card with no output. This affects any Windows deployment, andinstall.ps1ships one.2. The path is interpolated without quoting
The sentinel lives under the OS temp dir (
os.tmpdir()), which routinely contains a space —C:\Temp Folder\...on Windows, and anyTMPDIRwith a space on POSIX. The redirect then targets a different path, and shell metacharacters in the path would be interpreted rather than passed through. This one breaks Linux/macOS too.Fix
Generate the command per platform:
powershell.exe -NoProfile -NonInteractive -Command "Set-Content -LiteralPath '<path>' -Value stop -Encoding UTF8"cat > '<path>', single-quoted, with each shell's own single-quote escapingThe hook's JSON payload still arrives on stdin and is not consumed; the watcher only needs the sentinel to change, so the payload contents are not required.
Tests
tests/pty-stop-hook-command.test.ts(new) covers per-OS command selection, quoting of a path containing a space, and single-quote escaping for both shells — 4 tests, passing.Note
The POSIX branch is the one exercised in a production Linux deployment; the Windows branch is covered by the unit tests above rather than by a live Windows run.