Codex CLI Hooks
Akto Guardrails for Codex provides comprehensive security monitoring and validation for both chat interactions and tool executions — and works with both Codex CLI and Codex Desktop. It intercepts prompts before sending to Codex, validates tool calls before execution, blocks risky behavior, and reports all events to your Akto dashboard.
Key Features
✅ Zero Installation - No standalone apps to install
✅ Transparent Integration - Uses Codex's native hook mechanism (CLI and Desktop)
✅ Real-time Protection - Validates every prompt and tool call
✅ Centralized Monitoring - All events reported to Akto dashboard
✅ Flexible Deployment - Supports Argus and Atlas modes
✅ Configurable Behavior - Blocking or observation modes
✅ Auto-detected API Host - Automatically resolves Codex API endpoint from environment
How It Works
Codex's hook system (shared by both CLI and Desktop) executes custom scripts at four critical points:
4 Hook Points:
UserPromptSubmit- Validates prompts before sending to Codex APIStop- Ingests prompt/response pair when Codex finishes generatingPreToolUse- Validates tool requests before execution (blocks if malicious)PostToolUse- Ingests tool input/output after execution (observational only)
Note: Codex currently only supports the
Bashtool forPreToolUseandPostToolUsehooks (both CLI and Desktop).
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 and ingestion logic, Akto API communicationakto_machine_id.py: Generates unique device identifiers for Atlas modehooks.json: Links hooks to wrapper scriptsconfig.toml: Must enable thecodex_hooksfeature flag
Setup Guide
Prerequisites
Codex CLI or Codex Desktop installed
Akto instance URL
Python 3.7+
macOS, Linux, or Windows with bash/zsh
Installation Steps
Enable Codex Hooks Feature Flag
Codex hooks are experimental. Enable them in ~/.codex/config.toml (used by both CLI and Desktop):
Create Directories
Download Hook Scripts
Configure Akto Ingestion URL ⚠️ CRITICAL STEP
All wrapper scripts contain placeholder {{AKTO_DATA_INGESTION_URL}} that must be replaced with your actual Akto instance URL.
Automated replacement:
Manual replacement (alternative):
Edit each wrapper script and replace:
With:
Files to update:
akto-validate-prompt-wrapper.shakto-validate-response-wrapper.shakto-validate-pre-tool-wrapper.shakto-validate-post-tool-wrapper.sh
Configure Hooks
Copy hooks.json to ~/.codex/hooks.json:
Note: You can also place
hooks.jsonat<repo>/.codex/hooks.jsonfor repository-level hooks.
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 (prompt validation + tool validation)
false: Reports but allows execution
Verify Installation
Check logs to confirm hooks are working:
Test by running a Codex command:
CLI:
codex "What is 2+2?"Desktop: Open Codex Desktop and send a message in the chat
You should see log entries indicating validation occurred.
Configuration Reference
Wrapper Script Variables
Environment Variables (Optional)
Override defaults via environment variables in ~/.zshrc or ~/.bashrc:
Then reload your shell:
Codex API Host Auto-Detection
The Codex API host and path are automatically resolved from the same environment variables Codex CLI uses:
OPENAI_BASE_URL set
value of OPENAI_BASE_URL
/v1/responses
OPENAI_API_KEY set
api.openai.com
/v1/responses
ChatGPT browser login
chatgpt.com
/backend-api/codex/responses
Hook Input Fields
All hooks receive a common JSON payload on stdin, plus event-specific fields:
UserPromptSubmit
prompt
Stop
last_assistant_message, stop_hook_active
PreToolUse
tool_name, tool_use_id, tool_input
PostToolUse
tool_name, tool_use_id, tool_input, tool_response
Troubleshooting
Hooks Not Executing
Ingestion URL Not Configured
Check Logs for Errors
Events Not in Dashboard
Service Unavailable
If Akto is unreachable:
With
AKTO_SYNC_MODE=true: hooks fail open and allow execution (fail-safe)With
AKTO_SYNC_MODE=false: hooks skip ingestion silently
Uninstallation
To completely remove Akto hooks from Codex CLI or Codex Desktop:
Complete Removal
Selective Removal (Keep Logs)
Backup Before Removal
Verify Removal
Restore Codex to Default
After uninstallation, Codex CLI and Codex Desktop will operate without Akto security monitoring. Test with:
CLI:
codex "Test message"Desktop: Open Codex Desktop and send a message — no hook logs should appear
Enterprise Deployment
Automated Deployment Script
Deploy to developers:
Quick Setup Summary
Resources
Support: [email protected]
Community: https://www.akto.io/community
Last updated