Skip to content

fix(claude-pty): Stop hook fails on Windows and on paths with spaces - #411

Open
Ivancheng7 wants to merge 1 commit into
xvirobotics:mainfrom
Ivancheng7:fix/pty-stop-hook-cross-platform
Open

Ivancheng7 wants to merge 1 commit into
xvirobotics:mainfrom
Ivancheng7:fix/pty-stop-hook-cross-platform

Conversation

@Ivancheng7

Copy link
Copy Markdown
Contributor

The PTY Stop hook command is generated as `cat > ${sentinelPath}` — an unquoted, POSIX-only snippet. That carries two independent defects.

1. Windows has no cat

PTY hook commands are executed by the host shell (cmd on 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, and install.ps1 ships 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 any TMPDIR with 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:

  • Windows → powershell.exe -NoProfile -NonInteractive -Command "Set-Content -LiteralPath '<path>' -Value stop -Encoding UTF8"
  • POSIX → cat > '<path>', single-quoted, with each shell's own single-quote escaping

The 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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant