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.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
Step 1: Install Dependencies
Step 2: Configure Guardrails
Configuration
Hook Locations
The location ofhooks.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)
2. userPromptSubmitted (AUDIT-ONLY)
security_alerts.jsonl.
3. postToolUse (AUDIT-ONLY)
Audit Logs
All events are logged to~/copilot/hooks_logs/:
View Logs
Testing
Test Hook Manually
Troubleshooting
Hooks Not Running
-
Ensure hooks.json is in the correct location:
- Coding Agent:
.github/hooks/hooks.jsonon default branch - Copilot CLI:
hooks.jsonin current working directory
- Coding Agent:
-
Verify
"version": 1is set in hooks.json - Check Python is accessible at the configured path
- Validate JSON syntax of hooks.json
PowerShell 7 Not Found (Windows)
If you see this error with Copilot CLI:-
Install PowerShell 7+:
-
Add to system PATH:
- Open System Properties → Environment Variables
- Edit the
Pathsystem variable - Add:
C:\Program Files\PowerShell\7
- Restart your terminal/IDE completely
-
Verify:
pwsh --versionshould showPowerShell 7.x.x
API Returning 404
The"Policy not found" error means:
- The
policy_violationdetector references a non-existent policy - Fix: Disable
policy_violationor create the policy in Enkrypt Dashboard
Metrics
Resources
- GitHub Copilot Hooks Documentation
- Copilot Hooks Configuration Reference
- Enkrypt AI Documentation
- Enkrypt Dashboard
Next Steps
Configure Policies
Create custom guardrail policies
View Logs
Monitor security events
Add Detectors
Configure detection rules
Metrics
Track performance