Docs

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

SurfaceEnforcement
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
PromptsBlock or warn before the agent continues
MCP tool callsBlock, warn, allow-list, or audit
Web fetch/searchEnforced 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 nameAgent Keeper canonical name
run_shell_commandBash
read_fileRead
read_many_filesGlob
write_fileWrite
replace, editEdit
search_file_contentGrep
web_fetchWebFetch
mcp__server__toolMCP skill policy

Verify coverage

  1. Open the project with Gemini CLI after installing hooks.
  2. Ask Gemini to run pwd.
  3. Check Activity for a gemini event.
  4. 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.