Skip to main content
All writing

Integration guides2 min read

Approve Claude Code's Shell Commands From Your Phone

A PreToolUse hook can hold every Bash command until you approve it on Vibez.now, so a long Claude Code session doesn't need you at the keyboard to stay supervised.

Claude Code asks before it runs a command, in the terminal it is running in. That works while you are at that terminal. Leave for lunch, or start a long task on a remote machine, and either the session stalls on a prompt nobody sees or you loosen the permissions so it doesn't.

Hooks offer a third option. A PreToolUse hook runs before every tool call and can answer allow or deny. This one sends each Bash command to Vibez.now, where it appears on your Requests page and phone, and waits for your decision.

The hook

Standard library only. The settings.json to register it is in the docstring at the top. Set VIBEZ_API_KEY, from Settings in Vibez.now, in the environment Claude Code runs in.

.claude/hooks/approve-bash.py
#!/usr/bin/env python3
"""A Claude Code PreToolUse hook: every Bash command waits for your approval on Vibez.now.

Put this file at .claude/hooks/approve-bash.py, make it executable, set
VIBEZ_API_KEY in the environment Claude Code runs in, and add to
.claude/settings.json:

    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              {
                "type": "command",
                "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/approve-bash.py",
                "timeout": 600
              }
            ]
          }
        ]
      }
    }

Claude Code lets a call through when a PreToolUse hook times out, so this
script gives up and denies at WAIT_SECONDS, well inside the 600-second
timeout above, rather than relying on the timeout to stop anything. Every
failure path denies too. Python 3.9+, standard library only.
"""

import json
import os
import sys
import time
import urllib.request

API = os.environ.get("VIBEZ_API_URL", "https://vibez.now/api")
WAIT_SECONDS = 540


def call(path, body=None):
    request = urllib.request.Request(
        API + path,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Content-Type": "application/json", "x-api-key": os.environ["VIBEZ_API_KEY"]},
    )
    with urllib.request.urlopen(request, timeout=20) as response:
        return json.load(response)


def decide(allowed, reason):
    print(json.dumps({
        "hookSpecificOutput": {
            "hookEventName": "PreToolUse",
            "permissionDecision": "allow" if allowed else "deny",
            "permissionDecisionReason": reason,
        }
    }))
    sys.exit(0)


def main():
    event = json.load(sys.stdin)
    command = event.get("tool_input", {}).get("command", "")
    try:
        created = call("/submit-request", {
            "title": f"Claude Code: {command[:80]}",
            "description": event.get("tool_input", {}).get("description") or None,
            "code_snippet": command,
            "source": "claude-code",
            "metadata": {"cwd": event.get("cwd")},
            "expires_in_minutes": WAIT_SECONDS // 60,
        })
        status = created.get("status")
        deadline = time.monotonic() + WAIT_SECONDS
        delay = 3.0
        while status == "pending" and time.monotonic() + delay < deadline:
            time.sleep(delay)
            delay = min(delay * 1.5, 20.0)
            status = call(f"/check-status?request_id={created['request_id']}").get("status")
    except Exception as error:
        decide(False, f"Vibez.now approval failed ({error}); the command was not run.")
    if status == "approved":
        decide(True, "Approved on Vibez.now.")
    decide(False, "Not approved on Vibez.now; the command was not run.")


if __name__ == "__main__":
    main()

The detail that matters: timeouts

When a PreToolUse hook times out, Claude Code does not block the call; it falls back to the normal permission flow. A gate that waits until the timeout is a gate that opens at the timeout. So this hook keeps its own clock: it stops waiting at 540 seconds, inside the 600-second timeout in settings.json, and denies. Network errors, a missing key and an unanswered request all deny as well.

  • Approved on Vibez.now: the hook answers allow, and the command runs without a terminal prompt.
  • Rejected, unanswered or failed: the hook answers deny, and Claude sees the reason and can adjust.
  • Deny rules in your settings still apply even when the hook allows.

Ask about the commands that matter

Gating every command, including ls and git status, quickly turns approval into a reflex. Two ways to narrow it: an if filter on the hook in settings.json, written in permission-rule syntax, so it only fires for matching commands; or auto-approve rules in Vibez.now Settings, which approve requests from a named agent or source as they arrive.

What happens when a Claude Code PreToolUse hook times out?

The call is not blocked; it goes through Claude Code's normal permission flow. That is why this hook denies on its own before its timeout is reached.

How does a hook allow or deny a command?

It prints JSON with hookSpecificOutput.permissionDecision set to allow or deny, and a permissionDecisionReason, then exits 0.

Does this work on a remote machine?

Yes. The hook only needs outbound HTTPS to vibez.now and VIBEZ_API_KEY in its environment; you approve from the web or the iOS app.

Keep reading