Skip to content

fix(hooks): stop Copilot from silently deciding permission on unconfigured commands - #3212

Merged
KuSh merged 5 commits into
developfrom
fix/copilot-parity-omit-permission-decision
Aug 2, 2026
Merged

KuSh merged 5 commits into
developfrom
fix/copilot-parity-omit-permission-decision

Conversation

@KuSh

@KuSh KuSh commented Jul 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the root cause of #3037 properly, instead of the workaround 84aa4d6/0df6929 shipped, and closes two related gaps found while validating it live against real Copilot CLI (1.0.75) and VS Code Copilot Chat.

  • permissionDecision parity — handle_vscode (rtk hook copilot's PascalCase path, shared by VS Code Copilot Chat and Copilot CLI's Claude-compat entry) always asserted permissionDecision: "allow" or "ask". Asserting "ask" is exactly what #3037 reported: Copilot CLI 1.0.66+ treats it as authoritative and forces a distinct, memory-less "Hook permission request" dialog on every call. 84aa4d6/0df6929 patched the camelCase native path instead (which never had this problem) with an auto-allow heuristic — the actual bug in handle_vscode was never touched. Now rtk hook copilot only ever asserts permissionDecision: allow for an explicit, user-configured Allow rule — exactly the same rule Claude Code's own hook (process_claude_payload) and Factory Droid's hook already use. Everything else omits the field, per GitHub's own docs ("empty output uses default behavior" — hook silence is a supported, intentional no-op, not a workaround), letting Copilot's native trust-on-first-use dialog (which does have a working "don't ask again" option) take over.
  • Dual hook registration removed — rtk init --copilot registered both a PascalCase PreToolUse and a camelCase preToolUse entry in the same file. Live testing (raw stdin capture, both hook-order and key-order reversed) showed Copilot CLI treats them as two independent, sequentially-run hooks regardless of declaration order — camelCase always runs first and does the real rewrite, PascalCase always runs second on the already-rewritten command and just defers. A redundant process spawn with no behavioral benefit, since Copilot CLI honors the PascalCase-only schema perfectly well on its own. Dropped the camelCase entry; existing installs upgrade on the next rtk init --copilot / rtk init --global --copilot re-run (write_if_changed overwrites unconditionally on content diff — verified with dedicated upgrade tests, not just fresh-install tests).
  • VS Code Copilot Chat tool-name gap — found while testing the above live in actual VS Code: detect_format only recognized tool_name values "runTerminalCommand"/"Bash"/"bash". A real captured payload from VS Code Copilot Chat showed it actually sends "run_in_terminal" — unrecognized, so the hook fell through to PassThrough and never fired at all for VS Code Copilot Chat (no rewrite, no decision, nothing). Added "run_in_terminal" to the recognized set. Fixes [Bug] rtk hook copilot does not trigger for VS Code Copilot Chat — "run_in_terminal" not recognized in detect_format() #1425

Live validation

All three changes were validated against the real, currently-released binaries and both real hosts (not just unit tests):

  • Built the actual develop HEAD (23d1e89) fresh as the true "before" baseline (an initially-used stale local install turned out to predate both 84aa4d6 and 0df6929 entirely).
  • Confirmed via raw stdin capture that Copilot CLI 1.0.75 genuinely sends the PascalCase (tool_name/tool_input.command) payload shape when only that key is registered — not just a VS-Code-relayed artifact.
  • Reproduced the exact #3037 bug live: develop HEAD's literal permissionDecision: "ask" produces a distinct "Hook permission request" / "RTK auto-rewrite" dialog with no remember option, repeating on every call.
  • Confirmed the fix produces Copilot's normal generic trust dialog instead, with a working "don't ask again" option — one prompt per repo, then silent, matching Claude Code's own UX.
  • Confirmed real VS Code Copilot Chat (freshly installed) now correctly rewrites a compound cd <dir> && git status --short --branch command to cd <dir> && rtk git status --short --branch, with no forced permissionDecision.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test --all (2498 tests, all green)
  • New unit tests: vscode_response_from_decision decision matrix (allow/ask/deny/defer), dual-schema-upgrade tests (project + global scoped), run_in_terminal format detection
  • Live end-to-end validation against real copilot CLI 1.0.75 and VS Code Copilot Chat, described above

🤖 Generated with Claude Code

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Nice catch on the dual-hook-invocation — that's a real bug and the fix (plus the upgrade test) is clean.

One thing worth double-checking before merge, since it interacts with #3179 (still open): once rtk init --copilot stops registering the camelCase preToolUse entry, Copilot CLI on Windows will only ever send the PascalCase PreToolUse payload. Per GitHub's own hooks reference, that payload remaps the runtime tool name for terminal execution:

bash, powershell → Bash

So both platforms report tool_name: "Bash" under this schema — a value already in the matches! list here. If that mapping is accurate for the CLI version people are actually running, toolName: "powershell" (the case #3179 adds) only ever existed in the camelCase schema this PR removes — meaning after this merges and someone re-runs rtk init --copilot, that code path becomes legacy-only (still correct for un-upgraded installs, just not exercised by new ones).

Did the live validation on 1.0.75 happen to include a Windows run? If the PascalCase Bash mapping already covers it, might be worth a one-line note here (or a Windows-flavored test) so #3179 doesn't get merged under a premise this PR quietly invalidates, and so whoever reads HookFormat::CopilotCli's updated doc comment later knows the powershell case is transition-only.

@KuSh

KuSh commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

No windows machine on my side to check that part unfortunately 😕

KuSh added 5 commits July 27, 2026 13:59
…AskRewrite

handle_vscode (rtk hook copilot's PascalCase path, shared by VS Code Copilot
Chat and Copilot CLI's Claude-compat entry) always set permissionDecision to
"allow" or "ask", diverging from process_claude_payload which only asserts
"allow" for an explicit user-configured Allow rule and stays silent otherwise.
Asserting "ask" is what caused #3037: Copilot CLI 1.0.66+ treats it as
authoritative and forces a blocking dialog with no "remember" option on every
rewritten command.

84aa4d6/0df6929 patched the wrong path (the camelCase native handler, which
never had this problem) with an auto-allow heuristic gated on an `explicit`
flag, instead of fixing handle_vscode itself. Replace both with the same rule
Claude's own hook and Droid's hook already use: never assert a decision for
AskRewrite, regardless of whether the verdict was Default or an explicit Ask
rule. This removes the Copilot-specific heuristic (and the now-unused
`explicit` field) in favor of one behavior shared across all hosts.

Also extracts vscode_response_from_decision as a pure, testable function
(mirroring copilot_cli_response_from_decision), closing a prior gap where
handle_vscode's decision output had no direct unit test coverage.
…ok config

rtk init --copilot registered both a PascalCase PreToolUse entry and a
camelCase preToolUse entry in the same rtk-rewrite.json, on the assumption
that VS Code Copilot Chat needs the former and Copilot CLI needs the latter.

Live testing showed Copilot CLI treats PreToolUse/preToolUse as two
independent, sequentially-run hooks — a redundant second `rtk hook copilot`
process spawn per tool call, chaining the first hook's rewrite into the
second's input (confirmed via raw stdin capture, and confirmed independent
of declaration order in the file). Also confirmed Copilot CLI honors the
PascalCase-only schema perfectly well on its own, receiving the same
tool_name/tool_input.command shape either way — so the camelCase entry buys
nothing for Copilot CLI, while adding process overhead and an extra,
harder-to-reason-about execution path.

Drop the camelCase preToolUse entry, keeping the single PascalCase
PreToolUse entry shared by both hosts. Existing installs are not upgraded
automatically — re-running `rtk init --copilot` / `rtk init --global
--copilot` overwrites the old dual-schema file with the new one
(write_if_changed overwrites unconditionally on content diff), verified
by test_copilot_init_upgrades_old_dual_schema_install and
test_copilot_global_install_upgrades_old_dual_schema_install, which seed
the old dual-schema content and assert it gets replaced.
detect_format only matched tool_name values "runTerminalCommand", "Bash",
and "bash" for the VsCode hook format. Live payload capture from a real VS
Code Copilot Chat session (agent mode, GitHub.copilot-chat) showed it
actually sends "run_in_terminal" — none of the previously recognized
values — so detect_format fell through to PassThrough and the hook never
fired at all for VS Code Copilot Chat: no rewrite, no permissionDecision,
nothing.

Add "run_in_terminal" to the recognized tool_name set. Verified against the
real captured payload end-to-end: a compound "cd <dir> && git status
--short --branch" command now correctly rewrites only the git segment to
"rtk git status --short --branch", leaving "cd" untouched, with no
permissionDecision asserted (consistent with the Default-verdict behavior
fixed in 042aeaf).
…ot generated

The doc comments described the camelCase toolName/toolArgs schema as "GitHub
Copilot CLI"'s format, which was accurate when rtk init --copilot registered
it. Now that only the PascalCase schema is generated, this path is reachable
only via not-yet-upgraded installs' leftover registration, or hosts that use
this schema under a different toolName value on their own (JetBrains/
IntelliJ's Copilot plugin sends "run_in_terminal", tracked in #2443/#3093).
Note both call sites accordingly so the code isn't mistaken for dead weight.
…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.
@KuSh
KuSh force-pushed the fix/copilot-parity-omit-permission-decision branch from d1cc6ba to 2cb3908 Compare July 27, 2026 12:21
@BillChirico

Copy link
Copy Markdown

So this will fix RTK to work on Windows?

@KuSh

KuSh commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

So this will fix RTK to work on Windows?

It depends what's your exact problem with RTK on Windows but it should help for sure

@BillChirico

Copy link
Copy Markdown

So this will fix RTK to work on Windows?

It depends what's your exact problem with RTK on Windows but it should help for sure

What problems does this fix and when can we expect it to be released?

@pszymkowiak pszymkowiak 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.

LGTM — this fixes the root cause in handle_vscode cleanly instead of extending the previous workaround, and the removed dual-hook registration + run_in_terminal detection gap are both real fixes found through solid live testing.

Re: my earlier question about Windows and the camelCase hook removal — confirmed and closed by @romain-cureau's live test on Windows 11 / Copilot CLI 1.0.73: #3179 (comment). The PascalCase PreToolUse path fires and its updatedInput is honored end-to-end on Windows, so dropping the camelCase entry here doesn't regress Windows behavior.

CI green across the board (including windows-latest and benchmark). Approving.

@KuSh
KuSh merged commit 8722378 into develop Aug 2, 2026
16 checks passed
@KuSh
KuSh deleted the fix/copilot-parity-omit-permission-decision branch August 2, 2026 17:55
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Aug 2, 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.

[Bug] rtk hook copilot does not trigger for VS Code Copilot Chat — "run_in_terminal" not recognized in detect_format()

3 participants