Gemini CLI Setup
Agent Keeper integrates with Gemini CLI through command hooks. The Gemini adapter converts hook payloads into Agent Keeper's canonical Bash, Read, Write, Edit, Grep, Glob, WebFetch, and MCP skill events.
What gets monitored
| Surface | Enforcement |
|---|---|
Shell commands (run_shell_command) | Block or warn before execution |
File reads (read_file, read_many_files) | Block, warn, or audit based on read-path policy |
File writes and edits (write_file, replace) | Block or warn before execution |
| Prompts | Block or warn before the agent continues |
| MCP tool calls | Block, warn, allow-list, or audit |
| Web fetch/search | Enforced when Gemini emits the tool event |
Installation
Get your API key from Settings > API Keys, then run the public installer:
export AGENTKEEPER_API_URL="https://YOUR_AGENTKEEPER_URL"
export AGENTKEEPER_API_KEY="ak_live_..."
bash <(curl -fsSL "$AGENTKEEPER_API_URL/install-hooks.sh") --ide gemini
The installer stores the API key in ~/.agentkeeper/config, installs ~/.agentkeeper/hooks/gemini/agentkeeper-hook.sh, and updates ~/.gemini/settings.json.
Generated config
{
"hooksConfig": {
"enabled": true
},
"hooks": {
"BeforeTool": [
{
"matcher": "*",
"hooks": [
{
"name": "agentkeeper",
"type": "command",
"command": "~/.agentkeeper/hooks/gemini/agentkeeper-hook.sh",
"timeout": 5000
}
]
}
],
"AfterTool": [
{
"matcher": "*",
"hooks": [
{
"name": "agentkeeper",
"type": "command",
"command": "~/.agentkeeper/hooks/gemini/agentkeeper-hook.sh",
"timeout": 5000
}
]
}
],
"BeforeAgent": [
{
"matcher": "*",
"hooks": [
{
"name": "agentkeeper",
"type": "command",
"command": "~/.agentkeeper/hooks/gemini/agentkeeper-hook.sh",
"timeout": 5000
}
]
}
]
}
}
Gemini uses process exit codes for enforcement. The adapter exits 0 to allow and 2 to block, with the block reason written to stderr.
Tool name mapping
| Gemini CLI tool name | Agent Keeper canonical name |
|---|---|
run_shell_command | Bash |
read_file | Read |
read_many_files | Glob |
write_file | Write |
replace, edit | Edit |
search_file_content | Grep |
web_fetch | WebFetch |
mcp__server__tool | MCP skill policy |
Verify coverage
- Open the project with Gemini CLI after installing hooks.
- Ask Gemini to run
pwd. - Check Activity for a
geminievent. - Toggle Team → Policies → AI Coding Agents → Access Control → Gemini CLI to disable or re-enable org-wide access.
Notes
The adapter is fail-open on errors and timeouts. If Agent Keeper is unavailable, Gemini continues normally; when the API is reachable, all policy decisions are attributed to the gemini detection layer for filtering, alerts, and audit export.