Skip to content

fix(claude): make managed hook paths portable (STA-3348) - #13442

Merged
brennanb2025 merged 2 commits into
stablyai:mainfrom
OrcaWin:OrcaWin/sta-3348-windows-repro
Aug 11, 2026
Merged

brennanb2025 merged 2 commits into
stablyai:mainfrom
OrcaWin:OrcaWin/sta-3348-windows-repro

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • resolve managed Claude and OpenClaude hook commands from the destination runtime HOME instead of the installer profile
  • select .cmd versus .sh from the executing shell so synced settings work across Windows, macOS, Linux, SSH, and folder workspaces
  • preserve stdin draining and exit propagation without adding a platform-probe process to each hook

Windows evidence

  • Git Bash tests execute the destination profile hook while a stale source-profile hook exists
  • tests cover the direct path for ordinary, spaced, and non-ASCII profiles, the encoded fallback for cmd metacharacters, and an empty HOME
  • no UI changed; Electron/CDP validation was not applicable

Tests

  • pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/installer-utils.test.ts -t "wrapRuntimeHomeHookCommand" --maxWorkers=1 --reporter=dot
  • pnpm 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=dot
  • pnpm run typecheck:node
  • pnpm run typecheck:cli
  • targeted oxlint and oxfmt --check
  • pnpm run check:max-lines-ratchet

Fixes #12391

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds wrapRuntimeHomeHookCommand to the CLI TypeScript project. The wrapper validates script names, resolves HOME at runtime, selects Windows or POSIX execution, and drains stdin when execution is unavailable. Managed local and remote Claude commands now use this wrapper. Tests cover runtime selection, portable paths, Windows behavior, remote commands, statuslines, and stdin lifecycle behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change and tests but omits the required AI Review Report and Security Audit sections. Add the required AI Review Report and Security Audit sections, and explicitly address screenshots or state that there is no visual change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: making Claude managed hook paths portable.
Linked Issues check ✅ Passed The changes replace installer-profile paths with runtime HOME resolution and preserve cross-platform hook behavior required by issue #12391.
Out of Scope Changes check ✅ Passed The source, test, configuration, and verification changes are related to portable managed hook paths and their required behavior.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mjs
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/runtime-home-hook-command.ts
  • src/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

Comment on lines 331 to +345
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 })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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
fi

Repository: 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.mjs

Repository: 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}))
}
JS

Repository: 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"' || true

Repository: 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.

@OrcaWin

OrcaWin commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Windows low-spec Electron QA — STA-3348 / PR #13442 — PASS

Environment

  • OS: Microsoft Windows NT 10.0.26200.0
  • Host: ~15.9 GiB RAM, 8 logical processors (low-spec)
  • Node: v24.18.0
  • Checkout: OrcaWin/sta-3348-windows-repro @ d776f678d26a74e5a24f2239745f0b4fe52ae4c3
  • Worktree: C:\Users\neil\orca\workspaces\orca\sta-3348-windows-repro
  • Method: `` / playwright-cli CDP only (no Computer Use, no OS UI automation)
  • CDP: http://127.0.0.1:9333 · isolated ORCA_DEV_USER_DATA_PATH

Steps

  1. Fetched/checked out exact PR head d776f678d2 on branch OrcaWin/sta-3348-windows-repro.
  2. Backed up existing %USERPROFILE%\.claude\settings.json (hardcoded absolute paths).
  3. Launched worktree dev build via node config/scripts/run-electron-vite-dev.mjs with REMOTE_DEBUGGING_PORT=9333.
  4. Attached playwright-cli; confirmed identity Orca: OrcaWin/sta-3348-windows-repro / isDev:true / correct repo root.
  5. After startup hook reconciliation, re-read Claude settings and ran a Git Bash portability probe (file-existence only).

Result — PASS

Managed Claude hooks were rewritten from absolute C:/Users/neil/... paths to runtime-C:\Users\neil + OSTYPE selection of .cmd vs .sh.

Before (bug):
sh if [ -f 'C:/Users/neil/.orca/agent-hooks/claude-hook.cmd' ]; then 'C:/Users/neil/.orca/agent-hooks/claude-hook.cmd'; else { command -p cat 2>/dev/null || cat; } >/dev/null 2>&1 || :; fi

After (fix, prefix):
sh if [ -z "${HOME-}" ]; then { command -p cat 2>/dev/null || cat; } >/dev/null 2>&1 || :; else case "${OSTYPE-}" in msys*|cygwin*|win32*) if [ -f "$HOME/.orca/agent-hooks/claude-hook.cmd" ]; then case "$HOME" in *\&*|*\^*|*\(*|*\)*|*\;*|*,*|*=*|*%*|*\!*) if [ -f "$SYSTEMROOT/System32/WindowsPowerShell/v1.0/powershell.exe" ]; then "$SYSTEMROOT/System32/WindowsPowerShell/v1.0/powershell.exe" -NoProfile -ExecutionPolicy Bypass -EncodedCommand JABoAG8AbQBlAFAAYQB0AGgAIAA9ACAAJABlAG4AdgA6AEgATwBNAEUAIA…

Portability probe:
` ext
managed_command_len=1642
uses_home=true
uses_ostype=true
uses_cmd=true
uses_sh=true
hardcoded_neil=false
hardcoded_users=false
bash_home=/c/Users/neil
portable_home_guard=found:/c/Users/neil/.orca/agent-hooks/claude-hook.cmd
installed_literal_guard=found:C:/Users/neil/.orca/agent-hooks/claude-hook.cmd
origin_profile=absent
copied_literal_guard=missing:C:/Users/orca-sta3348-origin-profile/.orca/agent-hooks/claude-hook.cmd
alt_home_guard=found:/tmp/sta3348-dest.UWSu3g/.orca/agent-hooks/claude-hook.cmd
alt_home_exec_path_ok=yes
stale_absolute_still_points_to_origin=yes

bash_exit=0

`

Notes

  • No product UI renders the hook command string; the user-visible surface is the installed Claude settings entry + hook script under ~/.orca/agent-hooks/.
  • Empty-workspace shell screenshot proves the PR-head Electron app launched and was the attached CDP target (isolated profile → no workspaces).
  • User-owned statusLine (~/.claude/ccline/ccline) was left intact.
  • No product code was modified in this QA pass.

Evidence

PR-head Orca window (Windows)

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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.

@brennanb2025
brennanb2025 force-pushed the OrcaWin/sta-3348-windows-repro branch from f4e8e2f to 1de2d6f Compare August 11, 2026 20:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/claude/hook-service.test.ts
  • src/main/claude/hook-service.ts
  • src/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

Comment on lines 129 to 142
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@brennanb2025
brennanb2025 merged commit f226fcf into stablyai:main Aug 11, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* fix(claude): make managed hook paths portable

* perf(claude): keep portable hooks shell-native

---------

Co-authored-by: Brennan Benson <[email protected]>
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.

Use $HOME instead of hardcoded path in Claude agent hooks

2 participants