claude-remote-approver 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,7 @@ cli.mjs hook
25
25
  │ │
26
26
  └──SSE───▶ ntfy.sh/<topic>-response ◀──POST──┘
27
27
 
28
- │ stdout JSON: { "behavior": "allow" } or { "behavior": "deny" }
28
+ │ stdout JSON: allow / deny / ask (CLI fallback)
29
29
 
30
30
  Claude Code continues or stops
31
31
  ```
@@ -34,9 +34,13 @@ Claude Code continues or stops
34
34
  2. `cli.mjs hook` sends a notification to your ntfy topic with **Approve** and **Deny** action buttons.
35
35
  3. The hook subscribes to a response topic (`<topic>-response`) via server-sent events.
36
36
  4. When you tap a button on your phone, ntfy.sh publishes your decision to the response topic.
37
- 5. The hook reads the decision, writes `{"behavior":"allow"}` or `{"behavior":"deny"}` to stdout, and exits.
37
+ 5. The hook reads the decision and writes `{"behavior":"allow"}` or `{"behavior":"deny"}` to stdout. If the notification fails or times out, the hook returns `{"behavior":"ask"}` so Claude Code falls back to the CLI prompt.
38
38
  6. Claude Code proceeds accordingly.
39
39
 
40
+ ### AskUserQuestion support
41
+
42
+ When Claude Code calls the `AskUserQuestion` tool, the hook sends the question to your phone as a notification. Each option appears as an action button you can tap. If the question has more than 3 options, they are split across multiple notifications. If no response is received before the timeout, the hook falls back to the CLI prompt so you can answer at your terminal.
43
+
40
44
  ## Quick Start
41
45
 
42
46
  ```bash
@@ -179,7 +183,7 @@ Config file location: `~/.claude-remote-approver.json`
179
183
  |---|---|---|---|
180
184
  | `topic` | `string` | `""` | Your unique ntfy topic. Generated by `setup`. |
181
185
  | `ntfyServer` | `string` | `"https://ntfy.sh"` | The ntfy server URL. Change this if you self-host. |
182
- | `timeout` | `number` | `120` | Seconds to wait for a response before auto-denying. |
186
+ | `timeout` | `number` | `120` | Seconds to wait for a response before falling back to CLI. |
183
187
  | `planTimeout` | `number` | `300` | Seconds to wait for ExitPlanMode (plan approval) responses. Plan reviews need more reading time. |
184
188
  | `autoApprove` | `string[]` | `[]` | Reserved for future use. |
185
189
  | `autoDeny` | `string[]` | `[]` | Reserved for future use. |
@@ -225,7 +229,7 @@ The public ntfy.sh server is convenient but means your permission request detail
225
229
 
226
230
  ### Timeout behavior
227
231
 
228
- If no response is received within the configured timeout (default: 120 seconds), the hook automatically **denies** the request. This fail-closed design ensures Claude Code does not proceed without explicit approval.
232
+ If no response is received within the configured timeout (default: 120 seconds), the hook falls back to the **CLI prompt** (`ask`), so you can still respond at your terminal.
229
233
 
230
234
  ## Disclaimer
231
235
 
@@ -234,7 +238,7 @@ If no response is received within the configured timeout (default: 120 seconds),
234
238
  The authors are not responsible for any damages or losses arising from the use of this tool, including but not limited to:
235
239
 
236
240
  - Accidental approval of dangerous commands (e.g., mistapping Approve on your phone)
237
- - Unintended denial of safe commands (e.g., timeout, network issues)
241
+ - Unintended CLI fallback when away from terminal (e.g., timeout, network issues)
238
242
  - Security breaches if the topic name is compromised
239
243
 
240
244
  **Not a substitute for careful review.** The push notification shows the tool name and a brief summary, but not the full context of what Claude Code is doing. Always review what you are approving.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-remote-approver",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Approve or deny Claude Code permission prompts remotely from your phone via ntfy.sh",
5
5
  "type": "module",
6
6
  "bin": {
package/src/hook.mjs CHANGED
@@ -6,6 +6,9 @@ import { DEFAULT_CONFIG } from "./config.mjs";
6
6
  export const ASK = Object.freeze({ hookSpecificOutput: Object.freeze({ hookEventName: "PermissionRequest", decision: Object.freeze({ behavior: "ask" }) }) });
7
7
  const DENY = Object.freeze({ hookSpecificOutput: Object.freeze({ hookEventName: "PermissionRequest", decision: Object.freeze({ behavior: "deny" }) }) });
8
8
  const MAX_RETRIES = 3;
9
+ export const RETRY_DELAY_MS = 1000;
10
+ /** @internal Replaceable delay for testing. Do not use outside of tests. */
11
+ export const _internal = { delay: ms => new Promise(r => setTimeout(r, ms)) };
9
12
 
10
13
  /**
11
14
  * Build ntfy action buttons for Approve / Deny.
@@ -37,6 +40,7 @@ export function buildActions(server, topic, requestId) {
37
40
 
38
41
  /**
39
42
  * Send with retry, returning null on exhausted retries.
43
+ * Uses linear backoff: delay = RETRY_DELAY_MS * attempt (1s, 2s, …).
40
44
  */
41
45
  export async function sendWithRetry(sendFn, params) {
42
46
  for (let i = 0; i < MAX_RETRIES; i++) {
@@ -47,6 +51,7 @@ export async function sendWithRetry(sendFn, params) {
47
51
  console.error(`[claude-remote-approver] Notification failed after ${MAX_RETRIES} attempts:`, err.message, "— Falling back to CLI.");
48
52
  return null;
49
53
  }
54
+ await _internal.delay(RETRY_DELAY_MS * (i + 1));
50
55
  }
51
56
  }
52
57
  return null;