Contents
Gemini CLI integration

Gemini CLI push notifications

Gemini CLI hooks can alert your phone through PushPiper when the agent finishes or needs you, free for 10,000 messages a month on 10 devices. Hooks arrived in Gemini CLI v0.26.0 and run shell commands on specific events; a short bash script with a 10,000 millisecond timeout does the rest.

How Gemini CLI hooks handle notifications

Gemini CLI runs commands based on internal events, which makes it straightforward to push updates whenever an agent finishes or pauses. The hook system is active out of the box because the hooksConfig.enabled setting defaults to true. You don't need external process watchers or background daemons monitoring your terminal output.

When an event triggers, Gemini CLI passes payload data as JSON directly to your hook's standard input. For routine completions, the AfterAgent event provides both the original user prompt and the final agent response. For situations where Gemini needs manual approval, such as a tool permission prompt, the Notification event triggers with details about the required input.

The CLI enforces a strict rule on hook commands: standard output must contain only valid JSON. If your script outputs plain status text, progress bars, or error logs to stdout, Gemini cannot parse the output as a JSON object. That's why hook scripts must redirect command output elsewhere and print an empty JSON object before exiting.

Here is how the two primary hook events compare in their triggers and urgency levels:

EventFires whenPriority in the script
NotificationGemini needs attention, for example a tool permission request1
AfterAgentGemini finished a turn0

Create the PushPiper notification script

To forward events to your devices, create a small shell script that reads the hook payload from stdin, inspects the event type, and posts the notification payload to PushPiper. First, make sure you have an account by opening the PushPiper web app to grab your user key and generate an application token.

Save the following script to ~/.gemini/hooks/pushpiper.sh:

~/.gemini/hooks/pushpiper.sh
#!/usr/bin/env bash
input=$(cat)
event=$(jq -r '.hook_event_name' <<<"$input")

if [ "$event" = "Notification" ]; then
  title="Gemini CLI needs you"
  message=$(jq -r '.message // "Waiting for approval"' <<<"$input")
  priority=1
else
  title="Gemini CLI finished"
  message=$(jq -r '(.prompt_response // "Done")[0:1000]' <<<"$input")
  priority=0
fi

curl -s -o /dev/null https://api.pushpiper.com/1/messages.json \
  --form-string "token=APP_TOKEN" \
  --form-string "user=USER_KEY" \
  --form-string "title=$title" \
  --form-string "message=$message" \
  --form-string "priority=$priority" >/dev/null 2>&1

echo '{}'

Before using the script, update two placeholder values:

  • Replace APP_TOKEN with your 30-character application token that starts with a.
  • Replace USER_KEY with your 30-character user key that starts with u.

Make sure to mark the script executable by running chmod +x ~/.gemini/hooks/pushpiper.sh in your terminal. You also need jq installed on your machine so the script can extract hook_event_name, message, and prompt_response from Gemini's JSON payload.

Notice how the script handles output. The curl command pipes standard output to /dev/null using -o /dev/null, and standard error is redirected with >/dev/null 2>&1. At the very end, echo '{}' provides the exact JSON response Gemini expects on stdout. If you run other tools like Claude Code alongside Gemini, you'll recognize a similar pattern for handling command hooks without breaking CLI parsers.

Configure your Gemini CLI settings

Gemini CLI reads its hook configurations from settings.json. You can define hooks globally for all directories or locally for a single repository:

  • Global settings: ~/.gemini/settings.json applies to every Gemini CLI session on your machine.
  • Local settings: .gemini/settings.json in your current working directory applies only to that workspace.

Open your settings file and register the script under both Notification and AfterAgent:

~/.gemini/settings.json
{
  "hooks": {
    "Notification": [
      {
        "matcher": "*",
        "hooks": [
          {
            "name": "pushpiper-needs-you",
            "type": "command",
            "command": "~/.gemini/hooks/pushpiper.sh",
            "timeout": 10000
          }
        ]
      }
    ],
    "AfterAgent": [
      {
        "matcher": "*",
        "hooks": [
          {
            "name": "pushpiper-finished",
            "type": "command",
            "command": "~/.gemini/hooks/pushpiper.sh",
            "timeout": 10000
          }
        ]
      }
    ]
  }
}

The configuration assigns a timeout of 10000 milliseconds for each hook run, giving the network call 10 seconds to finish before Gemini abandons the hook. The matcher field is set to * to catch every prompt and permission request.

Once you save the file, restart Gemini CLI. The CLI loads hook definitions during startup, so changes made to settings.json while a session is running won't take effect until you start a fresh session.

Handling priorities and message limits

PushPiper uses numerical priorities to govern how alerts appear on your phone or desktop:

  • Priority 0 (Normal): Delivers a standard notification with sound, but respects your device's quiet hours. This is what the script uses for AfterAgent turns.
  • Priority 1 (High): Bypasses PushPiper quiet hours and rings with high urgency, which the script assigns to Notification events when Gemini CLI is paused waiting for you to approve a tool.
  • Priority 2 (Emergency): Requires retry (at least 30 seconds) and expire (at most 3 hours), and repeats until someone acknowledges it, it expires, or it reaches 50 repeats.
  • Priority -1 (Low) and -2 (Lowest): Silent notifications or silent inbox-only drops.

PushPiper's API rejects any message body longer than 1,024 characters with an HTTP 400 error. Because Gemini's prompt_response can span multiple paragraphs or pages of text, the script trims responses down using jq slice notation: [0:1000]. This ensures the payload fits well within PushPiper's 1,024-character cap while leaving room for fallback text. If you want to customize titles or sounds further, see the API reference for all supported parameters.

You can also use this same API endpoint to send a push notification to your phone from automated cron jobs, continuous integration runners, or other local scripts without installing third-party package dependencies.

Testing the setup

To verify the integration works before running large tasks, launch Gemini CLI and run a command that invokes a tool requiring approval. You should receive a high-urgency notification on your registered devices with the title "Gemini CLI needs you" and the approval prompt text.

Next, submit a prompt that completes quickly. As soon as the model finishes generating its answer, Gemini triggers the AfterAgent event. A normal-priority notification with the title "Gemini CLI finished" and the first 1,000 characters of the response will arrive on your phone.

If an alert fails to arrive, check whether ~/.gemini/hooks/pushpiper.sh has executable permissions. You can also run the script manually by piping a test JSON string like '{"hook_event_name":"AfterAgent","prompt_response":"Test completed"}' into it to verify that curl reaches the PushPiper API and prints {} to the terminal.

Sources

Questions and answers

Does PushPiper have native apps in the App Store or Google Play?

PushPiper does not have native App Store or Play Store apps yet. It installs directly from your browser as a Web Push application on Android, Windows, macOS, Linux, and iOS or iPadOS 16.4 and later.

Can PushPiper priority 1 or 2 alerts break through Apple Do Not Disturb?

No, PushPiper cannot send iOS critical alerts that break through Do Not Disturb or Focus modes. High and emergency priorities bypass PushPiper's internal quiet hours setting, but operating system focus restrictions still apply.

Where can I find my PushPiper token and user key?

Sign in to the PushPiper web app with Google. In the app you get your 30-character user key (starts with u) and a 30-character app token (starts with a).

What happens if my script outputs normal text instead of JSON?

Gemini CLI expects valid JSON on standard output from hook commands. A hook must print only a JSON object to stdout (sending any other output to /dev/null or stderr) and exit 0 so Gemini can parse stdout.

What happens when I exceed the 10,000 free messages per month?

Once you hit your monthly message limit, the PushPiper API answers with an HTTP 429 status code until quotas reset on the 1st of the month at 00:00 UTC, unless you add extra message packs.