Repository navigation
Conversation
…mpat consumers don't fail closed #13443's managed Windows Claude hook never writes to stdout: the env guards exit silently, and the curl POST is redirected to `>nul`. Real Claude Code's documented contract treats that as "no decision" and lets the tool call proceed - confirmed against the current hook docs, which describe exit 0 with empty stdout as a pass-through, and an all-fields- absent JSON object as functionally identical to no output at all for every event, including the permission-decision ones (PreToolUse, PermissionRequest). cursor-agent's third-party Claude-hooks-compat layer doesn't implement that "silence is fine" convention: it treats PreToolUse as a permission hook that must return a JSON verdict, and empty stdout is invalid JSON to it, so it fails closed - every shell command blocked with "Hook ... returned invalid JSON" (#14818). Orca can't fix a third-party consumer's parser. What it can fix is that its own hook script relies on an implicit convention ("nothing on stdout == no opinion") instead of stating that opinion explicitly. `{}` is a valid, schema-passing JSON object with none of the decision fields set - by the documented contract, indistinguishable from no output for real Claude Code - so emitting it is not a behavior change for Claude, and it gives any spec-following third-party consumer a parseable "no decision" instead of nothing to choke on. Added `emitEmptyJsonStdout` as an opt-in option on the shared `buildWindowsHookEnvironmentGuardLines`/`buildWindowsHookStdinDrainEpilogue` helpers (default off, unchanged behavior) and wired it into every exit path of the Claude .cmd - the three env guards, the main success path after the curl POST, and the Devin-skip stdin-drain epilogue - so no path can still emit nothing. Left every other consumer of these shared helpers (Grok, Gemini, Droid, Devin, Cursor's own installer, Command Code, Codex, Antigravity) on the default, since none of them were reported to have this problem and broadening the change would be an unrequested behavior change for agents that don't need it. Fixes #14818
📝 WalkthroughWalkthroughWindows hook environment guards and stdin-drain epilogues now accept an Merge Risk: ⚪ Minimal · up to This change emits valid empty JSON for the managed Windows hook without altering the intended permission behavior. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/claude/hook-service.ts (1)
72-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReduce the duplicated multi-line rationale. Keep one concise comment at each site. The issue reference can remain.
src/main/claude/hook-service.ts#L72-L74: replace the three-line compatibility explanation with one short rationale.src/main/claude/hook-service.test.ts#L403-L406: replace the four-line test rationale with one short test-intent comment.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e733bc19-892a-48c1-ab99-1467d3bba281
📒 Files selected for processing (3)
src/main/agent-hooks/hook-stdin-contract.tssrc/main/claude/hook-service.test.tssrc/main/claude/hook-service.ts
|
Superseding this with #14825, which now carries the 1. This fix cannot work on its own. The
2. The emission strategy here misses a path and can drift. This PR adds
There was also a third gap neither PR caught: the launcher's own missing-script fallback returns empty stdout without ever entering the script, reproducing #14818 whenever The analysis in this PR's description was sound and is carried over; only the mechanism changed. #14818 is fixed by #14825. |
Root cause
The managed Windows Claude hook script (
claude-hook.cmd) never writes anything to stdout on any path: the three env guards (ORCA_AGENT_HOOK_PORT/TOKEN/ORCA_PANE_KEYmissing) exit silently, and the curl POST that reports the event to Orca is redirected to>nul 2>&1.I checked the current hook documentation (code.claude.com/docs/en/hooks) for what that means: exit 0 with empty stdout is explicitly documented as a pass-through — "the hook has no decision to report, so the tool call continues through the normal permission flow." An empty JSON object
{}is documented to mean the same thing for every event, including the permission-decision ones (PreToolUse,PermissionRequest): none of the decision fields (decision,hookSpecificOutput,permissionDecision) are set, so it's treated as "no decision," identically to no output at all. So for real Claude Code, "write nothing" and "write{}" are the same thing.cursor-agent's third-party Claude-hooks-compat layer doesn't implement that convention. It treats
PreToolUseas a permission hook that must return a JSON verdict, and empty stdout is invalid JSON to its parser — so it fails closed:Every shell command in every cursor-agent session on Windows gets blocked, since Orca's own managed hook is registered on
PreToolUsewith matcher*.Why this is the root-cause fix, not a workaround
Orca doesn't control cursor-agent's parser — there's no fix available there. What Orca does control is its own hook script, and that script currently relies on an implicit convention ("nothing on stdout means no opinion") instead of stating that opinion explicitly.
{}is a valid, schema-passing JSON object with no fields set. By the documented contract, it is indistinguishable from no output for real Claude Code — so emitting it is not a behavior change for Claude Code itself. It just makes Orca's script an explicit, spec-compliant "no decision" instead of an implicit one, which happens to also be exactly what a strict but spec-following third-party consumer needs to not choke.Fix
Added
emitEmptyJsonStdoutas an opt-in option (defaultfalse, unchanged behavior) on the two shared helpers inhook-stdin-contract.ts:buildWindowsHookEnvironmentGuardLines({ emitEmptyJsonStdout: true })— each of the three env guards becomesif "%VAR%"=="" (echo {}& exit /b 0)instead ofif "%VAR%"=="" exit /b 0.buildWindowsHookStdinDrainEpilogue({ emitEmptyJsonStdout: true })— the stdin-drain epilogue (used both as the normal tail and as the Devin-skip landing point) emitsecho {}before itsexit /b 0.Wired both into
getManagedScript('local', ...)inhook-service.tsfor the Claude.cmd, plus oneecho {}before the main success-pathexit /b 0after the curl POST. That covers every exit path: the three early guards, the Devin-skip drain, and the normal success path.The POSIX
.shbranch and the statusline script are untouched — the statusline's stdout is the literal status line text shown in the UI, so emitting{}there would show{}in the UI. That script is not affected by any change in this PR.Scope
The two shared helpers are used by seven other agent hook services (Grok, Gemini, Droid, Devin, Cursor's own installer, Command Code, Codex, Antigravity). None of them were reported to have this problem, and none of them call the new option — the default keeps their generated scripts byte-for-byte identical to before this PR. Verified by running each of their test suites (see below); only Claude's own test file changes shape.
Testing
npx tsc --noEmit -p config/tsconfig.node.json— clean.hook-service.test.ts— 15/15 pass, including a new regression test asserting{}is emitted from every exit path of the generated.cmd(all three guards, the success path, and the drain epilogue).antigravity,command-code,droid,devin,cursor,gemini,grok,codex, plusstatusline-script.test.ts) — same 14 pre-existing failures asorigin/mainwith no changes applied (codex-session-resume-home path tests + one Devin POSIX-assertion test, both environmental/pre-existing, unrelated tohook-stdin-contract.ts), confirming the opt-in default didn't regress any of them.nul(buildWindowsAgentHookCurlPostCommand), soecho {}really is the only thing written to the script's stdout — no risk of the HTTP response body contaminating the JSON a consumer parses.Fixes #14818