AlphornAlphorn Docs

Gemini CLI

Get notified when Gemini CLI finishes a response or needs tool permission. Gemini CLI hooks (AfterAgent, Notification) that send to Slack, Telegram, or SMS.

Gemini CLI runs commands on agent events through hooks. Two events matter for notifications:

  • AfterAgent - the agent finished a response.
  • Notification - Gemini CLI needs your attention, for example to approve a tool (notification_type is ToolPermission).

1. Create the hook script

~/.gemini/hooks/alphorn-notify.sh
#!/usr/bin/env bash
# Forwards Gemini CLI AfterAgent and Notification hook events to Alphorn.
jq -c '{
  title: ("Gemini CLI - " + (.cwd | split("/") | last)),
  message: (if .hook_event_name == "Notification"
            then (.message // "Needs your attention")
            else (.prompt_response // "Finished") end),
  priority: (if .hook_event_name == "Notification" then 4 else 2 end),
  tags: ["ai-agent", "gemini-cli",
         (if .hook_event_name == "Notification" then "permission" else "completed" end)]
}' | curl -fsS --max-time 5 -X POST https://app.alphorn.dev/n/V1StGXR8_Z5jdHi6B-myT \
  -H "Authorization: Bearer $ALPHORN_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- > /dev/null
exit 0
chmod +x ~/.gemini/hooks/alphorn-notify.sh

The script prints nothing and exits 0. Gemini CLI parses the output of a successful hook as JSON, and exit code 2 blocks.

2. Register the hooks

~/.gemini/settings.json
{
  "hooks": {
    "AfterAgent": [
      {
        "matcher": "*",
        "hooks": [
          { "name": "alphorn-done", "type": "command", "command": "~/.gemini/hooks/alphorn-notify.sh", "timeout": 10000 }
        ]
      }
    ],
    "Notification": [
      {
        "matcher": "*",
        "hooks": [
          { "name": "alphorn-input", "type": "command", "command": "~/.gemini/hooks/alphorn-notify.sh", "timeout": 10000 }
        ]
      }
    ]
  }
}

timeout is in milliseconds in Gemini CLI. Use .gemini/settings.json in a project to enable the hooks only there. ALPHORN_API_KEY must be set in the environment Gemini CLI runs in. In some older Gemini CLI versions hooks had to be enabled in settings.json first, so if they never fire, update Gemini CLI or check its hooks docs for your version.

Event fields

EventUseful fields
Allsession_id, cwd, hook_event_name, timestamp
AfterAgentprompt, prompt_response (the agent's final text)
Notificationnotification_type, message, details

See AI Agent Notifications for routing conventions and an AGENTS.md snippet that lets the agent send notifications on its own.

On this page