Repository navigation
fix(claude): make managed hook paths portable (STA-3348) - #13442
Conversation
📝 WalkthroughWalkthroughThe change adds 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 17c4c612-805a-4f36-a047-572644c6736b
📥 Commits
Reviewing files that changed from the base of the PR and between 43fb9228cadae31f6964c5a197d8306d1ace75bd and d776f678d26a74e5a24f2239745f0b4fe52ae4c3.
📒 Files selected for processing (4)
config/scripts/verify-agent-hook-stdin-lifecycle.mjssrc/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/runtime-home-hook-command.tssrc/main/claude/hook-service.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/agent-hooks/runtime-home-hook-command.ts
- src/main/claude/hook-service.test.ts
- src/main/agent-hooks/installer-utils.test.ts
| const missingResult = await runShell( | ||
| rewriteLauncherScriptPath(command, missingPath), | ||
| command, | ||
| payload, | ||
| withoutOrcaEnvironment({ HOME: home }) | ||
| withoutOrcaEnvironment({ HOME: scratch }) | ||
| ) | ||
| assertSuccessfulWrite(missingResult, 'installed missing-script launcher') | ||
|
|
||
| const failingPath = join(scratch, 'failing-hook.sh') | ||
| const failingPath = join(scratch, '.orca', 'agent-hooks', 'claude-hook.sh') | ||
| mkdirSync(join(scratch, '.orca', 'agent-hooks'), { recursive: true }) | ||
| writeFileSync(failingPath, '#!/bin/sh\ncat >/dev/null\nexit 7\n', 'utf8') | ||
| chmodSync(failingPath, 0o755) | ||
| const failingResult = await runShell( | ||
| rewriteLauncherScriptPath(command, failingPath), | ||
| command, | ||
| payload, | ||
| withoutOrcaEnvironment({ HOME: home }) | ||
| withoutOrcaEnvironment({ HOME: scratch }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
verifier="config/scripts/verify-agent-hook-stdin-lifecycle.mjs"
if rg -n 'HOME:\s*scratch' "$verifier"; then
echo "The verifier passes a native scratch path directly as HOME." >&2
exit 1
fiRepository: stablyai/orca
Length of output: 315
🏁 Script executed:
#!/bin/bash
set -euo pipefail
verifier="config/scripts/verify-agent-hook-stdin-lifecycle.mjs"
echo "== outline relevant symbols =="
ast-grep outline "$verifier" --match runShell --view expanded || true
ast-grep outline "$verifier" --match withoutOrcaEnvironment --view expanded || true
echo
echo "== relevant source lines =="
sed -n '1,80p' "$verifier" | cat -n
echo
sed -n '310,360p' "$verifier" | cat -n
echo
echo "== runShell usages and definitions =="
rg -n "function runShell|const runShell|runShell\\(" "$verifier" -A 12 -B 6
echo
echo "== HOME slash normalization references in repo =="
rg -n "replaceAll\\('\\\\\\\\'|replaceAll\\(\"\\\\\\\\\"|mkdirSync \\|\\| mkdtempSync|HOME" config/scripts/verify-agent-hook-stdin-lifecycle.mjsRepository: stablyai/orca
Length of output: 10035
🏁 Script executed:
#!/bin/bash
set -euo pipefail
verifier="config/scripts/verify-agent-hook-stdin-lifecycle.mjs"
echo "== outline relevant symbols =="
ast-grep outline "$verifier" --match runShell --view expanded || true
ast-grep outline "$verifier" --match withoutOrcaEnvironment --view expanded || true
echo
echo "== relevant source lines =="
sed -n '1,80p' "$verifier" | cat -n
echo
sed -n '310,360p' "$verifier" | cat -n
echo
echo "== runShell contexts and definitions =="
rg -n "function runShell|const runShell|runShell\\(" "$verifier" -A 12 -B 6
echo
echo "== HOME normalization references in verifier =="
rg -n "replaceAll\\('\\\\\\\\'|replaceAll\\(\"\\\\\\\\\"|mkdirSync \\|\\| mkdtempSync|HOME" "$verifier"Repository: stablyai/orca
Length of output: 10035
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== shell path separator behavior =="
{
mkdir -p /tmp/sh-ws
mkdir -p "/tmp/sh-ws/with-dir"
echo "exit 7" > /tmp/sh-ws/with-dir/check-hook.sh
chmod +x /tmp/sh-ws/with-dir/check-hook.sh
printf 'forward slashes on Unix with file /bin/sh -c '\''"$HOME/check-hook.sh"'\''\n'
HOME=/tmp/sh-ws/with-dir /bin/sh -c '"$HOME/check-hook.sh"'
printf 'status: %d\n' "$?"
printf 'native backslash path on Unix with file /bin/sh -c '\''"$HOME/check-hook.sh"'\''\n'
HOME='/tmp/sh-ws\with-dir' /bin/sh -c '"$HOME/check-hook.sh"'
printf 'status: %d\n' "$?"
} | { sed -n '1,80p'; true; }
echo
echo "== check if WSL /bin/sh maps backslashes =="
if [ -x /bin/sh ]; then
str='$HOME/check-hook.sh'
printf 'shell arg with backslash: '
/bin/sh -c 'printf "%s\n" %s' "$str"
fi
echo
echo "== Node shell spawning from scratch with backslashes =="
node - <<'JS'
if (process.platform === 'win32') process.exit(0)
const { spawnSync } = require('node:child_process')
const { mkdirSync, mkdtempSync } = require('node:fs')
const scratch = '/tmp/sh-ws/with-dir'
mkdirSync(scratch, {_recursive:true})
const path = scratch + '/check-hook.sh'
require('fs').writeFileSync(path, '#!/bin/sh\nexit 7\n')
require('fs').chmodSync(path, 0o755)
for (const home of [scratch, '/tmp/sh-ws\\with-dir']) {
const r = spawnSync('/bin/sh', ['-c', '"$HOME/check-hook.sh"'], {
env: {...process.env, HOME: home},
encoding: 'utf8'
} )
console.log(JSON.stringify({home, status:r.status, stdout:r.stdout, stderr:r.stderr}))
}
JSRepository: stablyai/orca
Length of output: 256
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Node shell spawning from Unix scratch =="
node - <<'JS'
if (process.platform === 'win32') {
console.log(JSON.stringify({ platform: process.platform }))
process.exit(0)
}
const { spawnSync } = require('node:child_process')
const scratch = '/tmp/sh-ws/with-dir'
const path = scratch + '/check-hook.sh'
require('fs').writeFileSync(path, '#!/bin/sh\nexit 7\n')
require('fs').chmodSync(path, 0o755)
for (const home of [scratch, '/tmp/sh-ws\\with-dir']) {
const r = spawnSync('/bin/sh', ['-c', '"$HOME/check-hook.sh"'], {
env: {...process.env, HOME: home},
encoding: 'utf8'
})
console.log(JSON.stringify({home, status:r.status, stdout:r.stdout, stderr:r.stderr}))
}
JS
echo
echo "== WSL /bin/sh command argument representation with backslash =="
WAS_OK=$?
bash -c 'str=/"$HOME/check-hook.sh"; printf "%q\n" "$str"' || trueRepository: stablyai/orca
Length of output: 506
Normalize the shell HOME path on Windows.
mkdtempSync can return a native Windows path that spawn('/bin/sh', ...) passes as HOME. With backslashes, the installed launcher resolves "$HOME/.orca/agent-hooks/claude-hook.sh" as a non-existent path, falls back through command -p cat, and the expected exit code 7 check no longer exercises the failing hook.
Use a slash-normalized HOME for both shell invocations while keeping scratch unchanged for filesystem operations.
Windows low-spec Electron QA — STA-3348 / PR #13442 — PASSEnvironment
Steps
Result — PASSManaged Claude hooks were rewritten from absolute Before (bug): After (fix, prefix): Portability probe: bash_exit=0 ` Notes
Evidence
|
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
1 similar comment
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
f4e8e2f to
1de2d6f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 18e27810-6976-47a9-b922-2c867f2106b6
📥 Commits
Reviewing files that changed from the base of the PR and between f4e8e2fd01e6115686ef594f9d130b2273e31318 and 1de2d6f.
📒 Files selected for processing (5)
src/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/installer-utils.tssrc/main/claude/hook-service.test.tssrc/main/claude/hook-service.tssrc/main/claude/hook-settings.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/main/agent-hooks/installer-utils.ts
- src/main/claude/hook-service.ts
- src/main/agent-hooks/installer-utils.test.ts
- src/main/claude/hook-service.test.ts
| export function getWindowsManagedLifecycleHook(scriptPath: string): HookCommandConfig { | ||
| const system32 = win32.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32') | ||
| let clientArgs = [win32.join(system32, 'cmd.exe'), '/d', '/c', scriptPath] | ||
| if (WINDOWS_CMD_ARGUMENT_META.test(scriptPath)) { | ||
| const encodedCommand = wrapWindowsHookCommand(scriptPath).match(/ -EncodedCommand (\S+)$/)?.[1] | ||
| if (!encodedCommand) { | ||
| throw new Error('Failed to encode managed Claude hook path') | ||
| } | ||
| clientArgs = [ | ||
| win32.join(system32, 'WindowsPowerShell', 'v1.0', 'powershell.exe'), | ||
| '-NoProfile', | ||
| '-ExecutionPolicy', | ||
| 'Bypass', | ||
| '-EncodedCommand', | ||
| encodedCommand | ||
| ] | ||
| } | ||
| const runtimeScriptPath = win32.join( | ||
| '%USERPROFILE%', | ||
| '.orca', | ||
| 'agent-hooks', | ||
| win32.basename(scriptPath) | ||
| ) | ||
| // Why: Claude's Windows shell form opens Git Bash consoles; exec form hosts the client in a windowless console. | ||
| return { | ||
| type: 'command', | ||
| command: win32.join(system32, 'conhost.exe'), | ||
| args: ['--headless', ...clientArgs], | ||
| args: ['--headless', win32.join(system32, 'cmd.exe'), '/d', '/c', runtimeScriptPath], | ||
| timeout: MANAGED_HOOK_TIMEOUT_SECONDS |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Preserve the runtime launcher fallback in the Windows exec path.
cmd.exe /c parses runtimeScriptPath as a command after %USERPROFILE% expands. A profile path with spaces can fail because the path is not quoted. A missing script also returns a cmd.exe error instead of draining stdin and exiting successfully.
Generate an exec-form command that tests the runtime path, invokes the .cmd file in quotes, drains stdin when the file is unavailable, and preserves the invoked script exit code. The PR objective requires Windows paths with spaces and shell metacharacters to work.
) * fix(claude): make managed hook paths portable * perf(claude): keep portable hooks shell-native --------- Co-authored-by: Brennan Benson <[email protected]>

Summary
.cmdversus.shfrom the executing shell so synced settings work across Windows, macOS, Linux, SSH, and folder workspacesWindows evidence
HOMETests
pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/installer-utils.test.ts -t "wrapRuntimeHomeHookCommand" --maxWorkers=1 --reporter=dotpnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/installer-utils.test.ts src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts src/main/claude/hook-service.test.ts --maxWorkers=1 --reporter=dotpnpm run typecheck:nodepnpm run typecheck:clioxlintandoxfmt --checkpnpm run check:max-lines-ratchetFixes #12391