Gemini CLI Hooks

Akto Guardrails for Gemini CLI provides security validation for AI interactions. It intercepts prompts before sending to Gemini 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 Gemini 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 (project or user-level)

  • Configurable Behavior - Blocking or observation modes

How It Works

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

spinner

2 Hook Points:

  1. BeforeModel - Validates prompts before sending to Gemini API

  2. AfterModel - Ingests prompt/response when Gemini finishes (final chunk)

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

Note: Gemini CLI also supports project-level setup (.gemini/hooks/ and .gemini/settings.json in your project root). Config precedence: project → user → system.

Setup Guide

Prerequisites

  • Gemini CLI installed and configured (Gemini CLIarrow-up-right)

  • Akto instance URL

  • Python 3

  • macOS, Windows or Linux with bash/zsh

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 Gemini CLI settings configuration (user-level):

Note: Timeout is in milliseconds (10000 = 10 seconds). For project-level setup, use .gemini/settings.json and $GEMINI_PROJECT_DIR/.gemini/hooks/ in the command paths.

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

Verify Installation

Check logs to confirm hooks are working:

Test by running a Gemini command:

You should see log entries or hook activity. In Gemini CLI, use /hooks panel to view hook execution status.

Configuration Reference

Wrapper Script Variables

Environment Variables (Optional)

Override defaults via environment variables (e.g. in ~/.bashrc or ~/.zshrc):

Managing Hooks (Gemini CLI)

Command
Description

/hooks panel

View hook execution status and recent output

/hooks enable-all

Enable all hooks

/hooks disable-all

Disable all hooks

/hooks enable <name>

Enable a specific hook

/hooks disable <name>

Disable a specific hook

Troubleshooting

Hooks Not Executing

Ingestion URL Not Configured

Check Logs for Errors

Events Not in Dashboard

Hook Timing Out

Increase timeout in ~/.gemini/settings.json (value in milliseconds, e.g. "timeout": 120000). Ensure AKTO_DATA_INGESTION_URL is reachable.

Uninstallation

To completely remove Akto hooks from Gemini CLI:

Complete Removal

Selective Removal (Keep Logs)

If you want to preserve logs for audit purposes:

Backup Before Removal

Verify Removal

Restore Gemini CLI to Default

After uninstallation, Gemini 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:

Quick Setup Summary

Resources

Last updated