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:

spinner

3 Hook Points:

  1. userPromptSubmitted - Monitors prompts when submitted to Copilot (reporting only, cannot block)

  2. preToolUse - Validates tool use before execution and can block dangerous operations

  3. postToolUse - Ingests tool execution results for monitoring and audit

circle-exclamation

File Structure

Key Files:

  • Wrapper scripts (.sh / .ps1): Set environment variables, invoke Python scripts

    • ⚠️ Contains AKTO_DATA_INGESTION_URL placeholder - Must be set to your Akto instance URL

    • .sh used on macOS/Linux; .ps1 used on Windows

  • Python scripts (.py): Core validation logic and Akto API communication

  • akto_machine_id.py: Generates unique device identifiers for Atlas mode

  • hooks.json: Links hooks to wrapper scripts — uses bash key on macOS/Linux and powershell key on Windows

Note: hooks.json is 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

1

Create the Hooks Directory

macOS / Linux:

Windows (PowerShell):

2

Download Hook Scripts

macOS / Linux:

Windows (PowerShell):

3

Configure Akto Ingestion URL ⚠️ CRITICAL STEP

circle-exclamation

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.sh

  • akto-validate-pre-tool-wrapper.sh

  • akto-validate-post-tool-wrapper.sh

Files to update on Windows:

  • akto-validate-prompt-wrapper.ps1

  • akto-validate-pre-tool-wrapper.ps1

  • akto-validate-post-tool-wrapper.ps1

4

Verify hooks.json Configuration

The hooks.json file should already be configured after downloading. Verify it contains all three hooks:

Windows note: The powershell key is used automatically on Windows. The .ps1 wrapper sets all required environment variables before invoking the Python script — equivalent to what the .sh wrappers do on macOS/Linux.

Note: timeoutSec is in seconds (30 = 30 seconds). Hooks are loaded from .github/hooks/hooks.json in the directory you run copilot from.

5

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; preToolUse blocks dangerous tool executions

  • false: Monitoring only; all tool executions pass through but are logged

6

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

Last updated