gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Feature Request: Improve `AfterAgent` hook to support precise task completion notifications

Open RyderFreeman4Logos opened this issue 1 year ago • 0 comments

What would you like to be added?

Context & Workflow

I frequently use the Gemini CLI on a remote workstation (e.g., via SSH) for long-running coding tasks. Since I am not physically near the machine, I cannot rely on system desktop notifications or sounds.

To monitor progress, I have configured the AfterAgent hook to execute a script that sends a notification to my Telegram account (via a Telegram Bot API). This approach is extremely flexible and ensures I receive alerts on all my devices (phone, smart watch, laptop) no matter where I am.

The Problem

Currently, the AfterAgent hook fires at the end of every turn in the conversation loop. This includes:

  1. When the agent finishes generating text and is waiting for the user.
  2. When the agent generates a tool call (e.g., run_shell_command) and pauses to wait for the tool's output.

Because the hook cannot distinguish between these two states, my notification script fires every time the agent pauses to run a command. This results in a flood of "Task Complete" notifications during multi-step tasks, rendering the alerts useless and annoying. I only want to be notified when the agent has fully completed its current chain of thought and is waiting for my input.

Proposed Solution

I propose adding a has_pending_tool_calls boolean field to the input JSON passed to AfterAgent hooks.

This would allow my hook script to implement simple logic:

#!/bin/bash
# Read JSON from stdin
INPUT=$(cat)

# Check if there are pending tools
HAS_PENDING=$(echo "$INPUT" | jq -r '.has_pending_tool_calls')

if [ "$HAS_PENDING" == "true" ]; then
  # Agent is just running a tool, not done yet. Do nothing.
  exit 0
fi

# Agent is actually waiting for user input. Send notification.
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
     -d chat_id="$CHAT_ID" \
     -d text="Gemini Task Complete: $(echo "$INPUT" | jq -r '.prompt')"

Why is this needed?

Why this matters

  • Remote Work: Essential for users who work on headless servers or remote desktops.
  • Flexibility: Command hooks allow integration with any service (Telegram, Slack, Discord, PagerDuty) via standard CLI tools like curl.
  • Signal-to-Noise: Eliminates false positives, making notifications meaningful agaim.

Additional context

No response

RyderFreeman4Logos avatar Dec 05 '25 20:12 RyderFreeman4Logos