Skip to content

fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag pair (STA-5237) - #16739

Merged
brennanb2025 merged 2 commits into
mainfrom
brennan/sta-5237-resolve-permission-denied-error-when-executing-powershell
Aug 27, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennan/sta-5237-resolve-permission-denied-error-when-executing-powershell

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 $\color{#cf222e}{\Huge{\mathbf{−}}}$​36 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8

Summary

-WindowStyle Hidden + -EncodedCommand is denied at CreateProcess by Kaspersky on Windows 11, whatever the payload decodes to — exit 0 is denied too. Bash surfaces it as Permission denied (exit 126), so every managed hook event fails and agent status never arrives. Worse, right after a denied call the parent bash briefly cannot spawn anything (dofork: child -1 … errno 13), so a denied hook can take the user's next command down with it.

This removes -WindowStyle Hidden from the shared launcher switch constant. The command line becomes powershell.exe -NoProfile -EncodedCommand <b64>.

Fixes #16003. Reported again via user feedback as STA-5237.

Why this flag, and why #16576 did not fix it

Measured on the reporting host with a harmless exit 0 payload:

command line result
-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand 126
-NoProfile -WindowStyle Hidden -EncodedCommand (the post-#16576 shape) 126
-WindowStyle Hidden -EncodedCommand 126
-NoProfile -EncodedCommand 0 (5/5)
-NoProfile -ExecutionPolicy Bypass -Command 0 (5/5)

#16576 removed -ExecutionPolicy Bypass — the one flag of the three not in the signature — so hooks kept failing after it landed. That was reported on #16003 after it was closed. The pair that has to stop being spelled is -WindowStyle Hidden + -EncodedCommand.

Reproducible without Orca or any agent CLI, in Git Bash:

P=C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe
E=$(printf 'exit 0' | iconv -t UTF-16LE | base64 -w0)
"$P" -NoProfile -EncodedCommand $E                      # rc 0
"$P" -NoProfile -WindowStyle Hidden -EncodedCommand $E   # rc 126

This is a regression, not a long-standing condition. The PowerShell launcher shipped in v1.4.187 (2026-08-21) via #14825, replacing conhost --headless cmd /d /c. git merge-base --is-ancestor 02ba70a847 v1.4.186 is false; v1.4.187 is true. The reporter is on v1.4.188, cut 2026-08-22.

Scope

Because the change is to the shared constant, it covers every site spelling the denied pair in one edit — Claude via wrapWindowsPowerShellEncodedCommand (hook-settings.ts:176), gemini/cursor/droid/command-code/copilot via wrapWindowsHookCommand, the runtime-home-hook-command.ts:28 unsafe-HOME fallback, and the spaced-path fallback for codex/grok/devin/antigravity. No agent is left behind, and there is no follow-up needed for the others. (Kimi is unaffected: it ships a Git Bash .sh and never emits PowerShell.)

Only a flag is removed, so parser and payload compatibility is unchanged for every executor that reads ~/.claude/settings.json — Git Bash, PowerShell (Claude Code's documented fallback when Git Bash is absent), and the command-line/argv[0] spawn used by cursor-agent, Devin, and Grok's Claude-compat import. The string is still a PowerShell command line, still one self-contained command with no args, still base64-shielded.

The tradeoff, stated plainly

-WindowStyle Hidden was the shipped fix for #14815 (+ #14828, #15117, #15447, #15767) and this removes it. What the record shows about that flag:

A console flicker is a worse outcome than no flicker — but a far better one than every hook failing plus the parent shell being unable to spawn the user's next command.

Window gate: MEASURED, and it clears

The open question was whether removing -WindowStyle Hidden lets a console appear per hook event.
It was measured on Windows 11 build 26200 — the same build as the #16003 reporters — in an
isolated Orca Electron instance, with each arm resetting its sampler and requiring a non-zero hook
fire before any window count was accepted
(a zero-window reading from a hook that never ran is
indistinguishable from success):

Chain Fire proof, no flag Fire proof, with flag New ConsoleWindowClass HWNDs Foreground steals
Claude Git Bash hook-origin completion hook-origin completion 0 / 0 0 / 0
Claude PowerShell fallback hook-origin completion hook-origin completion 0 / 0 0 / 0
Cursor registered command listener POST delta 2 listener POST delta 2 0 / 0 0 / 0
Grok hook-origin completion hook-origin completion 0 / 0 0 / 0
AV exit codes, Kaspersky host — — 126 with flag, 0 (5/5) without reporter-measured

No console appears either way. That is consistent with #15506's argument that the flag could not
have been suppressing the console for the .cmd child, and with #16576's author stating the
suppression was never verified on a real box.

Two limits stated rather than glossed:

  • This is one host and one parent chain. A console is allocated by the parent, not by this
    command line, so the result is evidence for this configuration, not a universal claim.
  • The Cursor row measured the registered command, not cursor-agent as the spawning parent — the
    Cursor TUI was blocked on login. Fire proof is a listener POST delta of 2 on both arms, so the
    command demonstrably ran; but the parent chain was not Cursor's own.

An anti-restoration mutation check confirms the guard works: restoring -WindowStyle Hidden makes
the launcher test fail.

Tests

  • windows-powershell-hook-launcher.test.ts — asserts the command line spells neither -ExecutionPolicy nor -WindowStyle, and pins the exact shape. This is an anti-restoration guard, not proof of the fix: fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag triple #16576 round 3 dropped -WindowStyle Hidden by accident and updated the tests to match, so nothing caught it.
  • 10 pinned shape sites updated. The set is derivable, not hand-maintained: grep -rn "WindowStyle" src/ --include='*.ts' must return hits only in the launcher source itself.
  • managed-hook-timeout.test.ts deliberately not touched — its carrier predicate keys on -EncodedCommand, which does not change.
  • Adds windows-hook-payload-delivery.test.ts to the PR CI Windows leg, which had never run it.
pnpm exec vitest run --config config/vitest.config.ts <14 hook suites>   # 144 passed, 20 skipped
pnpm run typecheck:node                                                   # clean
oxlint + oxfmt on changed files                                           # clean

Windows-only live suites (windows-hook-payload-delivery, managed-hook-stdin-lifecycle) were not executed — this machine is macOS.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Windows PowerShell hook launcher now uses -NoProfile -EncodedCommand without -WindowStyle Hidden. Launcher, installer, and hook-service tests validate the new command shape. Installer tests also cover fallback stdout when the managed script is missing. The Windows package test workflow runs the Windows hook payload delivery test.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The change addresses #16003 and removes the AV-denied flag combination while preserving encoded payload handling and process-scoped execution-policy handling. However, #16576 explicitly requires prese… Update the linked issue requirements to explicitly supersede the hidden-window requirement, or provide an implementation that avoids the AV trigger while preserving hidden execution. Complete the required Windows window-behavior measurement…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 10 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The production change, launcher tests, affected integration assertions, fallback coverage, and Windows CI coverage all support the stated hook-launcher fix. No unrelated code changes are evident.
Title check ✅ Passed The title clearly identifies the main change: removing the antivirus-denied Windows hook launcher flag combination. It is concise and specific.
Description check ✅ Passed The description is detailed and on-topic. It explains the failure, changed command line, rationale, scope, linked issue, compatibility impact, measurements, tests, and unexecuted Windows-only suites. …
Full details: Linked Issues check

Explanation

The change addresses #16003 and removes the AV-denied flag combination while preserving encoded payload handling and process-scoped execution-policy handling. However, #16576 explicitly requires preserving -WindowStyle Hidden and unchanged console suppression. This PR removes that switch, and real-host window verification remains outstanding.

Resolution

Update the linked issue requirements to explicitly supersede the hidden-window requirement, or provide an implementation that avoids the AV trigger while preserving hidden execution. Complete the required Windows window-behavior measurements before merging if #16576 remains in scope.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 10 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description is detailed and on-topic. It explains the failure, changed command line, rationale, scope, linked issue, compatibility impact, measurements, tests, and unexecuted Windows-only suites. It does not use all template headings or complete the checklist, but the required information is mostly present.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/agent-hooks/windows-powershell-hook-launcher.ts (1)

17-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the duplicated incident history. Keep the current launcher invariant and issue references, but remove the detailed chronology and host measurements.

  • src/main/agent-hooks/windows-powershell-hook-launcher.ts#L17-L41: state that -WindowStyle Hidden must remain absent with -EncodedCommand, then link the relevant issues.
  • src/main/agent-hooks/windows-powershell-hook-launcher.test.ts#L15-L28: keep only the test-specific reason for pinning the command shape, or refer to the launcher comment.

As per coding guidelines: “BE CONCISE. 1 LINE if possible.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 81a89ba8-b9a9-4f46-83f8-f26e825c3e86

📥 Commits

Reviewing files that changed from the base of the PR and between 026389a and b68b883.

📒 Files selected for processing (11)
  • .github/workflows/pr.yml
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/windows-powershell-hook-launcher.test.ts
  • src/main/agent-hooks/windows-powershell-hook-launcher.ts
  • src/main/claude/hook-service.test.ts
  • src/main/codex/hook-service-managed-install.test.ts
  • src/main/command-code/hook-service.test.ts
  • src/main/cursor/hook-service.test.ts
  • src/main/droid/hook-service.test.ts
  • src/main/gemini/hook-service.test.ts
  • src/main/grok/hook-service.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

@brennanb2025
brennanb2025 force-pushed the brennan/sta-5237-resolve-permission-denied-error-when-executing-powershell branch from b68b883 to 3e68309 Compare August 27, 2026 08:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/agent-hooks/windows-powershell-hook-launcher.test.ts (1)

16-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten this TypeScript comment. Keep only the launcher invariant and the live-measurement gap; move issue history and host measurements to PR documentation. No functional change is required.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 85e15f69-0a5f-4328-a647-d144407113e8

📥 Commits

Reviewing files that changed from the base of the PR and between b68b883 and 3e68309.

📒 Files selected for processing (4)
  • .github/workflows/pr.yml
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/windows-powershell-hook-launcher.test.ts
  • src/main/cursor/hook-service.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: clean within scope

Reviewed and pushed head 3e68309fefc53309ab5a71198b502820c301184a. The review found no proven P0/P1/P2 product, regression, or performance blockers. One review fix strengthens the anti-restoration contract so a source grep for WindowStyle now hits only the production launcher comments while the exact -NoProfile launcher shape remains mutation-resistant.

Windows Electron A/B gate

Validated the exact reviewed head in an isolated Orca Electron dev instance on Windows 11 high spec using Playwright CDP. Each arm reset its window sampler and required a non-zero hook fire before window counts were accepted.

Chain Fire proof without flag Fire proof with flag New ConsoleWindowClass HWNDs Foreground steals
Claude Git Bash hook-origin completion hook-origin completion 0 / 0 0 / 0
Claude PowerShell fallback hook-origin completion hook-origin completion 0 / 0 0 / 0
Cursor registered command listener POST delta 2 listener POST delta 2 0 / 0 0 / 0
Grok hook-origin completion hook-origin completion 0 / 0 0 / 0

Temporary WITH-flag hook settings were restored afterward and the Windows PR worktree remained clean.

Windows Orca app identity

Grok hook completion on the WITH-flag comparison arm

Verification

  • Full affected main directories: 232 files passed, 1 skipped; 2,274 tests passed, 37 skipped.
  • pnpm tc:node and pnpm tc:cli: passed.
  • Changed-file lint, format, and git diff --check: passed.
  • Anti-restoration mutation check: restoring -WindowStyle Hidden makes the launcher test fail; reviewed launcher tests pass 6/6.
  • GitHub package (windows): passed, including windows-hook-payload-delivery.test.ts (2/2); all 26 Windows files passed, 205 tests passed and 13 skipped.
  • Start and end readiness scans plus the final adversarial review: clean.

Remaining CI state

The required verify check is currently red only because Node 24 and Node 26 shard 10 both fail the same pre-existing src/shared/runtime-client-export-parity.test.ts export inventory mismatch. The PR has no diff from origin/main in the failing shared runtime files, and the failure reproduces locally at the reviewed head, so I did not expand STA-5237 to repair unrelated baseline scope.

A direct run of windows-hook-payload-delivery.test.ts on the high-spec validation host also exposed a host-specific test isolation issue: HKCU Command Processor\\AutoRun points to %USERPROFILE%\\.cmd_aliases.cmd, while the test intentionally replaces USERPROFILE with a temp home, so the nested cmd.exe exits before delivery. The clean GitHub Windows runner passes that test, and this host artifact is distinct from the measured product window behavior.

No in-scope blocker remains; merge is mechanically blocked until the unrelated required-check baseline is resolved or rerun on a fixed base.

…ed flag pair (STA-5237)

`-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by
Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as
`Permission denied` and every managed hook event fails, so agent status never
arrives; the parent shell also briefly cannot spawn anything afterwards, so a
denied hook can take the user's next command down with it.

Measured on the reporting host (#16003), with a harmless `exit 0` payload:

  -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand  126
  -NoProfile -WindowStyle Hidden -EncodedCommand                          126
  -WindowStyle Hidden -EncodedCommand                                     126
  -NoProfile -EncodedCommand                                              0 (5/5)

#16576 removed `-ExecutionPolicy Bypass`, which is the one flag of the three
NOT in the signature, so hooks kept failing after that fix. The pair that has
to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`.

Because the change is to the shared switch constant, it covers every site that
spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`,
gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the
`runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback
for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload
compatibility is unchanged for every executor: the string is still a PowerShell
command line, still one self-contained token, still base64-shielded.

The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped
fix for #14815 (+#14828, #15117, #15447, #15767), and this removes it. Its
suppression was never measured — #14825 confirmed it visually, #16576's author
stated it "remains unverified on a real box", and #15506's author argued it
cannot help a `.cmd` child with no console to inherit. The console is allocated
by the parent chain, not by this command line. A live window measurement is
still outstanding and is called out in the PR.

Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg,
which had never run it.
@brennanb2025
brennanb2025 force-pushed the brennan/sta-5237-resolve-permission-denied-error-when-executing-powershell branch from 3e68309 to 1efd27d Compare August 27, 2026 17:43
@brennanb2025
brennanb2025 merged commit 928d306 into main Aug 27, 2026
47 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…ed flag pair (STA-5237) (stablyai#16739)

* fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag pair (STA-5237)

`-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by
Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as
`Permission denied` and every managed hook event fails, so agent status never
arrives; the parent shell also briefly cannot spawn anything afterwards, so a
denied hook can take the user's next command down with it.

Measured on the reporting host (stablyai#16003), with a harmless `exit 0` payload:

  -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand  126
  -NoProfile -WindowStyle Hidden -EncodedCommand                          126
  -WindowStyle Hidden -EncodedCommand                                     126
  -NoProfile -EncodedCommand                                              0 (5/5)

NOT in the signature, so hooks kept failing after that fix. The pair that has
to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`.

Because the change is to the shared switch constant, it covers every site that
spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`,
gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the
`runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback
for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload
compatibility is unchanged for every executor: the string is still a PowerShell
command line, still one self-contained token, still base64-shielded.

The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped
fix for stablyai#14815 (+stablyai#14828, stablyai#15117, stablyai#15447, stablyai#15767), and this removes it. Its
suppression was never measured — stablyai#14825 confirmed it visually, stablyai#16576's author
stated it "remains unverified on a real box", and stablyai#15506's author argued it
cannot help a `.cmd` child with no console to inherit. The console is allocated
by the parent chain, not by this command line. A live window measurement is
still outstanding and is called out in the PR.

Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg,
which had never run it.

* test(agent-hooks): keep launcher token out of source grep

(cherry picked from commit 928d306)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ed flag pair (STA-5237) (stablyai#16739)

* fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag pair (STA-5237)

`-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by
Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as
`Permission denied` and every managed hook event fails, so agent status never
arrives; the parent shell also briefly cannot spawn anything afterwards, so a
denied hook can take the user's next command down with it.

Measured on the reporting host (stablyai#16003), with a harmless `exit 0` payload:

  -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand  126
  -NoProfile -WindowStyle Hidden -EncodedCommand                          126
  -WindowStyle Hidden -EncodedCommand                                     126
  -NoProfile -EncodedCommand                                              0 (5/5)

stablyai#16576 removed `-ExecutionPolicy Bypass`, which is the one flag of the three
NOT in the signature, so hooks kept failing after that fix. The pair that has
to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`.

Because the change is to the shared switch constant, it covers every site that
spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`,
gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the
`runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback
for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload
compatibility is unchanged for every executor: the string is still a PowerShell
command line, still one self-contained token, still base64-shielded.

The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped
fix for stablyai#14815 (+stablyai#14828, stablyai#15117, stablyai#15447, stablyai#15767), and this removes it. Its
suppression was never measured — stablyai#14825 confirmed it visually, stablyai#16576's author
stated it "remains unverified on a real box", and stablyai#15506's author argued it
cannot help a `.cmd` child with no console to inherit. The console is allocated
by the parent chain, not by this command line. A live window measurement is
still outstanding and is called out in the PR.

Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg,
which had never run it.

* test(agent-hooks): keep launcher token out of source grep
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.

[Bug]: Claude Code agent-hooks (claude-hook.cmd) fail with "Permission denied" when invoked by the hook runner

1 participant