Notes
Phone Notifications for Claude Code
I often have several Claude Code sessions running at once, sometimes on different machines. Most of the time, a session is either working on its own or waiting on me to answer a question or approve a command. Rather than continuously switching between terminals to check which sessions are stuck, I set up a Claude Code hook that sends a push notification to my phone whenever a session is idle and needs my input. That lets me walk away from my computer and come back only when Claude actually needs me.
The Notify Script
My dotfiles have a
bin/notify
script on my PATH that sends a message to a self-hosted
ntfy server, which then pushes it to the ntfy app on my
phone:
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
source ~/.ssh/other/ntfy.sh
MESSAGE="${1:-"notification"}"
curl \
--header "Title: $MESSAGE" \
--header "Priority: high" \
--header "Tags: envelope_with_arrow" \
--user "$NTFY_USERNAME:$NTFY_PASSWORD" \
--data "$MESSAGE" \
"$NTFY_ADDRESS/claude"
The server address and credentials are kept in a separate file outside of the dotfiles repository so the script itself can be public:
# ~/.ssh/other/ntfy.sh
NTFY_ADDRESS="https://ntfy.example.com"
NTFY_USERNAME="username"
NTFY_PASSWORD="password"
On my phone, I subscribe to the claude topic in the ntfy
Android app
(there’s also an iOS app). If you don’t
want to host your own server, the public ntfy.sh server
works too. Pick a hard-to-guess topic name since public topics aren’t
password protected.
The notify command is also useful on its own outside of Claude Code. For
example, when I kick off a long build or data job, I chain notify to the end
of it so I get a callback on my phone when it’s done instead of checking back
on the terminal:
make build; notify "build finished"
The Claude Code Hooks
Claude Code hooks run shell commands
when certain events happen in a session. I call notify from three of them in
my global settings
(settings_personal.json
in my dotfiles, which gets merged into ~/.claude/settings.json):
"hooks": {
"Notification": [{
"matcher": "",
"hooks": [{"type": "command", "command": "notify claude"}]
}],
"PermissionRequest": [{
"matcher": "",
"hooks": [{
"type": "command",
"command": "notify \"$(jq -r '\"Claude needs permission: \" + .tool_name')\" 2>/dev/null || true"
}]
}],
"StopFailure": [{
"matcher": "",
"hooks": [{
"type": "command",
"command": "notify \"Claude error: $(jq -r '.stop_reason // \"unknown\"' 2>/dev/null || echo 'unknown')\" 2>/dev/null || true"
}]
}]
}
Notificationfires when Claude Code is idle and waiting for my input. This is the main one.PermissionRequestfires when Claude wants to run a tool that needs my approval. Hooks receive the event details as JSON on stdin, sojqpulls out the tool name to put in the notification, e.g. “Claude needs permission: Bash”.StopFailurefires when a session stops because of an error, so I don’t come back hours later to find a session that died early.
The || true suffixes keep a failed notification (e.g. on a machine without
the ntfy credentials) from interfering with Claude Code itself.
Fewer Interruptions
Notifications are only useful if they’re meaningful. If Claude asks for
permission to run ls or git diff every few minutes, my phone would never
stop buzzing. So the same settings file also has an allowlist of read-only
commands that Claude can run without asking:
"permissions": {
"allow": [
"Bash(cat *)",
"Bash(git diff *)",
"Bash(git log *)",
"Bash(grep *)",
"Bash(ruff check *)",
...
],
"defaultMode": "auto",
"deny": [
"Bash(git push *)"
]
}
With that, a notification on my phone almost always means a session has finished its work or needs a real decision from me.