Skip to content

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

Closed

Description

@leynier

Summary

On Windows, every time Orca starts it (re)installs the Claude Code managed hook entry in ~/.claude/settings.json using the raw scriptPath returned by Electron's app.getPath('userData') — i.e. with single backslashes:

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

When Claude Code runs the hook it invokes the command through Git Bash (/usr/bin/bash). Bash interprets the single backslashes as escape characters, so \U, \l, \A, \R, \o, \a, \c are stripped and the resulting string is:

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

This breaks the UserPromptSubmit, Stop, PreToolUse, PostToolUse, PostToolUseFailure and PermissionRequest hooks for every Claude Code prompt on Windows. Manually editing the JSON to use / (or doubled \\) works, but Orca's install() runs again on the next start and overwrites the user's edit with the broken raw path.

Reproduction

  1. Run Orca on Windows. Open Claude Code in any terminal (inside or outside Orca).
  2. Send any prompt.
  3. Observe the hook errors:
❯ Hola
  ⎿  UserPromptSubmit hook error
  ⎿  Failed with non-blocking status code: /usr/bin/bash: line 1:
     C:UsersleyniAppDataRoamingorcaagent-hooksclaude-hook.cmd: command not found
● Hola, ¿en qué puedo ayudarte?
● Ran 2 stop hooks
  ⎿  Stop hook error: Failed with non-blocking status code: /usr/bin/bash: line 1:
     C:UsersleyniAppDataRoamingorcaagent-hooksclaude-hook.cmd: command not found

The same error occurs when Claude Code is launched from a regular terminal — it is purely a function of the value Orca writes into settings.json.

Root cause

src/main/claude/hook-service.ts:

function getManagedCommand(scriptPath: string): string {
  return process.platform === 'win32' ? scriptPath : `/bin/sh "${scriptPath}"`
}

On win32 the function returns the raw path with backslashes. JSON serialization emits "C:\\Users\\..." (correct JSON), and JSON.parse returns a string with single backslashes. Claude Code then hands that string to bash unquoted, where backslashes are escape characters.

Proposed fix

Emit forward slashes on Windows. They are accepted by Windows when invoking a .cmd file (Windows path APIs treat / and \ interchangeably for file-system paths) and bash leaves them intact, so the same JSON value works through every shell layer with no extra quoting:

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

The companion createManagedCommandMatcher in installer-utils.ts already normalizes paths with replaceAll('\\', '/') before substring-matching, so existing stale entries written with backslashes are still detected and swept on the next install() call (automatic migration).

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 ownership refactor that also covers PTY env shaping and runtime-state isolation.

This issue is intentionally narrower: a single-line fix targeting only the path-escaping bug in getManagedCommand, with no architectural changes. The accompanying PR is intended to be a minimal, surgical change that can ship independently of any larger refactor and unblocks Windows users immediately, without prejudicing the wider redesign discussed in #1308.

Scope

  • Affects only Claude Code on Windows. The Codex/Cursor/Gemini hook services share the same getManagedCommand shape but their runtime invocation paths have not been verified to exhibit the same bash-escape behavior, so they are intentionally out of scope for this minimal fix.
  • OpenCode is not affected: it ships a JS plugin via OPENCODE_CONFIG_DIR rather than a .cmd invoked through a hook config.

Environment

  • Orca (Windows build, current main)
  • Claude Code CLI on Windows (Git Bash / /usr/bin/bash runtime)

Activity

  1. added theissue type on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions