How to install Claude Code on a VPS and run it 24/7

· 0x.cloud Team

How to install Claude Code on a VPS and run it 24/7

To install Claude Code on a VPS, open the web console of an Ubuntu 24.04 server, run the official installer curl -fsSL https://claude.ai/install.sh | bash, log in headlessly with a login URL or a claude setup-token token, and run the agent inside tmux. The agent keeps working while your laptop sleeps, and a dropped connection doesn't kill the session. You need a Claude Pro, Max, Ultra, Team, Enterprise or Claude Console account and a server with at least 4 GB RAM.

Let your agent prepare the server:

Prompt for an AI agent

Create an s2-4 server on 0x.cloud with the AI agents image and hourly billing. Show the dry_run price and wait for my "yes". Then, with run_command, create a sudo user called agent, enable linger for it, install Claude Code with the official installer as agent and run claude doctor. Send me the steps to log in with setup-token in the web console.

Claude Code VPS requirements

Requirement Value
OS Ubuntu 20.04+, Debian 10+ (we use Ubuntu 24.04 LTS)
Memory 4 GB RAM or more, x64 or ARM64
Account Claude Pro, Max, Ultra, Team, Enterprise or Claude Console
0x.cloud plan s2-4: 2 vCPU, 4 GB RAM, 60 GB NVMe, $15.99/mo

The free Claude.ai plan doesn't include Claude Code. s2-4 fits the agent plus builds and Docker-based tests. The 0x.cloud AI agents image comes with Claude Code and Codex (installed with npm), Node, Python, Git, tmux and Docker preinstalled, and you bring your own model keys. More on sizing at VPS for Claude Code.

Why not the cheaper s1-2? 4 GB of RAM is the official minimum in the Claude Code docs, and the agent shares the box with git, npm install, test runs and the Docker containers it starts. On 2 GB the process risks getting Killed mid-task. Two cores on s2-4 let the agent build while you read its output.

Trying it costs very little: s2-4 on hourly billing is $0.109520 an hour ($15.99 / 730 × 5), and setup is $0. Not for you? Delete the server and the remainder returns to your balance.

Deploy to 0x.cloud

Prepare the server

Don't run the agent as root. Create a dedicated user:

sudo adduser agent
sudo usermod -aG sudo agent

adduser creates the user and home folder, and usermod -aG sudo grants admin rights. Skip the second line if the agent shouldn't be an admin. Then let its services run without an open session:

sudo loginctl enable-linger agent

Check: loginctl show-user agent -p Linger prints Linger=yes. See how to add a sudo user on Ubuntu.

Block everything except SSH:

sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

The output should list only OpenSSH ALLOW Anywhere (plus its IPv6 twin). More rules are in the UFW firewall guide. Then install basic tools (already present on the AI agents image):

sudo apt update && sudo apt install -y git tmux curl

Install Claude Code on the VPS

Log in as agent at the login prompt of the web console in your cabinet and run the official installer:

curl -fsSL https://claude.ai/install.sh | bash

The script downloads the Claude Code binary to ~/.local/share/claude, links ~/.local/bin/claude and enables background auto-updates. No Node.js required. Make sure the folder is on your PATH, then verify:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
claude --version
claude doctor

claude --version prints the version, such as 2.1.329 (Claude Code), and claude doctor checks the install, settings and the last update attempt; its Auto-updates line should read enabled.

Prefer package-managed updates? Anthropic publishes a signed apt repository with a stable channel; the commands are in the official setup docs. apt installs don't self-update, so sudo apt upgrade handles them.

Headless login: URL, setup-token or API key

There's no browser on the server, so pick one of three methods.

1. Login URL and code. Run claude and choose account login. Open the URL it prints on your own computer, sign in, and paste the code into the Paste code here if prompted prompt.

2. Long-lived token. On a machine with a browser, run:

claude setup-token

It prints a one-year OAuth token. On the server, keep it in a private file:

echo 'export CLAUDE_CODE_OAUTH_TOKEN=your_token' > ~/.claude-token
chmod 600 ~/.claude-token
echo 'source ~/.claude-token' >> ~/.bashrc

The token uses your subscription and can only make model requests. Locally configured MCP servers still work.

3. Claude Console API key. Set ANTHROPIC_API_KEY the same way to bill through the API. Don't keep both a key and a token on the server: ANTHROPIC_API_KEY ranks above your subscription. In interactive mode Claude Code asks once whether to use the key; in claude -p mode it uses the key without asking, and requests bill the API.

Check your login: run /status inside claude. The login row should show your account or plan, not an API key, if you meant to use your subscription.

Run Claude Code 24/7 with tmux and autostart

Logging out kills foreground processes, including claude. Use tmux:

tmux new -s claude      # new session
cd ~/project && claude  # run the agent inside it
# Ctrl+b, then d: detach, the agent keeps working
tmux attach -t claude   # come back later

Our tmux guide covers windows and panes. To recreate the tmux session after every reboot, add a user service:

mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/tmux-claude.service
[Unit]
Description=tmux session for Claude Code

[Service]
Type=forking
ExecStart=/usr/bin/tmux new-session -d -s claude
ExecStop=/usr/bin/tmux kill-session -t claude

[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable --now tmux-claude
systemctl --user status tmux-claude
tmux ls

Run these logged in as agent at the web console's login prompt: after sudo -iu agent, systemctl --user fails with Failed to connect to bus. The status should read active (running) and tmux ls should list the claude session. The linger setting you enabled earlier lets user services run without an active login, so the claude session is waiting for you after a reboot. For unattended jobs, run the non-interactive mode claude -p "task" from cron or a systemd timer. Overnight workflows are covered in run Claude Code 24/7.

Update Claude Code

The native install updates itself in the background. To update right now:

claude update

To get builds that are about a week old and skip releases with major regressions, switch the Auto-update channel to stable in /config. For apt installs: sudo apt update && sudo apt upgrade claude-code.

Back up your setup

Settings, session history and credentials live in ~/.claude and ~/.claude.json. Keep projects in Git and push the agent's branches to a remote.

tar czf ~/claude-config-$(date +%F).tar.gz --exclude='.credentials.json' -C ~ .claude .claude.json

.credentials.json is excluded on purpose: logging in again after a restore is safer. On 0x.cloud, take a $0.99/mo snapshot before risky experiments and roll back if the agent breaks something.

Troubleshooting

Symptom Fix
claude: command not found ~/.local/bin isn't on PATH. Add it to ~/.bashrc and open a new shell
Usage bills the API instead of your plan ANTHROPIC_API_KEY is set. Run unset ANTHROPIC_API_KEY and check /status
Login expired The login or token expired. Run /login or a new claude setup-token
Process Killed Out of memory. Use 4 GB RAM or more, add swap or move to s2-4
Session gone after you log out Always start the agent inside tmux
Agent stuck on a permission prompt overnight Pre-approve the tools it needs with /permissions or project settings

If the agent needs to reach your other servers, set that up safely with Claude Code SSH access.

0x.cloud servers are in Warsaw, and support answers in about 30 minutes on average during business hours (06:00–20:00 UTC). If the agent breaks the system, an OS reinstall costs $0, and a snapshot before a risky task is $0.99/mo.

FAQ

What are the Claude Code VPS requirements? Officially: Ubuntu 20.04+ or Debian 10+, 4 GB RAM or more, and an x64 or ARM64 CPU. On 0x.cloud that's the s2-4 plan (2 vCPU, 4 GB RAM, 60 GB NVMe) at $15.99/mo.

How do I log in to Claude Code on a headless server? Run claude, open the login URL on your own computer and paste the code back into the terminal. Or run claude setup-token on a machine with a browser and set the token as CLAUDE_CODE_OAUTH_TOKEN on the server.

Do I need Node.js to install Claude Code? No. The native installer ships a standalone binary. Node.js 22+ is only needed for the npm install method.

Does Claude Code work with a free Claude account? No. You need a Pro, Max, Ultra, Team or Enterprise subscription, or a Claude Console account with API billing.

How do I keep Claude Code running after I disconnect? Start claude inside tmux. The session keeps running on the server and you reattach with tmux attach -t claude.

Deploy to 0x.cloud