Claude Code login on a remote server over SSH
Updated · Jere & CO
On your own computer, the first run of claude opens a browser, you sign in, and Claude Code picks up the result on its own. On a server you reached over SSH, the browser opens on the wrong machine, or nowhere. The good news: Claude Code’s main login was built for this, and only needs you to carry one code across.
1. The paste-code flow
- On the box, run
claude(or type/loginin a running session). - Claude Code shows a sign-in URL. Open it in the browser on your own computer or phone.
- Sign in and approve. Because your browser can’t reach Claude Code’s callback server on the box, it shows a login code instead of returning to the terminal.
- Paste that code at the
Paste code here if promptedprompt on the box.
The terminal says Login successful. The docs name this as the fix for SSH sessions, WSL2 and containers.
2. When the URL won’t copy
The login URL is long and wraps across lines, so clicking it in the terminal rarely works. Claude Code offers c to copy it, but that copies to the clipboard of the machine Claude Code runs on, which, over SSH, is the box, not your laptop (#69753). Two ways round it:
- Use the non-interactive command. It prints the URL and reads the code from standard input, which also helps when pasting into the interactive prompt does nothing:
claude auth login
- Or widen the terminal until the URL fits on one line, then select it.
3. A token for a box nobody sits at
For CI, scripts or an always-on agent box, the docs describe a one-year OAuth token. It uses the same browser sign-in as /login, so run it once on your own computer; it prints the token and saves it nowhere:
claude setup-token
Then, on the box:
export CLAUDE_CODE_OAUTH_TOKEN=your-token
It needs a Pro, Max, Team or Enterprise plan, and it can only make model requests: no Remote Control sessions, no claude.ai connectors. Locally configured MCP servers still work.
4. An API key instead
With a Claude Console account, set ANTHROPIC_API_KEY on the box. In an interactive session Claude Code asks once whether to use it; with -p it always does. Note that an approved key takes precedence over your subscription login, which surprises people who meant to use their plan. /status shows which credential is in use.
5. MCP servers: the sign-in with no paste step
Remote MCP servers that use OAuth sign in through /mcp, and they redirect to http://localhost:PORT/callback on the box with no code to paste. By default the port is random. Fix it when you add the server, then forward that port from your laptop before you sign in:
# on the box
claude mcp add --transport http --callback-port 8080 my-server https://mcp.example.com/mcp
# on your laptop, in a second terminal
ssh -N -L 8080:localhost:8080 you@your-box
Then run /mcp on the box, open the link on your laptop and approve; the redirect travels through the tunnel. Why this works, and the other ways out, is in OAuth redirect to localhost on a remote server.
What these have in common
Every route above needs you at a computer with the right terminal open, within a minute or two of the link appearing. When an agent hits a sign-in while you’re on the sofa with your phone, none of them help much.
The permanent fix
Handback catches the sign-in link Claude Code or one of its MCP servers opens on the box, through $BROWSER and xdg-open with the free Engine on Linux, or Engine mode in the Handback app when the box is a Mac, and hands it to the iPhone, iPad or Mac in your hand. When the link redirects to localhost on the box, the app binds that port on your device and tunnels the callback back, so the login finishes without a paste, a forward or a random port to look up. On an iPhone the sign-in opens in a sheet inside the app, which receives while it's on screen; links that arrive meanwhile wait on the box for 24 hours.
$7.99 / €7.99 · Mac, iPhone & iPad, one purchase
Sources
Every flag above was checked against these on 15 October 2026.