Skip to content

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

Closed

Description

@romain-cureau

Summary

rtk hook copilot recognizes the native Copilot CLI payload only when
toolName == "bash". On Windows, Copilot CLI names its shell tool
powershell, so detect_format returns PassThrough and the
HookFormat::CopilotCli branch — the one that emits modifiedArgs and
deliberately omits permissionDecision — is never reached.

What answers instead is the Claude-compat PreToolUse entry, which routes to
HookFormat::VsCode and emits permissionDecision: "ask". Since Copilot CLI
1.0.66+ treats that field as authoritative, every rewritten command prompts
(this is #3037), and the allowlist (--allow-tool "shell(rtk:*)",
permissions-config.json) cannot help: only allow/deny short-circuit the
permission flow, ask forces the prompt.

This also explains 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 #2424.

Environment

  • RTK: 0.43.0 (official release asset rtk-x86_64-pc-windows-msvc.zip,
    SHA256 A715E989BCEBFC208F388CF5ADAAA9953CBF1127B081BC09C4EF02E7D7FEA39F)
  • Copilot CLI: 1.0.73
  • OS: Windows 11 Pro 26200
  • Hook file: the one generated by rtk init -g --copilot
    (~/.copilot/hooks/rtk-rewrite.json, declaring both PreToolUse and
    preToolUse)

Evidence

Payload actually delivered to the camelCase preToolUse entry, captured
from a live Copilot CLI session with a logging hook:

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

toolArgs is the JSON-encoded string RTK expects — only toolName differs
(powershell, not bash).

Payload delivered to the PascalCase PreToolUse entry in the same session:

{"hook_event_name":"PreToolUse","session_id":"...","cwd":"C:\\Windows\\System32",
 "tool_name":"Bash","tool_input":{"command":"git status --short"}}

Resulting behavior, reproducible 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":{"hookEventName":"PreToolUse","permissionDecision":"ask",
 "permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git status"}}}

Root cause

src/hooks/hook_cmd.rs, detect_format:

// Copilot CLI: camelCase keys, toolArgs is a JSON-encoded string
if let Some(tool_name) = v.get("toolName").and_then(|t| t.as_str()) {
    if tool_name == "bash" {        // ← never true on Windows

Suggested fix

Accept Copilot CLI's Windows shell tool name:

if matches!(tool_name, "bash" | "powershell") {

A patch with a regression test (test_detect_copilot_cli_powershell) is
attached / in the linked PR.

Note on interaction with #3037

The two are complementary. With this fix the native path is reached on Windows
and returns modifiedArgs without permissionDecision, but the Claude-compat
PreToolUse entry generated by rtk init still answers ask for the same
tool call. Unless #3037 is fixed as well (or the generated hook file stops
declaring both entries), Windows users keep getting a prompt on every command.

Current workaround

Wrap the hook and rewrite the decision before Copilot sees it:

"command": "rtk hook copilot | sed 's/\"permissionDecision\":\"ask\"/\"permissionDecision\":\"allow\"/'"

On Windows the same thing is done from a small PowerShell wrapper, which must
also handle the fact that Windows PowerShell 5.1 prepends a UTF-8 BOM to piped
stdin (RTK already handles that itself — see
test_copilot_bom_prefixed_payload_is_recognized).

Activity

  1. pszymkowiak commented on Jul 23, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 94%

    Summary

    detect_format in src/hooks/hook_cmd.rs only matches toolName == "bash", so Copilot CLI's Windows shell tool ("powershell") falls through to PassThrough/Claude-compat path and never gets the modifiedArgs-only CopilotCli response — fix by matching both "bash" and "powershell".

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/hooks/hook_cmd.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. romain-cureau commented on Jul 27, 2026

    @romain-cureau
    ContributorAuthor

    Follow-up after testing on the same Windows box, since one claim above turned out to be wrong.

    Still accurate: detect_format doesn't recognize toolName: "powershell", so the native CopilotCli branch is unreachable on Windows. Fix in #3179.

    Retracted: I wrote that this "explains the Windows limitation documented in the README" and that only the Claude-compat entry answers. The first half is wrong. Copilot CLI fires both registered entries, and the PascalCase one both receives the call (remapped to tool_name: "Bash") and has its updatedInput honored — verified with a throwaway hook rewriting echo PROBE_INPUT_5521 to echo REWRITE_APPLIED_9137; the session printed REWRITE_APPLIED_9137. So the rewrite does work on Windows today, through that path.

    The user-visible symptom on Windows is therefore the ask prompt from handle_vscode (#3037), not a missing rewrite — which is exactly what #3212 fixes at the root. This issue narrows to "detect_format misreports what Copilot CLI sends on Windows", and once #3212 lands and users re-run rtk init --copilot, #3179's arm becomes legacy-only. Fine by me if maintainers prefer to close both in favour of #3212.

  3. KuSh commented on Jul 27, 2026

    @KuSh
    Collaborator

    Thanks a lot for the test and confirmation @romain-cureau. This MR will still be of value at least for the users that don't rerun init after an upgrade! I'll merge that one and rebase #3212 after that.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issueplatform:windowspriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions