Claude CLI Hooks

Akto Guardrails for Claude CLI provides security validation for AI interactions. It intercepts prompts before sending to Claude and responses after generation, 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 Claude CLI's native hook mechanism

  • βœ… Real-time Protection - Validates every prompt and response

  • βœ… Centralized Monitoring - All events reported to Akto dashboard

  • βœ… Flexible Deployment - Supports Argus and Atlas modes

  • βœ… Configurable Behavior - Blocking or observation modes

How It Works

Claude CLI's hook system executes custom scripts at two critical points:

spinner

2 Hook Points:

  1. UserPromptSubmit - Validates prompts before sending to Claude API

  2. Stop - Validates responses when Claude finishes generating

File Structure

Key Files:

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

    • ⚠️ Contains AKTO_DATA_INGESTION_URL placeholder - Must be replaced with 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

  • settings.json: Links hooks to wrapper scripts

Setup Guide

Prerequisites

Installation Steps

1

Create Directories

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

4

Configure Hooks

Create Claude CLI settings configuration:

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: Blocks threats

  • false: Reports but allows execution

6

Install Python Dependencies

7

Verify Installation

Check logs to confirm hooks are working:

Test by running a Claude command:

You should see log entries indicating validation occurred.

Configuration Reference

Wrapper Script Variables

Environment Variables (Optional)

Override defaults via environment variables or config file:

Option 1: Environment variables

Option 2: Config file

Troubleshooting

Hooks Not Executing

Ingestion URL Not Configured

Check Logs for Errors

Events Not in Dashboard

Python Dependencies Missing

Uninstallation

To completely remove Akto hooks from Claude CLI:

Complete Removal

Selective Removal (Keep Logs)

If you want to preserve logs for audit purposes:

Backup Before Removal

Verify Removal

Restore Claude CLI to Default

After uninstallation, Claude CLI will operate without Akto security monitoring. No additional configuration is needed beyond removing the files. Test with:

Enterprise Deployment

Automated Deployment Script

Deploy to developers:

Comparison with Cursor Hooks

Feature
Claude CLI Hooks
Cursor Hooks

Platform

Claude CLI

Cursor IDE

Hook Points

2 (Prompt + Response)

4 (Chat + MCP, each with req/resp)

Chat Monitoring

βœ… Yes (UserPromptSubmit, Stop)

βœ… Yes (beforeSubmitPrompt, afterAgentResponse)

MCP Tool Monitoring

❌ No

βœ… Yes (beforeMCPExecution, afterMCPExecution)

Total Files

6 files (2 wrappers, 2 Python, 1 utility, 1 config)

10 files (4 wrappers, 4 Python, 1 utility, 1 config)

Configuration File

~/.claude/settings.json

~/.cursor/hooks.json

Log Location

~/.claude/akto/logs/

~/.cursor/akto/chat-logs/ + ~/.cursor/akto/mcp-logs/

Setup Complexity

Fewer files, simpler

More files, more comprehensive

See also: Cursor Hooks for Cursor IDE setup

Quick Setup Summary

Resources

Last updated