Skip to main content

Overview

GitHub Copilot’s Coding Agent supports hooks for monitoring and controlling tool executions. The Secure MCP Gateway provides guardrails integration through hooks that validate prompts, tool inputs, and outputs.
Hooks Support: Copilot hooks work with Copilot Coding Agent and Copilot CLI, but NOT with VS Code Copilot Chat or inline suggestions.

Where Hooks Work


Installation

Prerequisites

  • GitHub Copilot with coding agent hooks support
  • Python 3.8+
  • PowerShell 7+ for Windows (required for Copilot CLI)
  • Enkrypt API key
Windows Users: Copilot CLI requires PowerShell 7+ (pwsh.exe), not Windows PowerShell 5.x.Install via:

Step 1: Install Dependencies

Step 2: Configure Guardrails


Configuration

Hook Locations

The location of hooks.json depends on which Copilot environment you’re using:

Copilot Coding Agent Setup

Copilot CLI Setup


Hooks Configuration

hooks.json Format


Hook Events

Only preToolUse can block actions. All other hooks are observational.

Guardrails Configuration

guardrails_config.json

Available Detectors


How It Works

1. preToolUse (BLOCKING)

Input from Copilot:
Output to Copilot:

2. userPromptSubmitted (AUDIT-ONLY)

This hook cannot block prompts — Copilot ignores its output. Violations are logged to security_alerts.jsonl.

3. postToolUse (AUDIT-ONLY)

Input from Copilot:

Audit Logs

All events are logged to ~/copilot/hooks_logs/:

View Logs


Testing

Test Hook Manually

Expected output:

Troubleshooting

Hooks Not Running

  1. Ensure hooks.json is in the correct location:
    • Coding Agent: .github/hooks/hooks.json on default branch
    • Copilot CLI: hooks.json in current working directory
  2. Verify "version": 1 is set in hooks.json
  3. Check Python is accessible at the configured path
  4. Validate JSON syntax of hooks.json

PowerShell 7 Not Found (Windows)

If you see this error with Copilot CLI:
Solution:
  1. Install PowerShell 7+:
  2. Add to system PATH:
    • Open System Properties → Environment Variables
    • Edit the Path system variable
    • Add: C:\Program Files\PowerShell\7
  3. Restart your terminal/IDE completely
  4. Verify: pwsh --version should show PowerShell 7.x.x

API Returning 404

The "Policy not found" error means:
  • The policy_violation detector references a non-existent policy
  • Fix: Disable policy_violation or create the policy in Enkrypt Dashboard

Metrics


Resources


Next Steps

Configure Policies

Create custom guardrail policies

View Logs

Monitor security events

Add Detectors

Configure detection rules

Metrics

Track performance