Skip to content

On Windows + Git Bash, Cursor agent breaks two ways: prompt injection is mangled, and hooks block every prompt #6694

Open

Description

@charlieYong

On Windows + Git Bash, Cursor agent breaks two ways: prompt injection is mangled, and hooks block every prompt

Summary

On Windows, when the terminal shell is Git Bash (the default many users pick, and the case where cursor-agent ships as a bash wrapper), Orca's Cursor integration is broken in two independent but same-root ways:

  1. Prompt injection is mangled — the initial task prompt is quoted with PowerShell rules but executed by bash, so any prompt containing ', !, \, etc. gets corrupted.
  2. Every hook blocks the prompt — Orca writes Cursor's hooks.json commands in PowerShell form, but cursor-agent executes hook commands via /bin/sh -c, so they fail with syntax error near unexpected token '&', and Cursor treats the failed beforeSubmitPrompt hook as a block.

Both stem from the same wrong assumption: on Windows, Orca hardcodes "shell = PowerShell", but the Cursor CLI toolchain (launcher + hooks) runs under POSIX shell / bash.

Environment

  • OS: Windows 10/11
  • Terminal shell: Git Bash (settings.terminalWindowsShell: "git-bash")
  • defaultTuiAgent: "cursor"
  • cursor-agent on PATH is a Git Bash wrapper script (common on Windows); cursor-agent itself runs hook commands with process.env.SHELL || "/bin/sh".

Bug 1 — Prompt injection quoted for the wrong shell

Root cause

resolveStartupShell defaults to 'powershell' on win32 whenever no explicit shell is provided:

// src/shared/tui-agent-startup-shell.ts
export function resolveStartupShell(platform, shell) {
  return shell ?? (platform === 'win32' ? 'powershell' : 'posix')
}

buildAgentStartupPlan then quotes the prompt with quoteStartupArg(prompt, shell) and, for argv agents (cursor, codex, …), builds `${baseCommand} ${quotedPrompt}`.

But every caller of buildAgentStartupPlan passes platform but never shell (src/renderer/src/lib/launch-agent-in-new-tab.ts, launch-work-item-direct-agent.ts, worktree-activation.ts, FloatingTerminalWindowControls.tsx, …). So on Windows the prompt is always PowerShell-quoted, regardless of the pane's actual shell. The pane shell, however, is chosen later from settings.terminalWindowsShell (and per-tab shellOverride); git-bash routes to bash.exe --login -i. A PowerShell-quoted command string is then handed to bash.

Demonstration

PowerShell quoting of don't delete → 'don''t delete'. Parsed by bash:

$ bash -c "printf '[%s]\n' 'don''t delete'"
[dont delete]          # apostrophe swallowed — WRONG

$ bash -c "printf '[%s]\n' 'don'\''t delete'"
[don't delete]         # POSIX quoting — correct

Proposed fix

Thread the effective pane shell into the startup plan instead of assuming PowerShell on Windows.

// shared
export function windowsTerminalShellToStartupShell(
  windowsShell: string | undefined
): AgentStartupShell {
  const s = (windowsShell ?? 'powershell.exe').toLowerCase()
  if (s === 'git-bash' || s.endsWith('bash.exe') || s === 'wsl.exe') return 'posix'
  if (s === 'cmd.exe' || s === 'command_prompt') return 'cmd'
  return 'powershell'
}
// each launcher (already reads settings via the app store)
const windowsShell = perTabShellOverride ?? settings.terminalWindowsShell
const shell =
  resolvedLaunchPlatform === 'win32'
    ? windowsTerminalShellToStartupShell(windowsShell)
    : undefined // resolveStartupShell -> 'posix'

const startupPlan = buildAgentStartupPlan({ agent, prompt, cmdOverrides, platform: resolvedLaunchPlatform, shell, /* … */ })

buildAgentStartupPlan already forwards shell into resolveStartupShell; only the call sites must supply it. Per-tab shellOverride must win over the global setting. WSL panes also need POSIX quoting.


Bug 2 — Hook commands written for PowerShell but executed by /bin/sh

Root cause

Orca writes Cursor's ~/.cursor/hooks.json command in PowerShell form for all Windows installs:

// src/main/cursor/hook-service.ts
function getManagedScriptFileName(): string {
  return process.platform === 'win32' ? 'cursor-hook.cmd' : 'cursor-hook.sh'
}
function getManagedCommand(scriptPath: string): string {
  return process.platform === 'win32'
    ? wrapWindowsHookCommand(scriptPath)   // powershell.exe -EncodedCommand …
    : wrapPosixHookCommand(scriptPath)
}

The resulting hooks.json command (decoded) is:

powershell.exe -NoProfile -ExecutionPolicy Bypass -EncodedCommand <…>
# decodes to:  & 'C:\Users\<u>\.orca\agent-hooks\cursor-hook.cmd'; exit $LASTEXITCODE

But cursor-agent runs hook commands through a POSIX shell:

// cursor-agent index.js
te(this.options?.shell || process.env.SHELL || "/bin/sh", [...shellArgs, "-c", u], …)

So bash receives a PowerShell statement and fails:

Hook blocked with message: --: eval: line 1: syntax error near unexpected token `&'
  --: eval: line 1: `$OutputEncoding = …; … | & { $input | powershell.exe -EncodedCommand … }'

A non-zero hook exit on beforeSubmitPrompt is treated by Cursor as blocking the prompt, so the user cannot submit anything.

Evidence this is just a missing branch

Orca already knows Cursor hooks must be POSIX: the remote path uses cursor-hook.sh + wrapPosixHookCommand unconditionally:

// src/main/cursor/hook-service.ts (remote)
const remoteScriptPath = `${remoteHome}/.orca/agent-hooks/cursor-hook.sh`
const command = wrapPosixHookCommand(remoteScriptPath)

Only the local win32 branch wrongly assumes PowerShell.

Proposed fix

Cursor's hook commands are executed by Cursor's own shell ($SHELL//bin/sh), not by Orca's terminal shell. On Windows, Cursor still runs hooks via the bundled bash, so Cursor's managed hook should use the POSIX .sh script + wrapPosixHookCommand on all platforms (the script already exists — see getManagedScript POSIX branch). At minimum, choose the hook form based on how Cursor invokes hooks, not on process.platform.


Workarounds (no code change)

  • Bug 1: set terminalWindowsShell to PowerShell and point agentCmdOverrides.cursor at the native cursor-agent.cmd so the quoting matches the executing shell. (Keep day-to-day terminals on Git Bash via per-tab shellOverride.)
  • Bug 2: disable Orca-managed agent hooks (agentStatusHooksEnabled: false) and clear the broken entries in ~/.cursor/hooks.json. This unblocks prompts but loses Orca's live status/title/permission UI for all agents.

Both workarounds are obviously band-aids; the real fix is to stop assuming PowerShell on Windows for the Cursor (and other POSIX-toolchain) integration.

Activity

  1. added
    bugSomething isn't working
    size/mMedium PR (≤600 added lines, ≤25 files)
    on Jun 30, 2026
  2. added theissue type on Jul 12, 2026
  3. added
    pending_reproRepro attempted; still pending conclusive reproduction
    on Jul 16, 2026
  4. OrcaWin commented on Jul 17, 2026

    @OrcaWin
    Collaborator

    Agent reproduction package (Windows orchestration 2026-07-16)

    Host context: Windows 11 / Orca 1.4.143.0 / repo path used: docs/bug-reproductions/
    Labels applied: see issue labels (has_repro or cannot_repro).
    Security: Do not run user-uploaded binaries from issue attachments. Recreate fixtures from the steps/scripts below.


    Issue 6694 — Git Bash + Cursor agent prompt mangled + hooks block

    Status: needs_setup / treated as cannot_repro on this host until prerequisites land
    Host: Windows 11, Orca 1.4.143
    Label: cannot_repro (attempted; blocked)

    What we tried

    Git Bash present. Cursor agent.cmd NOT installed. Source analysis matches issue: resolveStartupShell defaults to powershell on win32; hooks written PowerShell-style while cursor-agent may run via /bin/sh.

    What is needed Install Cursor Agent CLI; set terminalWindowsShell=git-bash; launch Cursor with prompt containing apostrophe; inspect hooks.json command shell.

    Install Cursor Agent CLI; set terminalWindowsShell=git-bash; launch Cursor with prompt containing apostrophe; inspect hooks.json command shell.

    Notes

    • Docs live under docs/bug-reproductions/. Re-run once prerequisites exist.
    • Security: do not run untrusted issue attachments.

    How another agent should use this

    1. Read this comment fully (status, expected vs actual, blockers).
    2. If a script is included above, copy it to a temp file and run it on a Windows 11 host with Orca installed (prefer production install under %LOCALAPPDATA%\Programs\orca).
    3. Capture evidence (CLI --json, screenshots, logs) under a local folder; optionally comment results back here.
    4. If status is cannot_repro / needs_setup, satisfy the listed prerequisites first, then re-attempt and flip labels: remove cannot_repro, add has_repro when conclusive.
  5. deleted a comment from edison7009 on Aug 22, 2026
  6. nwparker commented on Oct 24, 2026

    @nwparker
    Contributor

    Thanks for the thorough report. Prompt quoting now follows the actual shell (Git Bash included) and the Cursor hook command was reworked so it runs under the shell Cursor uses. Could you confirm on the latest build with Git Bash? If it still happens on the latest build, please reply or reopen and we'll take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingos:Windowspending_reproRepro attempted; still pending conclusive reproductionsize/mMedium PR (≤600 added lines, ≤25 files)

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions