Two Windows defects in the claude install lane, both reported with repros
in #1902 (bili 0.1.179, Claude Code 2.1.284):
1. The SessionStart hook command carried the install-time node path with a
PowerShell-only leading '&' for spaced paths. Claude Code 2.1.284 runs
hooks through cmd.exe, which dies on the '&' ('& was unexpected at this
time.') — the lane silently never started. #1376 had probe-verified
PowerShell on 2.1.282, so no single spelling of a spaced command path
survives both client shells across versions. Root fix: emit a bare
'node' head (PATH-resolved by every client shell — claude's own npm shim
requires node on PATH), like the kimi hook already does. Existing
installs self-heal: refreshOurHookCommands rewrites our owned hook
commands on the next session-start repin or reinstall.
2. resolveClaudeCli took the raw first where.exe hit, which for npm global
installs is the extensionless POSIX shim — unspawnable by Node (ENOENT),
so MCP registration failed at install time. Hits are now ranked the way
cmd.exe resolves them: PATH order first, PATHEXT order within each
directory; no-match keeps the old first-hit behavior. A CLAUDE override
(the reporter's working bypass) still passes through untouched.
Behavior change (intended, disclosed): the emitted claude hook command goes
from '& "<abs node path>" <script>' / '<abs node path> <script>' to
'node <forward-slashed script>'. The absolute-path form also went away, so
a node binary moved after install can no longer strand the hook.
Tests: resolveClaudeCli gains the #1902 repro (extensionless-first npm dir)
plus PATH-vs-PATHEXT precedence pins; the installer round-trip now asserts
the emitted hook carries a bare 'node' head; hook-command.test.ts comments
updated to record both observed client shells. Typecheck + targeted suites
(hook-command, claude-native, kimi-native) green locally; Windows CI runs
the shell integration tests.
Real Windows machines (node under "Program Files", localized cmd errors,
existing USERPROFILE homes) exposed four CI-invisible test assumptions:
- discover: withHome now mirrors HOME into USERPROFILE on win32 so
os.homedir() resolves inside the sandbox instead of the real ~/.zcode
- doctor: withEnv mirrors HOME->USERPROFILE on win32 for the same reason
(real ~/.dsh profiles were leaking into sandboxed-home tests)
- hook-command: the "& spaced head" PowerShell call-operator form is no
longer demanded of cmd (production hooks resolve a bare node; cmd never
sees a spaced head)
- hermes: the missing-CLI assertion now matches the shared manual-enable
tail, since a Windows shell probe fails with a localized error instead
of ENOENT
Bare rmSync(dir, {recursive, force}) in test teardowns throws ENOTEMPTY on
loaded CI runners when a spawned child recreates entries between readdir and
rmdir (observed: issue1086-chain T3 on ubuntu-latest Node 22, run
36520549393). Node's rimraf only retries transient errors when maxRetries is
set, so a shared tests/tmp-rm.ts rmrf() with maxRetries:10/retryDelay:50 now
replaces all 354 bare recursive teardown calls across 91 test files, matching
the precedent already at issue1086-chain-self-exemption.test.ts:663. Orphaned
named rmSync imports dropped where no longer used. Test-only change.
isOursSessionStartEntry is how bili recognizes its own SessionStart hook on
uninstall/reinstall. The portable emitter can now produce a quoted trailing
argument (spaced install paths); pin the detector against every form it can
emit so the two cannot drift.
The SessionStart hook is the one place bili hands a client a SHELL STRING
rather than an argv array, so the client's own shell re-parses our path.
Two Windows shapes break it, both hit in the field on Claude Code 2.1.282:
1. Backslashes are escape-eaten by POSIX shells. `D:\Dev\node\node.exe`
loses `\D` and `\n` and becomes `D:Devnodenode.exe` — command not found.
The hook never starts the proxy while the client's base_url already
points at the fixed port, so the session HANGS on a dead origin instead
of failing loudly. Forward slashes are accepted by every shell we emit
for, so the fix is to forward-slash both the exe and its arguments.
2. Quoting the COMMAND token is not portable:
form bash PowerShell cmd
bare token ok ok ok
"quoted" first token ok PARSE ERR * ok
& "quoted" first token ERR ok ERR
*PowerShell reads a leading quoted token as a STRING EXPRESSION: with an
argument after it the whole command dies at parse time (`UnexpectedToken`,
taking the hook command with it) and on its own it exits 0 having run
nothing — a silent no-op, worse than an error.
No spelling covers a spaced command path in all three shells, so the only
question is which shell to keep working. Windows runs Claude Code's
SessionStart hooks through PowerShell — probe-verified: a cmd-only builtin
(`ver > file`) writes nothing while a PowerShell-only one
(`Write-Output ... > file`) writes its file, and a bash shell would have
created an EMPTY file rather than a populated one. So `&` is the form that
keeps the real hook path alive. cmd never sees a spaced command here: the
kimi hook resolves a bare `node` through PATH and so is never quoted.
Quoting an ARGUMENT is safe in all three shells and is kept for paths that
need it (a spaced temp dir or username is the common case).
Both call sites now share `portableHookCommand(exe, args)` — claude
(`process.execPath` + the bootstrap script) and kimi (`node` + the hook
script, previously built with `path.join`, which is the same bug via
backslashes).
Tests: tests/hook-command.test.ts pins the exact spelling AND runs the
produced command through every shell the platform actually has, so a fix that
only looks right on paper fails. tests/kimi-native.test.ts asserted
`endsWith(path.join(...))`, which pinned the backslash bug — it now asserts
the portable shape.
Full suite: 2659 tests, 2640 pass. The 11 failures are pre-existing on a
clean tree (identical names and counts).
Fixes#1376