Closed bug report

claude-rc restarts remote control every ~8 h: an OAuth token refresh looks like a new sign-in

dereke · ·closed by Colby Knox

adom/hook 1.3.10 (claude-rc) · adom/core 4.15.2 · hydrogen-bootstrap 0.5.77 · Hydrogen 0.1.419 (build c7393e6f) on macOS (Mac mini) · Claude Code 2.1.306 (linux-arm64, the VS Code extension's binary) · claude-rc reports env=hc, with cron running and registered

What happens

claude-rc check restarts a healthy claude rc server about every 8 hours. Every restart shuts down all active remote sessions.

The cause is server_identity_stale(). It treats "~/.claude/.credentials.json is newer than the server process" as "the user signed in again". But Claude Code rewrites that file on every OAuth access-token refresh. The tokens last 8 hours: expiresAt is 8 h after the file's mtime. The account stays the same. The 2-minute cron check then sees a newer file, kills the server's process group and relaunches it.

Observed on 2026-10-21 (local time):

  • 18:15:40 .credentials.json rewritten. This was a token refresh; oauthAccount in ~/.claude.json was unchanged.
  • 18:16:01 server log: Shutting down 1 active session(s)…
  • 18:16:02 server log: Environment preserved. Restart `claude remote-control` to reconnect existing sessions.
  • 18:16:04 claude-rc: launching (name=…, env=hc)

The previous launch was at 10:20:04 the same day, about 8 h earlier, so it fits the same cycle. The next one would have come at about 02:12. From the user's phone, remote control looks like it stopped and the open session drops.

Expected

A token refresh on the same account should not restart the server. It should restart only if:

  • the signed-in account changed, or
  • the running server is no longer connected. This still covers the ConfRoomROG case the check was added for.

Suggested fix (running locally; patch attached)

  1. New account_id(): reads oauthAccount.accountUuid and organizationUuid from ~/.claude.json. It returns empty when they're unknown, for example with an API-key login or no python3.
  2. launch(): records that ID in the state file as account=.
  3. server_identity_stale(): keeps the mtime gate and its 60 s slack. After that, it returns stale only if the account differs from the recorded one, or if server_connected() is false.
    • If there's no recorded account (a server started by an older keeper), it adopts the current account instead of restarting.
  4. New server_connected(): reads the newest status line of the TUI redraw from the log (·✔︎· Connected · …).
    • The match is anchored at the line start, because the Capacity: … · … line that follows also contains a middle dot.

Testing: I ran the patched check in a sandbox HOME against nine cases:

Case Result
Token refresh no restart
Account change restart
Older keeper with no recorded account adopts the account, no restart
Same account but disconnected restart
Credentials older than the server no restart
API-key login, connected no restart
API-key login, disconnected restart
Real server log tail no restart

A live claude-rc check on this container afterwards left the running server alone.

Caveat: I don't know the full set of status words the RC TUI prints when it's unhealthy. The check treats anything other than Connected on the newest status line as not connected.

claude-rc-token-refresh.patch

1 Reply

Colby Knox ·

Thanks for the diagnosis and the patch. Fixed in adom/hook 1.3.11, built on your patch with two changes:

  • The keeper learns the server's account while the credentials are unchanged. It doesn't wait for the first rewrite. With adoption at the first rewrite, a sign-in to another account right after the upgrade would have been adopted and missed. If the account was never learned and the credentials are newer, it restarts once, as before.
  • "Not connected" must last 5 minutes. The status line briefly reads Reconnecting · retrying in …ms after a network blip, so a single check doesn't count. A log with no status line counts as connected, so an unrecognized TUI format can't bring back the 8-hour restarts.

There are 8 new keeper tests: token refresh, account change, an older keeper's server, a brief reconnect, 5 minutes stuck off Connected, no status line, and an unknown account. Machines pick it up on their next update; adom-wiki pkg install adom/hook gets it now.

Colby Knox closed this ·

Log in to reply.