copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

`preToolUse` agent hook denial does not work

Open springcomp opened this issue 5 months ago • 4 comments

Describe the bug

Running chat session from Copilot CLI, I have installed a hook that denies all commands.

Affected version

  • GitHub Copilot Chat Extension v1.0.65

Steps to reproduce the behavior

.github/hooks/hooks.json

{
  "version": 1,
  "hooks": {
    "preToolUse": [
      {
        "cwd": "src",
        "bash": "bin/Debug/net10.0/hook",
        "powershell": "bin/Debug/net10.0/hook",
        "timeoutSec": 15
      }
    ]
  }
}

A simple C# hook.exe program:

Program.cs

Console.WriteLine("{\"permissionDecision\":\"deny\"}");
Environment.Exit(2);

Here is a simple session prompt:

Give me the latest powershell Get-Date

I tried everything:

  • Exit code 2
  • {"permissionDecision": "deny"} response to preToolUse hook events.
  • {"behavior":"deny"} response to permissionRequest hook events.

Still, the tool is called and never denied.

Expected behavior

The tool call SHOULD be denied.

Additional context

No response

springcomp avatar Jun 20 '26 09:06 springcomp

The regression contract here can be very small.

For a PreToolUse event with a concrete tool_use_id, if the hook response resolves to permissionDecision: "deny", then:

  • run_in_terminal must not execute
  • no successful PostToolUse event should be emitted for that tool_use_id
  • the transcript should record a denied tool result with the hook reason

I would also pin precedence in the test: top-level permissionDecision vs hookSpecificOutput.permissionDecision vs exit code 2. If multiple shapes are accepted, they should converge to the same internal verdict before tool dispatch, rather than each host path interpreting them separately.


Generated with ax.

Necmttn avatar Jun 21 '26 09:06 Necmttn

I updated the issue to make it easier to reproduce

springcomp avatar Jun 30 '26 05:06 springcomp

This looks like a dispatch invariant rather than only a hook-format problem: once any pre-tool hook returns deny, the matching tool_use_id must become non-dispatchable. It would help to normalize all accepted hook output shapes into one internal verdict before execution, then test the full path (hook -> denial event -> no process spawn), not just JSON parsing. Logging the normalized verdict and tool_use_id would also make failures much easier to diagnose.

BGMLAI avatar Jul 14 '26 00:07 BGMLAI

This appears to be resolved as of GitHub Copilot CLI v1.0.86. Please update to that release or a newer stable version. We're closing this as completed. If it still happens, please comment with your version and reproduction steps.

copilot-cli-bot[bot] avatar Sep 20 '26 09:09 copilot-cli-bot[bot]