DEV Community

Cover image for Stop wasting time on vibe coding
Israel Saba
Israel Saba

Posted on • Edited on

Stop wasting time on vibe coding

Have you ever left Claude Code to chew on a hard task, only to learn it stopped 1s after you were out?

Giving Claude Code full access to your computer is not the wisest decision, so the next safest alternative is actually deciding on permission queries that need your attention.

So, assuming you took the safest route, as I did, there is a way to not lose queries from Claude code when you are away from your desk, and I explain it here.

Please note the Roadmap, where I will add a way to make decisions on the go too.**

How to tackle the problem

We will use an open-source app called ntfy that sends custom notifications directly to your mobile. It can be installed on your iOS or Android mobile and you can use it for free.***

Option 1 - Quick-win

Use ntfy claude, as opposed to self-hosted, without a de-bouncer

NTFY Setup

  1. Sign-up at ntfy app

  1. Sign-in and access your dashboard
  2. Click Subscribe to topic

Step 3

  1. Click GENERATE NAME* -> SUBSCRIBE and take note of the topic

Step 4

  1. Click on your avatar at the top -> Click your username
  2. At Access tokens click Create access token, choose a name (e.g. claude-code), click CREATE TOKEN and take note of the created token (it is always available at the user settings).

Steps 5 and 6

Step 6

Step 6

  1. Download NTFY app to your mobile and enable notifications
  2. Sign-in to your ntfy account in the app (make sure you are subscribed to topic created on 4.)

Claude Code Setup

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

Start a new claude session and enjoy!

Option 2: de-bouncing add-on

To avoid multiple notifications at the same time we can add a de-bouncer.

  • Create the de-bouncer script at the path ~/.claude/scripts/ntfy-debouncer.sh below
#!/usr/bin/env bash
set -euo pipefail

NTFY_SERVER_URL="ntfy.sh"
NTFY_TOPIC="<your-topic-name-from-step-4>"
LOGFILE="/tmp/ntfy-hook.log"
TOKEN="<your-token-from-step-6-above>"

exec >>"$LOGFILE" 2>&1

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


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

MSG="${1:-}"
[[ -n "$MSG" ]] || exit 2

curl -v \
  -H "Authorization: Bearer ${TOKEN}" \
  -L \
  -d "$MSG" \
  "https://${NTFY_SERVER_URL}/${NTFY_TOPIC}"
Enter fullscreen mode Exit fullscreen mode
  • Chmod the script
chmod +x .claude/scripts/ntfy-debouncer.sh
Enter fullscreen mode Exit fullscreen mode
  • Update ~/.claude/settings.json to use it
{
  "hooks": {
    "PermissionRequest": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.claude/scripts/ntfy-debouncer.sh 'Claude Code is requesting your input to move on'"
          }
        ]
      }
    ],
"Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.claude/scripts/ntfy-debouncer.sh 'Claude Code has finished working'"
          }
        ]
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

Option 3: token security

  • Create a keychain entry on your terminal
security add-generic-password -a "$USER" -s "ntfy.sh" -w "<your-token-from-step-6-above>" -U
Enter fullscreen mode Exit fullscreen mode
  • at ~/.claude/scripts/ntfy-debouncer.sh paste
#!/usr/bin/env bash
set -euo pipefail

NTFY_SERVER_URL="ntfy.sh"
NTFY_TOPIC="<your-topic-name-from-step-4>"
LOGFILE="/tmp/ntfy-hook.log"

exec >>"$LOGFILE" 2>&1

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


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

MSG="${1:-}"
[[ -n "$MSG" ]] || exit 2

# Storing the token
# security add-generic-password -a "$USER" -s "ntfy.sh" -w "tk_XXX" -U

TOKEN="$(security find-generic-password -a "$USER" -s "$NTFY_SERVER_URL" -w 2>/dev/null || true)"
if [[ -z "${TOKEN}" ]]; then
  echo "ERROR: token not found in Keychain (service: ntfy.israelsaba.com.br, account: $USER)" >&2
  exit 3
fi

curl -v \
  -H "Authorization: Bearer ${TOKEN}" \
  -L \
  -d "$MSG" \
  "https://${NTFY_SERVER_URL}/${NTFY_TOPIC}"
Enter fullscreen mode Exit fullscreen mode

Roadmap

Other things I'd like to explore/write about regarding this. Let me know what you would like first. Do let me know your thoughts and any extra tips.

[X] Explore a more secure option using MacOS secrets to store the NTFY token
[ ] Write about my self-hosted instance of ntfy and how I connect it here
[ ] Explore using the "Notification" hook on Claude Code

reference docs: Claude Code hooks, NTFY

*It is important to generate a random topic name as this is a public platform. If you name it claude-code for instance, anyone who has done the same will be able to push notifications to your ntfy. That can be solved by running a self-hosted instance.

**Do check this NetworkChuck's video on the matter. It solves the same problem with n8n and Slack, and it even includes a way to answer the prompt on the go.

***Tutorial made using MacOS as base. Although shell script shebang is designed for maximum compatibility.

Top comments (7)

Collapse
 
capestart profile image
CapeStart

For the roadmap, I’d love a secure token setup next, like pulling the bearer token from keychain/secret store instead of hardcoding it. Also maybe add a tiny payload with what permission it’s asking for, so you don’t have to tab back in just to see the prompt.

Collapse
 
israelsaba profile image
Israel Saba

Great! I will do it and comment back here to let you know.

Collapse
 
israelsaba profile image
Israel Saba

Added as option 3 there

Collapse
 
capestart profile image
CapeStart

Fine

Collapse
 
pedro_borges_ece1addab35f profile image
Pedro Borges

That is awesome! Appreciate the time to write something practical to get the notifications!

Collapse
 
israelsaba profile image
Israel Saba

Sure! Glad you enjoyed!

Collapse
 
marie_costafreitassaba_ profile image
Marie Costa Freitas Saba

Awesome way to improve coding skills πŸ‘πŸ»πŸ‘πŸ»πŸ‘πŸ»