Skip to content

fix(claude-hook): use forward slashes in Windows managed hook command path - #1329

Merged
nwparker merged 1 commit into
stablyai:mainfrom
leynier:fix/windows-hook-path-backslash-escape
May 2, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
leynier:fix/windows-hook-path-backslash-escape

Conversation

@leynier

@leynier leynier commented May 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1328.

Problem

On Windows, Orca writes the Claude Code managed hook command into ~/.claude/settings.json as a raw path with single backslashes:

C:\Users\<user>\AppData\Roaming\orca\agent-hooks\claude-hook.cmd

Claude Code invokes hooks through Git Bash (/usr/bin/bash), which interprets \U, \A, etc. as escape sequences and collapses the path to:

/usr/bin/bash: line 1: C:UsersleyniAppDataRoamingorcaagent-hooksclaude-hook.cmd: command not found

Every Claude Code hook (UserPromptSubmit, Stop, PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest) fails on Windows. Manually editing the JSON works until Orca's next install() overwrites it.

Fix

Single-line change in src/main/claude/hook-service.ts::getManagedCommand: emit forward slashes on Windows. They are accepted when invoking a .cmd file and bash leaves them intact, so the same JSON value works through every shell layer.

return process.platform === 'win32'
  ? scriptPath.replaceAll('\\', '/')
  : `/bin/sh "${scriptPath}"`

createManagedCommandMatcher in agent-hooks/installer-utils.ts already normalizes slashes when sweeping stale entries, so existing installs migrate automatically on the next install() call.

Scope

Intentionally minimal:

  • Touches only src/main/claude/hook-service.ts (one function, one line of logic + a why-comment).
  • Does not change Codex / Cursor / Gemini hook services: they share the same getManagedCommand shape, but their runtime invocation paths have not been verified to exhibit the same bash-escape behavior. Keeping them out of scope makes this change safe to ship independently and easy to revert.
  • OpenCode is unaffected (it uses OPENCODE_CONFIG_DIR + JS plugin, no JSON-stored command).

Relationship to #1308

Issue #1308 ("Managed hook runtime and PTY spawn env handling drift across layers") describes the same symptom but frames it as part of a broader cross-layer refactor covering PTY env shaping and runtime-state isolation.

This PR is intentionally narrower and more focused than #1308: a one-line behavioral fix that unblocks Windows users immediately, with no architectural changes. It does not preempt or block #1308's broader redesign — both can land independently.

Verification

  • Local: edited getManagedCommand and confirmed the resulting path no longer collapses through bash -c. Existing path matching in createManagedCommandMatcher handles backslash-or-forward-slash normalization, so previously-installed entries are detected and swept on the next install.
  • Cross-platform: branch on process.platform === 'win32' is unchanged for non-Windows; behavior on macOS/Linux is identical.

Related

Claude Code on Windows runs settings.json hooks through Git Bash

(/usr/bin/bash). A path with single backslashes (e.g.

C:\Users\...\claude-hook.cmd) is interpreted by bash as a string

containing escape sequences, so \U, \A, etc. collapse and the

launcher fails with 'command not found'.

Emit forward slashes from getManagedCommand() on win32 so the same

JSON value works through every shell layer (Windows accepts forward

slashes in path arguments, bash leaves them intact).

Amp-Thread-ID: https://ampcode.com/threads/T-019de591-6d60-771f-bfc6-4a8164791bca
Co-authored-by: Amp <[email protected]>
@nwparker
nwparker merged commit 6faf406 into stablyai:main May 2, 2026
1 check passed
@leynier
leynier deleted the fix/windows-hook-path-backslash-escape branch May 2, 2026 05:12
mralexsaavedra pushed a commit to mralexsaavedra/orca that referenced this pull request May 2, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

Windows: Claude managed hook command path uses backslashes that bash strips, breaking every hook

2 participants