← Commit history

1.3.7: the watchdog restarts a remote-control server whose account changed after it started

John Lauer ·42ba894f96 ·27d ago ·parent e78fa4e
3 files changed +39−3
claude-rc+36
@@ -212,8 +212,44 @@ launch() {   st_del retry_after   return 0 }+# A RUNNING server holds the account it started with. Sign Claude Code into a different+# account (or refresh an expired login) and the old process keeps serving the OLD identity:+# `status` says running, the log says Ready, and the box simply never appears in the new+# account's device list. ConfRoomROG 2026-09-23: the server had been up since Sep 19 while+# the credentials were rewritten that morning, and John could not see the box from his phone.+# So: credentials newer than the process = stale identity, restart it.+server_identity_stale() {+  local pid="$1" creds="$HOME/.claude/.credentials.json" age started cmtime+  [ -n "$pid" ] || return 1+  [ -s "$creds" ] || return 1+  age="$(ps -o etimes= -p "$pid" 2>/dev/null | tr -d ' ')"+  [ -n "$age" ] || return 1+  started=$(( $(date +%s) - age ))+  cmtime="$(stat -c %Y "$creds" 2>/dev/null || echo 0)"+  # 60s of slack: the server writes nothing to the creds file, but a login that happens a+  # moment before the launch must not look newer than it.+  [ "$cmtime" -gt $(( started + 60 )) ]+}++restart_server() {+  local pid="$1"+  [ -n "$pid" ] || return 0+  kill "$pid" 2>/dev/null || true+  # the `printf y | claude rc` keeper shares the group; take its parent too when it is ours+  local ppid; ppid="$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ')"+  if [ -n "$ppid" ] && ps -o cmd= -p "$ppid" 2>/dev/null | grep -q "claude r[c] --name"; then kill "$ppid" 2>/dev/null || true; fi+  sleep 3+  launch+}+ check() {   case "$(state)" in enabled|failed) ;; *) return 0 ;; esac+  local pid; pid="$(running_pid)"+  if [ -n "$pid" ] && server_identity_stale "$pid"; then+    echo "claude-rc: Claude was signed in again after this server started; restarting it so remote control uses the current account."+    restart_server "$pid"+    return $?+  fi   if [ -n "$(running_pid)" ]; then     # Older keepers marked the fifth attempt failed even if it stayed up.     if [ "$(state)" = failed ]; then
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "hook",-  "version": "1.3.6",+  "version": "1.3.7",   "type": "app",   "org": "adom",   "bundled": true,
page.json+2−2
@@ -1,6 +1,6 @@ {   "slug": "hook",-  "version": "1.3.6",+  "version": "1.3.7",   "type": "app",   "org": "adom",   "bundled": true,@@ -79,4 +79,4 @@     }   ],   "tag": "latest"-}\ No newline at end of file+}