How to Run Claude Code on a Remote Server
How to SSH into a remote Linux server, install Claude Code, keep it running persistently with tmux, and optionally connect to the session from your phone without a terminal.
You can run Claude Code on any remote Linux server — a VPS, a cloud VM, a home machine — and keep the session running after you close your terminal. The core setup is SSH in, install Node.js and Claude Code, wrap the session in tmux so it survives disconnects, and detach. The remote coding session keeps running whether or not you're connected.
TL;DR
- SSH into the server and install Node.js 18+ via nvm
- Install Claude Code:
npm install -g @anthropic-ai/claude-code - Wrap every session in tmux so it survives SSH disconnects
- Detach with
Ctrl+B D; reconnect anytime withtmux attach -t claude - Resume Claude Code after reattaching with
claude --continue - Optional: install Grass for mobile monitoring without SSH
Prerequisites
- SSH access to a remote Linux server (Ubuntu 22.04+ recommended)
- An Anthropic API key
- Node.js 18+ available on the server (this guide covers installation via nvm)
- Basic SSH and terminal familiarity
Step 1: SSH into the server
ssh user@your-server-ip
If you're connecting for the first time, verify your SSH key is set up correctly. Password authentication works too but key-based auth is preferred for servers you'll access frequently.
Step 2: Install Node.js 18+ via nvm
Node.js 18 or higher is required for Claude Code. The cleanest way to install it on a server is via nvm, which avoids permission issues with global npm packages:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install --lts
Verify: node --version should return v18.x or higher.
Step 3: Install Claude Code
npm install -g @anthropic-ai/claude-code
Verify installation:
claude --version
Step 4: Set the Anthropic API key
Add your API key to your shell profile so it persists across sessions:
echo 'export ANTHROPIC_API_KEY="sk-ant-your-key-here"' >> ~/.bashrc
source ~/.bashrc
Verify it's set:
echo $ANTHROPIC_API_KEY
Never commit API keys to version control. If you're working in a shared repo, use a .env file excluded via .gitignore.
Step 5: Install tmux
tmux is what keeps Claude Code running after you close your terminal. Without it, closing your SSH connection sends SIGHUP to all foreground processes — Claude Code exits immediately.
sudo apt install tmux -y
Verify: tmux -V should return a version like tmux 3.2a.
Step 6: Start a named tmux session
Naming sessions by project keeps things organized, especially if you're running multiple agents:
tmux new -s claude
You're now inside a tmux session. Your shell prompt looks the same, but tmux is running underneath it.
Step 7: Navigate to your project and start Claude Code
cd ~/project
claude
Claude Code starts inside the tmux session. You can interact with it normally.
Step 8: Detach without stopping the session
When you want to walk away:
# Press Ctrl+B, then D (hold Ctrl, press B, release both, then press D)
Your terminal returns to the shell. Claude Code is still running inside tmux on the server. Close your SSH connection — nothing stops.
Step 9: Reconnect to the session
When you want to check in:
ssh user@your-server-ip
tmux attach -t claude
You're back inside the running session, exactly where you left off.
Step 10: Resume a Claude Code session after reattaching
If Claude Code exited naturally while you were away (task complete, error, or it was waiting for input and timed out), resume with:
claude --continue
This resumes the most recent session for the current directory, restoring the full conversation history from the .jsonl transcript file at ~/.claude/projects/<cwd>/. Use claude --resume <session-id> to resume a specific past session.
See the Claude Code CLI reference for the full list of flags.
Useful tmux commands for Claude Code
| Command | What it does |
|---|---|
tmux new -s name |
Start a named session |
tmux attach -t name |
Reattach to a session |
tmux ls |
List all running sessions |
tmux kill-session -t name |
Kill a session |
Ctrl+B D |
Detach from current session |
Ctrl+B C |
Create a new window in the session |
Ctrl+B W |
List all windows |
What server size do you need?
Claude Code is not CPU-intensive — it spends most of its time waiting on API responses from Anthropic. The compute requirement is minimal:
- Minimum: 1 vCPU, 1GB RAM (DigitalOcean Basic Droplet at $6/month, Hetzner CX11 at ~€4/month)
- Recommended: 1 vCPU, 2GB RAM if running multiple concurrent sessions
- Note on AWS: EC2 t3.micro (1GB RAM) is marginal for multiple sessions; t3.small (2GB) is safer
Storage: Claude Code's transcript files (.jsonl) are small — a few MB even for long sessions. Standard storage is fine.
Going further: monitoring from your phone
tmux keeps the session alive after you close your terminal. But you still need SSH to check on it — open a client, reconnect, tmux attach. If you want to monitor output, handle agent approval gates, and send new prompts without opening a terminal at all:
npm install -g @grass-ai/ide
In the tmux session (or a second window), run:
grass start --network tailscale
# or: grass start --network remote-ip
A QR code appears. Scan it from the Grass iOS or Android app. Your phone connects to the running session — live output, approval modals, file browser, prompt input. No SSH required.
For Tailscale to work, install it on both the server and your phone (same account). The connection runs over the private Tailscale network — nothing exposed publicly.
Frequently asked questions
How do I install Claude Code on a Linux server?
Install Node.js 18+ via nvm, then run npm install -g @anthropic-ai/claude-code. Set your API key with export ANTHROPIC_API_KEY="sk-..." and add it to ~/.bashrc for persistence. Verify with claude --version.
How do I run Claude Code on AWS EC2?
Same process as any Linux server. Provision an EC2 instance (Ubuntu 22.04 LTS recommended), SSH in, install nvm + Node.js + Claude Code, and wrap sessions in tmux. For t3.micro (1GB RAM), be aware memory may be tight if running multiple sessions — t3.small (2GB) is safer.
How do I keep Claude Code running after I disconnect from SSH?
Use tmux. Start a named session with tmux new -s claude, run claude inside it, and detach with Ctrl+B D. Claude Code keeps running on the server. Reconnect anytime: SSH back in, then tmux attach -t claude.
Can I run Claude Code headlessly on a remote server?
Yes, inside tmux. For fully unattended runs without any approval gates, use claude --dangerously-skip-permissions — but only in isolated environments (containers, throwaway VMs) where a bad command can't cause serious damage.
What size server do I need to run Claude Code?
A 1 vCPU, 1GB RAM server is the minimum. Claude Code waits on API responses most of the time, so CPU matters less than memory. 2GB RAM is recommended for running multiple sessions simultaneously.
How do I set the Anthropic API key on a remote server?
Add it to ~/.bashrc: echo 'export ANTHROPIC_API_KEY="sk-..."' >> ~/.bashrc && source ~/.bashrc. For Docker or systemd environments, pass it as an environment variable in the process definition.
How do I access a Claude Code session running on a remote server from my phone?
Install Grass on the server (npm install -g @grass-ai/ide) and run grass start --network tailscale (requires Tailscale on both server and phone) or grass start --network remote-ip. Scan the QR code from the Grass app. From that point, the Grass app is the interface — no SSH or terminal required.