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): Set environment variables, invoke Python scripts

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

  • 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

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 or Linux with bash/zsh

Installation Steps

1

Create the Hooks Directory

2

Download Hook Scripts

3

Configure Akto Ingestion URL ⚠️ CRITICAL STEP

circle-exclamation

Automated replacement:

Manual replacement (alternative):

Edit each wrapper script and replace:

With:

Files to update:

  • akto-validate-prompt-wrapper.sh

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

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

4

Verify hooks.json Configuration

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

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:

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

Check logs to confirm hooks are working:

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

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

Deploy to developers:

Quick Setup Summary

Resources

Last updated