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:
2 Hook Points:
BeforeModel- Validates prompts before sending to Gemini APIAfterModel- 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_URLplaceholder - Must be replaced with your Akto instance URL
Python scripts (
.py): Core validation logic and Akto API communicationakto_machine_id.py: Generates unique device identifiers for Atlas modesettings.json: Links hooks to wrapper scripts
Note: Gemini CLI also supports project-level setup (
.gemini/hooks/and.gemini/settings.jsonin your project root). Config precedence: project → user → system.
Setup Guide
Prerequisites
Gemini CLI installed and configured (Gemini CLI)
Akto instance URL
Python 3
macOS, Windows or Linux with bash/zsh
Installation Steps
Create Directories
Download Hook Scripts
Configure Akto Ingestion URL and API Token ⚠️ CRITICAL STEP
All wrapper scripts contain the placeholders {{AKTO_DATA_INGESTION_URL}} and {{AKTO_API_TOKEN}} that must be replaced — the URL with your actual Akto instance URL, and the token with your Akto API token (obtain it from Akto Atlas → Connectors → Setup Guardrail card). If your deployment does not require auth, set the token to an empty string so the placeholder is removed (an unsubstituted {{AKTO_API_TOKEN}} would be sent as an invalid Authorization header).
Automated replacement:
Manual replacement (alternative):
Edit each wrapper script and replace:
With:
Files to update:
akto-validate-prompt-wrapper.shakto-validate-response-wrapper.sh
Configure Hooks
Create Gemini CLI settings configuration (user-level):
Note: Timeout is in milliseconds (10000 = 10 seconds). For project-level setup, use
.gemini/settings.jsonand$GEMINI_PROJECT_DIR/.gemini/hooks/in the command paths.
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
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)
/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
Gemini CLI: https://geminicli.com/
Support: support@akto.io
Community: https://www.akto.io/community
Last updated