[Bug] Remote control startup fails with intermittent 401s from code-session endpoints
Bug Description
Remote control (remoteControlAtStartup: true) fails to connect with intermittent 401s from the code-session endpoints. Freshly logged in; token valid 7h, scopes include user:sessions:claude_code, Max sub. Across ~15 min of debug logs on canary 2.1.212 (macOS): createCodeSession succeeded 2/9 times, /bridge failed 6/6, archive succeeded 2/2 — all with the same token, sometimes seconds apart. Create returned 200 at 00:03:35Z and 401 at 00:04:45Z with no credential change in between. The same token authenticates six claude.ai connector MCP servers and the main /v1/messages API without issue throughout. Manual /rc and startup auto-connect fail identically. Not a multi-session conflict (reproduced with a single process, no daemon, after a full reboot). Debug log available.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.1.212
- Feedback ID: 72e9c361-28e8-4aa9-9443-1981966dc388
Errors
[]
4 Comments
Independent reproduction — different account, machine, and terminal; same afternoon onset. Also ties in #78307: we hit both failure surfaces (create-side and bridge-side) from what looks like one root cause.
Environment: macOS (darwin 25.3), Max subscription, observed on both 2.1.211 and 2.1.212, sessions launched both interactively and under a
script -qPTY wrapper.Timeline (Pacific, 2026-07-16): RC registrations succeeded at 10:22 and 14:06–14:10; first observed failure 16:45; still failing at 18:04.
/v1/messagesand MCP traffic authenticated fine with the same credentials throughout — sessions that lose RC registration run their whole task locally, they're just invisible/unreachable remotely.Controlled A/B (alternating launches, minutes apart, same env): per-request 401 rate on
POST /v1/code/sessionsandPOST .../bridgewas roughly 50%+. The strongest server-side signal: the same in-memory token fails then succeeds within one process, sub-second apart —And a run where both endpoints flapped in sequence (this one exhausted the bridge retries and surfaced the "Remote credentials fetch failed" banner, 2.1.212):
Triage note —
--debugis a red herring worth ruling out early: across ~a dozen manual samples, adding--debug/--verboseappeared 100% protective and no-flag launches failed ~50% — convincing enough that we initially chased it as a heisenbug. Controlled alternating runs broke the pattern: a--debuglaunch failed the same way, and every successful debug run still shows 401s that the 3 internal retries happened to rescue. It's retry luck, not a flag effect. Others will likely observe the same correlation.Given ~50% per-request failure, the 3-attempt/sub-second retry budget on both
createCodeSessionandfetchRemoteCredentialsexhausts easily; a longer/jittered retry window would paper over incidents like this one at the client.---
Posted by Claude Code (Fable 5), at the account owner's instruction — he has not reviewed this content.
Adding a quantified Windows datapoint that matches this issue's 401 cluster — including before/after rates across an app auto-update boundary, and evidence it is not local.
Symptom: identical to OP — toggling Remote Control fails 2–5 s after
Enabling remote controlwithbridge_state: failed — Remote credentials fetch failed — see debug logorSession creation failed — see debug log. Nondeterministic per attempt (~25–30% success; success and failure 6–10 s apart on identical local state); retrying eventually succeeds for every session. Every failed disconnect additionally throwsCannot read properties of undefined (reading 'session_url')(157 occurrences in one night), and laterDELETE /v1/code/sessions/<id>returns 404Session not found— appears to leak server-side sessions (same mechanism as #78333).Environment: Windows 11 Pro 10.0.22631; Claude Desktop MSIX 1.22209.0 (auto-updated from 1.20186.1 at 2026-07-17 01:31:39 UTC after being staged 72 h —
[updater] Auto-restarting app after update pending for 72 hours); bundled Claude Code CLI 2.1.209. Residential IPv4-only, no proxy/PAC/VPN, clock skew +0.4 s.Timeline / quantification (UTC):
/authorizere-login (~04:02, auth succeeded, 17 sessions initialized), full MSIX reinstall of the same 1.22209.0 (~04:21).Evidence it is not local:
Notes for triage:
POST /v1/code/sessions+ bridge-credentials issuance in the 2026-07-17 01:35–04:30 UTC window should show this.session_url) prevents session cleanup, and combined with the 3-transient-failure self-disable (#78364) converts intermittency into a hard outage for automation that relies on Remote Control.Independent reproduction on macOS / 2.1.212 / claude.ai OAuth (Max), with one datum I haven't seen in this thread yet: the failure reproduces with raw
curl, no CLI in the loop at all. That isolates it from the client entirely — not a client bug, not a 2.1.212 regression.Same token, same minute, two endpoints
| Endpoint | Result |
|---|---|
|
GET /v1/sessions(anthropic-beta: ccr-byoc-2025-07-29) | 12/12 → 200 ||
GET /v1/code/sessions| ~35% 200 / ~65% 401 |n=44 across three samples (12/20, 9/12, 8/12 failing). Identical token bytes throughout (sha256 unchanged,
expiresAtvalid ~4h out, scopes includeuser:sessions:claude_code), alternating within seconds:My ~65% independently matches the 13/20 (~65%) that #78366 measured on presence pulses, which suggests one root cause across the code-session endpoints rather than three separate bugs.
The detail that may be the most useful pointer
The 401 response still carries the resolved organization header:
So the server authenticates the token far enough to resolve the organization, and then returns
authentication_erroranyway. That points at an inconsistency inside the code-session auth path rather than anything about token validity — consistent with the OP's observation that the same token authenticates/v1/messagesand the connector MCP servers without interruption.Repro (no CLI involved)
→ mixed
401 200 401 401 …. Addingx-organization-uuidmakes no difference (tested both ways, ~65–75% either way), so it isn't org resolution on the request side.The archive endpoint is affected too: archiving one session took 6 attempts to get a 200.
Why it surfaces as a hard failure
Matches @evoskamp's analysis in #78323. The bridge's retry wrapper is a plain retry with no token refresh between attempts — budget
init_retry_max_attempts: 3, from thetengu_bridge_repl_v2_configdynamic config (server-controlled, so not something users can raise locally). Startup needs two independent chains to land (createCodeSession, then/bridgecredentials fetch), so at a ~65% per-call failure rate:which matches the reported "fails roughly half my launches." Worth noting the retry budget is a symptom amplifier, not the bug — at a 0% server error rate the budget never matters.
Environment / timing
Happy to supply full
--debug-filelogs or additional request-ids if useful.Another independent reproduction, adding two dimensions not yet in this thread: Team plan and the Linux CLI.
Environment: Linux, Claude Code 2.1.212 (stable), claude.ai OAuth, Team subscription (
subscriptionType: team),remoteControlAtStartup: true. The same OAuth token drives/v1/messagesand several claude.ai connector MCP servers without issue throughout — only the/v1/code/sessions+/bridgecalls flap.Across 3 startup launches within ~13 min I saw all three states described above:
Hard fail —
createCodeSession401 on all 3 attempts →Session creation failed:Bridge-side flap that recovered — create OK, then
fetchRemoteCredentials401 on attempt 1/3, rescued on retry (matches @jaidhyani's sub-second flap):Clean connect (one launch).
So ~1/3 of my (small) sample failed outright — consistent with the ~30–65% per-request 401 rates measured above. Confirms this is not Max-specific and not macOS/Desktop-specific: a Team-plan OAuth token on the Linux CLI hits the identical endpoint-selective 401 on
/v1/code/sessions. Nothing to add to @djknudson's curl-level isolation — just widening the affected population. Happy to share full--debuglogs / feedback ID.---
Drafted by Claude Code, reviewed and posted by the account owner.