Claude Code runs fine on a remote machine over SSH. Connect with ssh, install it on the server with curl -fsSL https://claude.ai/install.sh | bash, and run claude. There is no browser on the server, so when it asks you to log in, press c to copy the login URL, open it in a browser on your own computer, and paste the code it gives you back into the terminal. Start Claude Code inside tmux so it keeps running when your SSH connection drops.
011. Install on the server
Connect and install with Anthropic's script:
ssh you@your-server
curl -fsSL https://claude.ai/install.sh | bash
claude --version
You can also install with npm (npm install -g @anthropic-ai/claude-code@latest, Node.js 22 or later, without sudo), or from Anthropic's apt, dnf and apk repositories. Instructions for each are in Anthropic's setup guide.
022. Log in without a browser on the server
Run claude. It tries to open a browser and, on a server, cannot. Then:
- Press
cto copy the login URL, or select and copy it from the terminal. - Open it in a browser on your laptop and sign in.
- If the browser shows a code, paste it at the Paste code here if prompted line.
- You see Login successful.
Other options, from Anthropic's authentication documentation:
- An API key: set
ANTHROPIC_API_KEYon the server and Claude Code asks you once to approve it. - A long-lived token: run
claude setup-tokenon a machine with a browser, then setCLAUDE_CODE_OAUTH_TOKENon the server. It needs a Pro, Max, Ultra, Team or Enterprise plan, and the token does not work for Remote Control.
On a Mac reached over SSH, a locked Keychain is common. Claude Code then stores the login in ~/.claude/.credentials.json, readable only by you.
033. Keep it running when SSH disconnects
If the SSH connection drops, everything started in it stops, including Claude Code in the middle of a task. Start a tmux session first:
tmux new -s claude
claude
Detach with Ctrl+B then D, close your laptop, and later reattach with tmux attach -t claude. screen works the same way. Anthropic's Remote Control documentation gives the same advice.
044. Fix the keyboard
- Shift+Enter for a new line works in Ghostty, Kitty, iTerm2, WezTerm, Warp and recent Windows Terminal. In VS Code, Cursor, Zed and older Alacritty, run
/terminal-setuponce. Run it on your own computer's terminal, not inside tmux.Ctrl+J, or\then Enter, always works. - Inside tmux, add these to
~/.tmux.confon the server, then detach and reattach:
set -g allow-passthrough on
set -g focus-events on
set -s extended-keys on
set -as terminal-features 'xterm*:extkeys'
- Option shortcuts on a Mac need "Use Option as Meta Key" in Apple Terminal, or Option set to "Esc+" in iTerm2.
055. Pasting and images
Long pastes collapse to a placeholder such as [Pasted text #1 +120 lines]; Claude still gets all of it. For very large input, copy a file to the server with scp and point Claude at it. Pasting an image from your laptop's clipboard into a terminal on a server generally does not work, because the server cannot see your clipboard. Copy the image to the server and give Claude its path.
066. Other ways to reach a remote machine
- VS Code Remote-SSH: open a window connected to the server and use Claude Code in its terminal or the Claude Code extension there.
- Remote Control: start
claude --remote-controlon the server and drive the session from the Claude app on your phone or from claude.ai/code. It needs a claude.ai login. See Claude Code Remote Control. - Dev containers: Anthropic publishes a dev container feature for Claude Code; keep
~/.claudeon a volume so you stay logged in.
077. Know when it needs you
A notification hook on the server fires on the server, where there is no desktop, so notify-send shows nothing. To hear about it on your laptop, use a terminal that shows notifications sent over SSH, or send a push from the server. Claude Code Notifier does the second: an independent tool (not made by Anthropic) with a free command line tool, ccn, that you install on the server, and apps for iPhone and Android. It only makes outbound connections, so no ports need opening, and it keeps working after your laptop disconnects. See Claude Code notifications over SSH.
08FAQ
Can I use Claude Code over SSH?
Yes. Install it on the remote machine, run claude in your SSH session, and log in by opening the URL it gives you in a browser on your own computer.
How do I log in to Claude Code on a headless server?
Run claude, press c to copy the login URL, open it on another device, sign in, and paste the code back. Or set ANTHROPIC_API_KEY, or a token from claude setup-token as CLAUDE_CODE_OAUTH_TOKEN.
Does Claude Code keep running if SSH disconnects?
Not unless you start it inside tmux or screen. Then it keeps working and you can reattach later.
Why doesn't Shift+Enter work in Claude Code over SSH?
Your terminal or tmux is not passing the key through. Run /terminal-setup on your local terminal, add the tmux settings above, or use Ctrl+J for a new line.
Use OpenAI's Codex CLI? Notifier for Codex does the same for Codex.