Support unattended authentication for Remote Control on long-running Claude Code instances
Feature request
I run several long-running Claude Code instances as always-on agents, usually on servers/containers where there is no interactive user sitting at the machine.
Remote Control is particularly useful for this kind of setup, but currently an RC-capable Claude Code login requires human reauthentication roughly every 30 days.
I spent some time testing the OAuth behavior to make sure this wasn't something that could already be solved externally with refresh tokens. From what I can tell, it can't.
Current behavior
On Claude Code 2.1.260 I tested the OAuth token flow directly.
A normal Claude Code login with:
user:profileuser:inferenceuser:sessions:claude_code
works with Remote Control.
However, user:sessions:claude_code appears to have a server-side maximum lifetime of 30 days. Refreshing the credential does not extend that lifetime. The refresh token rotates, but the returned lifetime continues counting down towards the expiry of the original login. Claude Code already refreshes these credentials automatically, so implementing an external refresh-token script doesn't solve this.
I also tested longer-lived credentials:
user:profileanduser:inferencecan be issued with much longer lifetimesuser:sessions:claude_codeis capped at 30 days- a long-lived credential without
user:sessions:claude_codegets through the Claude Code client-side checks, but Remote Control registration fails with a 403 because the required scope is missing setup-tokenremains a good solution for unattended inference, but cannot be used with Remote Control
So as far as I can tell, there is currently no supported way to run Remote Control indefinitely on an unattended Claude Code instance.
Use case
The use case here is long-running Claude Code agents. For example, I run Claude Code instances that stay alive for weeks or months, perform scheduled/asynchronous work, receive tasks through Channels, and can be managed remotely. These aren't ephemeral CI jobs, they are persistent Claude Code environments.
Requiring a human to authenticate every ~30 days introduces an unnecessary lifecycle dependency for something that is otherwise designed to remain running unattended. This becomes more relevant as Claude Code moves further towards long-running and asynchronous agent workflows.
Proposed solution
I don't think this necessarily means making the existing setup-token more privileged by default. A few possible approaches could work:
- allow an explicit opt-in for Remote Control when creating a setup token
- introduce a revocable machine/agent credential with
user:sessions:claude_code - provide a supported unattended/device authorization flow that can maintain Remote Control access without periodic interactive login
The important part for this use case is having some supported authentication path for Remote Control that doesn't require a human to sign in again every 30 days. The existing 30-day behavior could remain the default for normal interactive Claude Code logins.
Related issues
There have already been requests around using setup-token with Remote Control, including #33105 and #50977.
I think this request is slightly broader. I'm not specifically asking for the existing setup token to bypass the current restriction. I'm asking whether Claude Code can provide a supported authentication model for Remote Control on persistent/unattended instances.
This also avoids trying to work around the restriction by automating the claude.ai browser login, which would be brittle and doesn't seem like the right solution.
Additional context
Products such as Claude Tag also point towards increasingly asynchronous and long-running agent workflows.
I understand that Anthropic-hosted agents have a very different security and execution model from a local Claude Code process, so I'm not suggesting they should share the same authentication mechanism. I mention it only because long-running agent workflows seem to be becoming a more important part of the Claude ecosystem, and having a supported authentication story for persistent self-hosted Claude Code instances would complement that direction.
Data point on the 30-day lifetime, measured on a headless Ubuntu 26.04 server where claude remote-control runs as a systemd service (Max plan, CLI 2.1.284, login through claude auth login with the paste-the-code route).
The 30 days are a ceiling, not the lifetime you get. Over eight logins the server issued refresh tokens with lifetimes between 27.1 and 29.9 days, and the value looks random per issuance:
| login (UTC+2) | context | lifetime |
|---|---|---|
| 2026-09-06 11:08 | tmux | 28.92 d |
| 2026-09-27 22:13 | VS Code extension | 28.61 d |
| 2026-09-29 13:22 | phone browser, user A | 27.10 d |
| 2026-09-29 13:22 | same phone, 25 s later, user B | 27.98 d |
| 2026-09-29 17:33 | laptop browser, user A | 28.23 d |
| 2026-09-29 17:34 | same laptop, 21 s later, user B | 29.91 d |
| 2026-09-29 17:37 | same laptop, fresh private window, user A | 27.40 d |
| 2026-09-29 17:38 | same private window, 48 s later, user B | 28.94 d |
User A and B are two Linux users on the same claude.ai account, each with its own .credentials.json.
Two logins 21 seconds apart, same laptop, same browser, differ by 40 hours. A fresh private window did not reset anything: it produced a shorter lifetime than the login four minutes earlier. The last value is 2,500,335 seconds exactly, so the server is not rounding to hours or days.
Where the number comes from, as far as the client shows: in 2.1.284 the login path sets refreshTokenExpiresAt to Date.now() + refresh_token_expires_in * 1000 from the token response, with a fallback of exactly 30 days only when that field is missing. None of the eight logins hit the fallback, so the server sends the value. On refresh the client keeps the stored date when the response carries no refresh_token_expires_in, which matches your observation that refreshing never extends anything: on one account, three weeks after its login, the date read on three different days was the same second, with several eight-hourly refreshes in between. The client sends no lifetime at all for a normal login; expires_in is only sent on the setup-token style paths (one year, inference-only), consistent with your scope test.
Practical consequence for unattended use: "30 days after login" cannot be planned on. The expiry has to be read back from the credential file and any warning has to be based on that. We ended up building a small web page so that a human with a phone can do the monthly re-login for both users, which is exactly the lifecycle dependency this issue describes.
Two things would already help without changing the security model:
- Make the lifetime deterministic, or document the spread, so tooling can predict the expiry.
- Let
claude auth statusreport whether the refresh token is still valid. Today it saysloggedIn: trueeven whenrefreshTokenExpiresAtis in the past (tested with a credential file whose date was moved one day back).
+1 on a revocable machine credential that carries user:sessions:claude_code.
Another data point: Mac mini running claude remote-control bridges 24/7 (v2.1.308). Logged in with /login on 2026-09-25 11:13 UTC; on 2026-10-25 04:18 UTC (29.7 days later) all bridges began failing every 5 s with "Failed to refresh session … token: Remote Control is only available with claude.ai subscriptions. Please use /login", sessions exited and headless claude -p failed too. A second Max account on a Linux VPS hit the same on 2026-10-23. Asks: (1) a long-lived credential that can register Remote Control on unattended hosts, or let refresh extend the login; (2) a clear "login expired" error instead of "only available with claude.ai subscriptions"; (3) notify the account owner by email/app a few days before expiry, not only in the terminal.
@piti4ek2 your 29.7 days falls inside the 27.1 to 29.9 day spread from my comment of 2026-09-29, so it looks like the same server-side lifetime.
On your point 2, two observations from our server that may help whoever picks this up:
- On 2026-08-29 (CLI 2.1.251) the bridge failed with the same "Remote Control is only available with claude.ai subscriptions. Please use
/login" text while the stored refresh token was still valid until 2026-09-27 (details in my comment on #88054). So that message does not tell you the login expired; it also shows up for a refresh race. - When our refresh token actually expired on 2026-09-27 (CLI 2.1.283), the bridge itself stayed up and logged only
Session failed: Process exited with error cse_…. The real reason,OAuth session expired and could not be refreshed, was only in the session transcript.
So there are at least two different messages for an expired login, and the one you saw is shared with an unrelated failure. Until that changes, the only reliable signal I have found is refreshTokenExpiresAt in .credentials.json.