Skip to content

fix(hook): detect Copilot CLI shell tool on Windows - #3179

Merged
KuSh merged 1 commit into
rtk-ai:developfrom
romain-cureau:fix/hooks-copilot-windows-powershell-tool
Jul 27, 2026
Merged

KuSh merged 1 commit into
rtk-ai:developfrom
romain-cureau:fix/hooks-copilot-windows-powershell-tool

Conversation

@romain-cureau

@romain-cureau romain-cureau commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • detect_format matched the native Copilot CLI payload only on toolName == "bash". Copilot CLI names its shell tool powershell on Windows, so the payload fell through to PassThrough and the HookFormat::CopilotCli branch was unreachable there.
  • Consequence: on Windows only the Claude-compat PreToolUse entry answers, via HookFormat::VsCode, which emits permissionDecision: "ask" — a permission prompt on every rewritten command (see rtk hook copilot emits permissionDecision "ask", forcing a permission prompt on every command in Copilot CLI >= 1.0.66 #3037), and one the allowlist cannot suppress since only allow/deny short-circuit Copilot's permission flow.
  • This also matches the Windows limitation documented in the README ("On native Windows (cmd.exe / PowerShell), RTK filters work but the hook does not auto-rewrite commands") and reported in Windows and GitHub Copilot #2424.

Fixes #3178.

Test plan

  • cargo fmt --all -- --check ✅ · cargo clippy --all-targets ✅ (no warnings) · cargo test --all — hooks:: subset 396/396 green, new test_detect_copilot_cli_powershell passes

    Run locally on rustc 1.97.1 / stable-x86_64-pc-windows-msvc. fmt caught a width overflow in my own patch, fixed in 10ca886. cargo test --all reports 16 failures, all in core::stream::tests (program not found — they spawn Unix binaries); verified identical on unmodified origin/develop, so pre-existing on Windows and unrelated. Details in the comments below.

  • Manual verification against a live Copilot CLI session

    Captured with a logging hook wired to the camelCase preToolUse entry, Copilot CLI 1.0.73 / Windows 11, RTK 0.43.0 (official release asset):

    {"sessionId":"c1b3f427-...","timestamp":1784807355614,"cwd":"C:\\Windows\\System32",
     "toolName":"powershell","toolArgs":"{\"command\":\"rtk gain\",\"description\":\"...\"}"}

    toolArgs is already the JSON-encoded string RTK expects — only toolName differed. And with the shipped binary:

    $ echo '{"toolName":"powershell","toolArgs":"{\"command\":\"git status\"}"}' | rtk hook copilot
                                         # empty: PassThrough, native path skipped
    
    $ echo '{"tool_name":"Bash","tool_input":{"command":"git status"}}' | rtk hook copilot
    {"hookSpecificOutput":{...,"permissionDecision":"ask",...,"updatedInput":{"command":"rtk git status"}}}

Note

This is complementary to #3037, not a replacement. With this fix the native path is reached on Windows and returns modifiedArgs without a permissionDecision, but the PreToolUse entry that rtk init also writes still answers ask for the same tool call. Unless #3037 lands as well (or the generated hook file stops declaring both entries), Windows users keep getting a prompt on every command.

@CLAassistant

CLAassistant commented Jul 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@KuSh KuSh left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @romain-cureau, thanks for your contribution, LGTM apart from one minor nitpick!

Comment thread src/hooks/hook_cmd.rs Resolved
@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for tracking this down — since you've got Copilot CLI running on Windows already, could you help confirm something that affects whether this stays needed long-term?

Right now rtk init --copilot registers two hook entries for Copilot CLI: a PascalCase PreToolUse and a camelCase preToolUse. Copilot CLI apparently fires both, independently, on every tool call (that's the redundant-double-hook bug #3212 separately fixes). Your fix here targets the camelCase one (toolName: "powershell").

Question: on your Windows setup, was the other hook (PreToolUse, PascalCase) already receiving and correctly handling your terminal commands before this fix, in parallel with the broken camelCase one? Per GitHub's hooks reference, that payload remaps both bash and powershell to a single tool_name: "Bash" — a value rtk already recognizes there. If that hook was already firing correctly for you, it'd mean the prompt-every-time symptom you saw was likely coming only from the camelCase side being silently ignored (your fix is still correct either way) rather than Windows being entirely unhandled.

Asking because #3212 removes the camelCase registration entirely in favor of the PascalCase one — if that one already works standalone on Windows, this fix's code path becomes legacy-only once #3212 lands and someone re-runs rtk init --copilot. Not asking for changes here, just want to get the full picture before the two PRs land.

KuSh added a commit that referenced this pull request Jul 26, 2026
…owershell

GitHub's hooks reference normalizes bash/powershell to tool_name "Bash" for
PascalCase PreToolUse payloads, so the schema rtk init --copilot now
exclusively registers already handles Copilot CLI on Windows via the
existing "Bash" match. Document that the camelCase toolName "powershell"
case (#3178/#3179) is transition-only, and add a regression test making
the Windows-coverage reasoning explicit.
@romain-cureau
romain-cureau force-pushed the fix/hooks-copilot-windows-powershell-tool branch from 9637b25 to 7ab299c Compare July 27, 2026 07:01
@romain-cureau

Copy link
Copy Markdown
Contributor Author

@KuSh nitpick addressed — copilot_cli_input now takes a tool argument like vscode_input, existing call sites pass "bash", and the new test uses it. Also rebased onto current develop, so the run_in_terminal arm added by #3149/fix/2443-copilot-ide-terminal is preserved: matches!(tool_name, "bash" | "powershell" | "run_in_terminal").

@pszymkowiak — yes, and I tested it rather than inferring it. The PascalCase hook was already firing and being honored on Windows, in parallel with the ignored camelCase one. Two pieces of evidence, both from Copilot CLI 1.0.73 on Windows 11.

1. It receives the call. Both entries fire for the same tool call; the payloads differ exactly as you describe:

// camelCase preToolUse — toolName is the real Windows tool
{"sessionId":"...","cwd":"C:\\Windows\\System32",
 "toolName":"powershell","toolArgs":"{\"command\":\"rtk gain\",...}"}

// PascalCase PreToolUse — same session, remapped to "Bash"
{"hook_event_name":"PreToolUse","session_id":"...","cwd":"C:\\Windows\\System32",
 "tool_name":"Bash","tool_input":{"command":"git status --short"}}

2. Its updatedInput is actually applied. I registered a throwaway PascalCase hook that rewrites one marker command to another and returns permissionDecision: "allow":

// hook sees:      echo PROBE_INPUT_5521
// hook returns:   {"hookSpecificOutput":{...,"permissionDecision":"allow",
//                   "updatedInput":{"command":"echo REWRITE_APPLIED_9137"}}}

Session output was REWRITE_APPLIED_9137. So on Windows the PascalCase path rewrites end-to-end, and updatedInput is honored there — the symptom I hit was purely handle_vscode asserting ask, which matches your analysis in #3212.

Correction to my own issue text: I wrote in #3178 that the unreachable native path "explains the Windows limitation documented in the README" and cross-posted that on #2424. That was wrong for Copilot CLI and I've retracted it there — the rewrite does happen on Windows, via the Claude-compat entry. Whatever #2424 is hitting is something else. Sorry for the noise.

So yes: once #3212 lands and users re-run rtk init --copilot, this arm is legacy-only — it still matters for anyone who doesn't re-init, and it keeps detect_format honest about what Copilot CLI actually sends, but it's no longer load-bearing. Happy to close it in favour of #3212 if you'd rather keep the surface small.

Test plan status unchanged and worth restating: cargo fmt/clippy/test still not run on my side (no Rust toolchain on the Windows box this was diagnosed on, and CI here is action_required pending maintainer approval). The change is one match arm plus a test helper signature, but please don't take my word for the build.

Copilot CLI names its shell tool "powershell" on Windows, so detect_format
only ever matched "bash" and fell through to PassThrough. The native
CopilotCli branch — the one returning modifiedArgs without a permissionDecision
— was therefore unreachable on Windows, leaving only the Claude-compat
PreToolUse entry to answer, which emits "ask" and prompts on every command.

Verified against a live Copilot CLI 1.0.73 session on Windows 11: the payload
delivered is {"toolName":"powershell","toolArgs":"{\"command\":\"...\"}"} —
toolArgs is already the JSON-encoded string RTK expects, only toolName differed.

Refs rtk-ai#3178

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@romain-cureau
romain-cureau force-pushed the fix/hooks-copilot-windows-powershell-tool branch from 7ab299c to 10ca886 Compare July 27, 2026 07:12
@romain-cureau

Copy link
Copy Markdown
Contributor Author

Retracting my earlier "test plan not run" caveat — I installed a Rust toolchain and ran the CI commands locally. Pushed as 10ca886.

cargo fmt --all -- --check caught a real issue in my own patch: adding the tool argument pushed the second copilot_cli_input call in test_copilot_bom_prefixed_payload_is_recognized over the width limit. Fixed and folded into the commit.

CI command Result
cargo fmt --all -- --check ✅ exit 0
cargo clippy --all-targets ✅ exit 0, no warnings
cargo test --all ⚠️ 2483 passed / 16 failed — all pre-existing on Windows, none related (see below)
hooks:: subset ✅ 396 passed, 0 failed
new test_detect_copilot_cli_powershell ✅ passes

The 16 failures are all in core::stream::tests, failing with Failed to spawn process / program not found — they shell out to Unix binaries that don't exist on Windows. To be sure they aren't mine, I ran the same subset on a detached checkout of unmodified origin/develop (1d6798d):

# origin/develop, not a line of this PR applied
$ cargo test --bin rtk core::stream
test result: FAILED. 18 passed; 16 failed; ...

# this branch
$ cargo test --bin rtk core::stream
test result: FAILED. 18 passed; 16 failed; ...

Identical, so cargo test --all is simply not green on a Windows host today. Worth knowing given this is the Windows-facing code path — happy to file that separately if it's not already known.

The security-lint job's expect()/panic! hits are also pre-existing and none are in hook_cmd.rs (that step is ::warning::-only, non-blocking).

Environment: rustc 1.97.1, stable-x86_64-pc-windows-msvc, Windows 11.

@KuSh
KuSh merged commit 7da2674 into rtk-ai:develop Jul 27, 2026
11 checks passed
KuSh added a commit that referenced this pull request Jul 27, 2026
…owershell

Contributor testing on Windows 11 with Copilot CLI 1.0.73 (#3179) confirmed
Copilot CLI remaps its native bash/powershell shell tool to tool_name: "Bash"
under the PascalCase PreToolUse schema, and that its updatedInput is honored
end-to-end there. Since rtk init --copilot now only registers that schema,
Windows already works standalone through it — the camelCase toolName
"powershell" case (#3178/#3179) becomes legacy-only, relevant solely to
un-upgraded installs. Document that on both HookFormat variants.

Also fixes a HookDecision::AskRewrite struct-pattern leftover in
copilot_ide_response_from_decision (added by #3093, merged into develop
after this branch's own struct-to-tuple AskRewrite refactor), surfaced as a
compile error by rebasing onto develop to pick up #3179.
@aeppling aeppling mentioned this pull request Jul 27, 2026
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.

hook(copilot): on Windows, detect_format never matches Copilot CLI's shell tool (toolName: "powershell")

4 participants