Get an Android notification when Claude Code finishes a turn
6 min read
Published · Updated
A Claude Code Stop hook can send your phone a message when Claude finishes responding. Merge this entry into ~/.claude/settings.json on the machine running Claude Code. It calls the pushbag CLI with a fixed message, so prompts and command output stay out of your notifications.
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "pushbag notify 'Claude Code finished its turn' --title 'Claude Code' >/dev/null"
}
]
}
]
}
}
Register your phone and test the channel
Install Pushbag from Google Play, allow notifications, and sign in using the same account you use in the dashboard. Signing in registers the device. The Android setup guide also covers pairing with a code.
On the machine that runs Claude Code, install the CLI and open the key setup flow:
npm install -g @pushbag/cli
pushbag auth login
Create a Notifications key that can publish to your personal channel. Follow the printed instructions to save it, or provide it through PUSHBAG_API_KEY in Claude Code’s environment. Test the delivery path before enabling the hook:
pushbag notify 'Phone delivery test' --title 'Claude Code'
The CLI prints Sent to CHANNEL_ID (MESSAGE_ID), with the actual identifiers filled in. Check your phone for the test message. If it appears in the web dashboard only, check the account and notification permission on the phone.
Test the hook
Open a new Claude Code session and ask for a short reply. Expect one message when Claude finishes that response. A turn can end with a question or a summary of unfinished work, so use the alert as a cue to read the reply. If the manual test worked but the hook cannot find pushbag, use the executable’s absolute path in the hook.
To limit the hook to your own copy of one project, use .claude/settings.local.json there instead of the user settings file. See Claude Code’s hook reference and the agent notification guide.
Only page me after a long turn
The simple hook is enough for an unattended session. If you use Claude while sitting at your terminal, a one-line answer probably doesn’t warrant a phone alert. Measure the interval between UserPromptSubmit and Stop instead. The first event gives the hook a place to start the clock. The second tells it when to read the clock and decide whether to send. A two-minute threshold includes the time you spend waiting on a permission dialog, which matters if you want to measure how long you’ve been away.
Here is a complete replacement for the simple configuration above. This version is for macOS or Linux with Python 3. Place it in the project’s .claude/settings.local.json. Merge the two event entries if the file already has hooks. Remove the earlier unconditional Stop command if you installed it globally, or both hooks will run on a long turn.
{
"hooks": {
"UserPromptSubmit": [{
"hooks": [{
"type": "command",
"command": "python3 \"$HOME/.claude/pushbag-turn.py\""
}]
}],
"Stop": [{
"hooks": [{
"type": "command",
"command": "python3 \"$HOME/.claude/pushbag-turn.py\""
}]
}]
}
}
Save the following script at ~/.claude/pushbag-turn.py. The hook receives one JSON object on standard input. The same script handles both events so that both ends of the timer use the same session identifier and clock.
import hashlib
import json
import os
from pathlib import Path
import subprocess
import sys
import time
event = json.load(sys.stdin)
minimum_seconds = 120
directory = Path.home() / ".claude" / "pushbag-timers"
directory.mkdir(mode=0o700, exist_ok=True)
session = hashlib.sha256(event["session_id"].encode()).hexdigest()
marker = directory / session
if event["hook_event_name"] == "UserPromptSubmit":
marker.write_text(str(time.time()))
elif event["hook_event_name"] == "Stop" and marker.exists():
started = float(marker.read_text())
marker.unlink()
seconds = int(time.time() - started)
if seconds >= minimum_seconds:
project = Path(event["cwd"]).name
command = ["pushbag", "notify", f"{project}: turn ended after {seconds}s",
"--title", "Claude Code"]
if report_url := os.environ.get("PUSHBAG_REPORT_URL"):
command.extend(["--click", report_url])
subprocess.run(command, check=True, stdout=subprocess.DEVNULL)
Use Python 3.8 or newer for this script. The marker stores one timestamp. Its filename comes from the session ID so sessions in different terminals do not overwrite each other’s clocks. A new prompt in the same session replaces an abandoned timestamp. Removing the marker before sending means another Stop for the same submission cannot send it again. That choice favors a single alert over retrying a failed send. If the publish fails, the subprocess error remains visible on standard error.
The title identifies the tool. The message uses the final component of the working directory, so two repositories with the same folder name produce the same project label. Choose a fixed label for one checkout if the directory name would disclose a client or project on the lock screen. The hook doesn’t need the assistant’s answer to tell you when to come back.
Make the alert open something useful
If the work updates an existing report, export PUSHBAG_REPORT_URL in the shell that starts Claude. Use the artifact’s root URL to show the current report. Use a numbered URL to point to one particular review. The script passes the URL as a separate argument to --click. Access to a private report still depends on who opens it. Test the destination in the phone browser with the account you expect to use.
When the report is the deliverable, the publishing step itself can send the alert with pushbag upload report.html --private --notify and a Both key. That puts the new version in the notification after publication. Disable the separate Stop alert for that workflow if you only need to hear about successful uploads. A turn ending and a report publishing successfully are two different events.
Test the timing independently of delivery
For the first test set minimum_seconds to zero and start a fresh session in the configured project. Submit one prompt and read the project name in the resulting alert. During this first test, leave the report variable unset so a mistyped link cannot obscure a successful basic delivery. Restore 120, submit another short prompt, and check that the timer file disappears without a message. Then try a turn that takes longer than two minutes. If only the first test succeeds, check which working directory and user account started the session and whether both hooks loaded.
If the server responds This credential cannot publish to this channel., check the key’s publish permissions and the requested channel. A manual send from another terminal can use a different profile or environment. If the alert is in the dashboard but silent on Android, check the phone’s notification controls and the channel’s mute and minimum priority settings before changing the hook. Claude Code integration · Phone delivery setup · Comparing pushbag and ntfy
Frequently asked questions
Will this fire after every shell command Claude runs?
No. Stop fires when Claude finishes responding. Tool invocations have separate hook events.
Can I alert only for a project on this machine?
Use that project's .claude/settings.local.json and keep the hook script under your home directory.
Can I keep my prompt out of Android notifications?
Yes. Build the notification from the working directory and elapsed time. The example does not send the prompt or transcript.