Skip to content

Windows: Claude Code hooks are written with an args array that Claude Code ignores, so a bare conhost.exe runs on every tool call #15797

Closed

Description

@maytayci

Summary

On Windows, Orca writes Claude Code hook entries containing an args array. Claude Code's hook schema has no args field — it executes command only. The effective command is therefore a bare C:\WINDOWS\System32\conhost.exe, which spawns a console host, emits terminal control sequences, and never invokes claude-hook.cmd.

Environment

  • Orca 1.4.185 (publisher: stablyai)
  • Claude Code 2.1.229 (winget install)
  • Windows 11 Pro 26200
  • VS Code integrated terminal (also reproduced in a standalone terminal; not visible in JetBrains' terminal, which does not apply the sequences)

What Orca writes

Orca installs 11 hook entries into ~/.claude/settings.json (SessionStart, UserPromptSubmit, Stop, StopFailure, SubagentStart, SubagentStop, TeammateIdle, PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest), each shaped like:

{
  "type": "command",
  "command": "C:\WINDOWS\System32\conhost.exe",
  "args": [
    "--headless",
    "C:\WINDOWS\System32\cmd.exe",
    "/d",
    "/c",
    "%USERPROFILE%\.orca\agent-hooks\claude-hook.cmd"
  ],
  "timeout": 10
}

PreToolUse, PostToolUse, PostToolUseFailure and PermissionRequest use "matcher": "*", so they fire on every tool call.

Where it comes from

In resources/app.asar, the Windows hook builder returns a {command, args} pair:

function Qy(e){
  let t = path.win32.join(process.env.SystemRoot ?? "C:\Windows", "System32"),
      n = path.win32.join("%USERPROFILE%", ".orca", "agent-hooks", path.win32.basename(e));
  return {
    type: "command",
    command: path.win32.join(t, "conhost.exe"),
    args: ["--headless", path.win32.join(t, "cmd.exe"), "/d", "/c", n],
    timeout: se
  };
}

The intent is clearly correct — run the .cmd inside a headless conhost so no console window flashes. The problem is only that Claude Code takes a single command string, not command + args.

Impact

With args dropped, each hook run executes a bare conhost.exe, which writes this to the terminal:

ESC[?9001h ESC[?1004h ESC[?25l ESC[?9001l ESC[?1004l ESC[2J ESC[m ESC[H ESC]0;C:\WINDOWS\System32\conhost.exe BEL ESC[?25h
  • ESC[2J + ESC[H clear the screen and home the cursor — on every tool call. In VS Code's integrated terminal this visibly wipes output mid-session (the reported symptom was "text keeps disappearing").
  • ESC[?9001h then ESC[?9001l toggles win32-input-mode on and back off, which can desync keyboard handling from what the TUI expects.
  • ESC]0;… retitles the terminal tab to conhost.exe.
  • The hook exits 0, so Claude Code records it as a successful run and nothing is logged as an error.
  • Orca's agent-hook integration never runs at all — claude-hook.cmd is never invoked, so no hook events reach the local endpoint.

Measured over ~29 days of local session transcripts: 899 recorded hook runs, 800+ of them in the ~44 hours after install (206 PreToolUse + 201 PostToolUse for the Bash tool alone).

Suggested fix

Collapse the invocation into a single command string and drop args:

{
  "type": "command",
  "command": "\"%SystemRoot%\System32\conhost.exe\" --headless \"%SystemRoot%\System32\cmd.exe\" /d /c \"%USERPROFILE%\.orca\agent-hooks\claude-hook.cmd\"",
  "timeout": 10
}

It would also help to re-read ~/.claude/settings.json after writing and assert that no args key survives in the entries Orca owns.

Not affected

  • claude-hook.cmd, codex-hook.cmd and claude-statusline.cmd themselves are fine. The statusline integration works correctly — only the hook-entry shape is wrong.
  • The Codex integration is unaffected: ~/.codex/config.toml contains no Orca hook wiring.

Activity

  1. maytayci commented on Aug 21, 2026

    @maytayci
    Author

    Additional detail that narrows the repro: no project or agent session inside Orca is needed — installing and launching Orca once is sufficient.

    On this machine the hooks were written on first launch, before Orca was ever used for anything: at that point ~/.orca/ contained nothing but agent-hooks/ (no sessions, no worktrees, no project state), and %APPDATA%/Orca held only empty Electron cache directories.

    Repro steps

    1. Windows 11, Claude Code installed (~/.claude/settings.json exists)
    2. Install Orca 1.4.185 and launch it once — do not open a project or start any agent
    3. Inspect ~/.claude/settings.json → 11 hook entries appear, each command: conhost.exe plus an args array that Claude Code's hook schema doesn't recognize
    4. Outside Orca (e.g. VS Code integrated terminal), start a Claude Code session and let it run any tool
    5. Observed: on every tool call the screen is cleared (ESC[2J + ESC[H) and the tab is retitled to conhost.exe; claude-hook.cmd never runs
    6. Expected: outside Orca the hook should be a silent no-op (the env-var guards in claude-hook.cmd are designed for exactly that); inside Orca it should report the event via claude-hook.cmd

    Timeline from this machine: Orca installed 2026-08-19; first launch 2026-08-20 19:22 local — agent-hooks/ and the 11 hook entries appeared at that minute, and the first corrupted hook run shows in Claude Code transcripts one minute later.

  2. yzxcj797 commented on Aug 21, 2026

    @yzxcj797
    Contributor

    Version-pinned this against the release tags by reading src/main/claude/hook-settings.ts at each:

    • v1.4.185 / v1.4.186 — getWindowsManagedLifecycleHook is exactly the decompiled builder: {command: <System32>\conhost.exe, args: ["--headless", <System32>\cmd.exe, "/d", "/c", %USERPROFILE%\.orca�gent-hooks\<script>]}, gated on the (mis)assumption that Claude's exec form supports args (supportsExecHookArgs). So the reported shape is what 1.4.185 ships.
    • v1.4.187 / main — the builder is reworked to a single self-contained command (an encoded PowerShell launcher whose comment states the reason verbatim: "some Claude-compatible consumers ignore args, so the invocation must be self-contained"), with conhost gone from the file entirely. A scan of the current hook installers finds no writer that emits an args key anymore.

    Self-healing on upgrade: the install sweep's managed-command matcher (hookHasManagedCommand) also scans args entries for the agent-hooks/<script>.cmd needle, so the legacy conhost entries are recognized as managed and replaced by the new single-string command on the first launch of a current build — no manual settings.json surgery needed.

    So: fixed in 1.4.187; anyone on 185/186 should update and relaunch once with any Claude worktree active. If args-shaped Orca entries reappear on 1.4.187+, that would be a regression worth a fresh report.

  3. maytayci commented on Aug 21, 2026

    @maytayci
    Author

    Thanks @yzxcj797 for the detailed version-pinned diff — really helpful.

    Confirming empirically: updated this machine from 1.4.185 to 1.4.187 (release asset, sha256-verified) and relaunched once. ~/.claude/settings.json now gets a single self-contained command string per hook (no args key, no bare conhost.exe). Decoded the payload — it runs claude-hook.cmd if present, otherwise drains stdin and prints {} as a clean no-op, so no more screen-clearing outside Orca either. Self-heal worked as described, no manual settings.json editing needed.

    Marking this resolved on my end. Will reopen with a fresh report if args-shaped entries ever reappear on 1.4.187+.

  4. nwparker commented on Aug 22, 2026

    @nwparker
    Contributor

    Thank you — this is an unusually precise report, and the diagnosis is exactly right.

    Already fixed on main, ahead of your build. The {command, args} shape you decompiled from 1.4.185's app.asar was replaced in #14818/#14815. Windows hooks are now written as a single command string with no args key:

    export function wrapWindowsPowerShellEncodedCommand(command: string): string {
      return `${getWindowsPowerShellExecutablePath()} ${WINDOWS_POWERSHELL_HOOK_SWITCHES} -EncodedCommand ${encodeWindowsPowerShellHookCommand(command)}`
    }

    src/main/agent-hooks/windows-powershell-hook-launcher.ts. Switches are -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden, and the payload is -EncodedCommand UTF-16LE base64 — so nothing has to survive cmd.exe or MSYS rewriting, and there is no args array for a consumer to drop. Hidden PowerShell replaced conhost specifically because, unlike conhost, it relays hook output and exit status (#14818).

    Two things your report adds that the fix did not have, and which I have kept:

    1. The failure was silent in both directions — no console flash to notice, and the hook never ran, so hook-dependent features simply did nothing. Worth remembering as a shape: a launcher whose arguments a consumer may drop degrades to "runs the launcher bare", which is rarely harmless.
    2. installer-utils.ts still understands the legacy args shape (hookHasManagedCommand) so an upgrade can recognise and clean up the 11 entries 1.4.185 wrote into your ~/.claude/settings.json. That matters — without it those stale entries would keep firing after the upgrade. Confirmed present on main.

    Closing as fixed. If a build after 1.4.185 still writes args for you, please reopen with the settings.json block — that would mean the cleanup path is missing a case.

    Related: #15767 reports the same root cause via Cursor's hook import.

  5. nwparker commented on Aug 22, 2026

    @nwparker
    Contributor

    Fixed on main by #14818/#14815: Windows hooks are now a single command string via hidden PowerShell -EncodedCommand, with no args array.

  6. amomurawskiio425-cloud commented on Aug 23, 2026

    @amomurawskiio425-cloud

    Same bug hit me — and your diagnosis is correct. Claude Code's hook schema has no args; it runs command verbatim, so Orca's conhost.exe + args: [--headless,…] becomes a bare conhost that spawns a console and never calls claude-hook.cmd. That's root-caused in Orca's Windows hook builder, not your setup.

    The frustrating part is deleting those 11 entries by hand doesn't last — Orca re-installs them every time it starts, so the windows come straight back.

    What actually ended it for me was letting Coffee CLI clean the residue on launch: it drops only the Orca-written hook entries from ~/.claude/settings.json (yours stay intact) and skips while Orca is running so it doesn't fight Orca. After that the bare-conhost-per-tool-call stopped for good.

    One honest caveat: it won't restore hooks Orca already deleted, and if Orca stays running it won't touch anything while active. But for this exact args-swallowing pollution it's a real cure, not a workaround. https://github.com/edison7009/Coffee-CLI/releases/tag/v3.3.8

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions