DEV Community

Cover image for Push Claude Code Updates to Your Phone with ntfy
Israel Saba
Israel Saba

Posted on

Push Claude Code Updates to Your Phone with ntfy

I'll show how your can get notified, on your phone and on your laptop when Claude Code needs your input to move on or when it finishes.

Below should be a quick and simple win already. A debounce strategy and a self-host option will eventually be added.

Simplest strategy [NTFY cloud and no debounce]

NTFY

  1. Sign-up at ntfy.sh
  2. Sign-in and access your dashboard
  3. Click Subscribe to topic
  4. Click GENERATE NAME -> SUBSCRIBE and take note of the topic
  5. Click on your avatar at the top -> Click your username
  6. At Access tokens click Create access token and choose a name (e.g. claude-code)
  7. take note of your token
  8. Download NTFY app to your mobile and enable notifications
  9. Sign-in to your ntfy account in the app (make sure you are subscribed to topic created on 4.)

Claude Code

  1. Edit ~/.claude/settings.json (create if needed) to have it as below
{
  "hooks": {
    "PermissionRequest": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "curl -H 'Authorization: Bearer <token-ntfy-step-7>' -v -L -d 'Claude Code is requesting your input to move on' ntfy.sh/<topic-ntfy-step-4>"
          }
        ]
      }
    ],
"Stop": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "curl -H 'Authorization: Bearer <token-ntfy-step-7>' -v -L -d 'Claude Code has finished working' ntfy.sh/<topic-ntfy-step-4>"
          }
        ]
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

Start a new claude session and enjoy!

Adding de-bouncer

To avoid multiple notifications at the same time we can add a debouncer.

  • Create the de-bouncer script at the path below
#!/usr/bin/env bash
set -euo pipefail

LOCKFILE="/tmp/claude-notify-last"
COOLDOWN=30  # seconds

if [ -f "$LOCKFILE" ]; then
  LAST=$(cat "$LOCKFILE")
  NOW=$(date +%s)
  if [ $((NOW - LAST)) -lt $COOLDOWN ]; then
    exit 0
  fi
fi

date +%s > "$LOCKFILE"

MSG="${1:-}"  # first argument
if [ -z "$MSG" ]; then
  echo "Usage: $0 \"message\"" >&2
  exit 2
fi

curl -H 'Authorization: Bearer <token>' -L \
  --data-binary "$MSG" \
  "https://ntfy.sh/<topic-ntfy-step-4>"
Enter fullscreen mode Exit fullscreen mode
  • Chmod the script chmod +x .claude/scripts/ntfy-debouncer.sh
  • Update claude to use it
{
  "hooks": {
    "PermissionRequest": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "./scripts/ntfy-debouncer.sh 'Claude Code is requesting your input to move on'"
          }
        ]
      }
    ],
"Stop": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "./scripts/ntfy-debouncer.sh 'Claude Code has finished working'"
          }
        ]
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)