Copilot Hooks
Akto Guardrails for GitHub Copilot provides security validation for AI-assisted development across VS Code and the CLI. It intercepts prompts when submitted and tool executions before and after they run, validates against security policies, blocks risky behavior, and reports events to your Akto dashboard.
Key Features
✅ Zero Installation - No standalone apps to install
✅ Transparent Integration - Uses GitHub Copilot's native hook mechanism in both VS Code and CLI
✅ Real-time Tool Blocking - Can block dangerous tool executions before they run
✅ Centralized Monitoring - All events reported to Akto dashboard
✅ Flexible Deployment - Supports Argus and Atlas modes
✅ Configurable Behavior - Blocking or observation modes
⚠️ Prompt Monitoring Only - GitHub Copilot limitation prevents blocking prompts at submission
How Hooks Works
GitHub Copilot's hook system executes custom scripts at three critical points in both VS Code and the CLI:
3 Hook Points:
userPromptSubmitted- Monitors prompts when submitted to Copilot (reporting only, cannot block)preToolUse- Validates tool use before execution and can block dangerous operationspostToolUse- Ingests tool execution results for monitoring and audit
GitHub Copilot Limitation: The userPromptSubmitted hook cannot block prompt execution. Prompts flagged by guardrails will still reach the LLM. Only preToolUse can prevent operations from executing. For complete prompt blocking, consider using a network proxy.
File Structure
Key Files:
Wrapper scripts (
.sh/.ps1): Set environment variables, invoke Python scripts⚠️ Contains
AKTO_DATA_INGESTION_URLplaceholder - Must be set to your Akto instance URL.shused on macOS/Linux;.ps1used on Windows
Python scripts (
.py): Core validation logic and Akto API communicationakto_machine_id.py: Generates unique device identifiers for Atlas modehooks.json: Links hooks to wrapper scripts — usesbashkey on macOS/Linux andpowershellkey on Windows
Note:
hooks.jsonis loaded from the project root's.github/hooks/directory.
Setup Guide
Prerequisites
GitHub CLI installed or VS Code
Akto instance URL
Python 3
macOS / Linux: bash or zsh
Windows: PowerShell 5.1+ (built-in on Windows 10/11, including Azure Virtual Desktop pooled sessions)
Installation Steps
Create the Hooks Directory
macOS / Linux:
Windows (PowerShell):
Download Hook Scripts
macOS / Linux:
Windows (PowerShell):
Configure Akto Ingestion URL ⚠️ CRITICAL STEP
All wrapper scripts contain the variable AKTO_DATA_INGESTION_URL that must be set to your actual Akto instance URL.
macOS / Linux — automated replacement:
Windows (PowerShell) — automated replacement:
Manual replacement (alternative):
Edit each wrapper script and replace:
With your actual Akto instance URL, e.g. https://your-akto-instance.com.
Files to update on macOS/Linux:
akto-validate-prompt-wrapper.shakto-validate-pre-tool-wrapper.shakto-validate-post-tool-wrapper.sh
Files to update on Windows:
akto-validate-prompt-wrapper.ps1akto-validate-pre-tool-wrapper.ps1akto-validate-post-tool-wrapper.ps1
Verify hooks.json Configuration
The hooks.json file should already be configured after downloading. Verify it contains all three hooks:
Windows note: The
powershellkey is used automatically on Windows. The.ps1wrapper sets all required environment variables before invoking the Python script — equivalent to what the.shwrappers do on macOS/Linux.
Note:
timeoutSecis in seconds (30 = 30 seconds). Hooks are loaded from.github/hooks/hooks.jsonin the directory you run copilot from.
Configure Hook Behavior (Optional)
Edit wrapper scripts to customize:
macOS / Linux — in each *-wrapper.sh:
Windows — in each *-wrapper.ps1:
Mode Options:
Argus: Standard validation and reporting
Atlas: Includes device-specific metadata
Sync Mode:
true: Validates in real-time;
preToolUseblocks dangerous tool executionsfalse: Monitoring only; all tool executions pass through but are logged
Verify Installation
macOS / Linux:
Windows (PowerShell):
Check logs to confirm hooks are working:
macOS / Linux:
Windows (PowerShell):
Configuration Reference
Wrapper Script Variables
Environment Variables (Optional)
Override defaults via environment variables (e.g. in ~/.bashrc or ~/.zshrc):
Troubleshooting
Hooks Not Executing
Ingestion URL Not Configured
macOS / Linux:
Windows (PowerShell):
Windows: Hooks Not Running
Step 1 — Verify .ps1 wrapper files were downloaded:
If missing, re-run the Windows download step above.
Step 2 — Unblock downloaded files:
Files downloaded via Invoke-WebRequest are marked as "from the internet" by Windows. Under RemoteSigned execution policy (default on Windows 10/11), these are blocked. Run:
Step 3 — Check execution policy:
The hooks.json already includes -ExecutionPolicy Bypass in the powershell command, which overrides the policy per-invocation regardless of system settings.
Check Logs for Errors
Events Not in Dashboard
Hook Timing Out
Increase timeoutSec in hooks.json (value in seconds, e.g. "timeoutSec": 60). Ensure AKTO_DATA_INGESTION_URL is reachable from your machine.
Permission Denied on Scripts
Uninstallation
Complete Removal
Selective Removal (Keep Logs)
Backup Before Removal
Verify Removal
Enterprise Deployment
Automated Deployment Script
macOS / Linux:
Windows (PowerShell) — works on Azure Virtual Desktop pooled sessions:
Deploy to developers (Windows):
Quick Setup Summary
Resources
GitHub Copilot CLI: https://github.com/features/copilot/cli
Support: [email protected]
Community: https://www.akto.io/community
Last updated