Skip to content

Offer: your first month of web hosting is free on monthly plans. Order by 7 Jan. See plans

HostEthical
All guides

Guides 13 min read ·

Claude Code on a VPS: How to Run It 24/7 on Ubuntu (Setup, Security and Costs)

Run Claude Code on a VPS so long tasks keep going when your laptop sleeps: specs, headless login, tmux, deploy keys, safe permissions and costs in rupees.

Yes, you can run Claude Code on a VPS, and it's a practical way to keep it working 24/7. Install it as a normal (non-root) user on a Linux server, sign in by opening the login link on your laptop or phone and pasting the code back, and start it inside tmux so the session keeps running after you disconnect. Anthropic asks for 4 GB of RAM or more, and because the model runs on Anthropic's servers, the VPS mainly needs CPU and memory for the builds and tests Claude runs.

This guide uses Claude Code 2.1.330 (released 20 November 2026), Anthropic's native installer and Ubuntu 24.04 LTS, as of November 2026. You need a Claude Pro, Max, Ultra, Team or Enterprise plan, or a Claude Console account billed per token; the free plan doesn't include Claude Code. To have Claude change a live website, see our guide to editing a website with Claude Code.

Why run Claude Code on a VPS instead of your laptop?

A laptop pauses a long task when the lid closes, the battery dies or the Wi-Fi drops. A server doesn't:

  • It's always on. Start a task, close the laptop and check later. Anthropic's Remote Control documentation says to start claude on a remote machine "inside tmux or screen to keep the session running after you disconnect from SSH".
  • Long tasks survive. A dependency upgrade or a slow test suite can run for an hour while you're away, and Claude can notify your phone when it needs a decision.
  • It works close to your server's code. A Linux VPS with the same OS and runtime versions as production lets Claude reproduce bugs and run the real build. Use a staging box, never the production server.
  • It's a clean, disposable environment. Anthropic's sandbox guide says a dedicated virtual machine "provides the strongest separation, with its own kernel". Your laptop's files and personal SSH keys stay out of reach.

Anthropic's own cloud sessions (claude.ai/code, or the Code tab in the Claude app) also keep running after you close your laptop, at no cost beyond your plan's usage limits, and they're the easier choice for self-contained tasks on a GitHub repository. How the options compare:

Your laptopAnthropic cloud sessionYour own VPS
Keeps working with the laptop closedNoYesYes
Extra costNoneNone, counts toward plan limitsServer rent
RepositoriesAnyGitHub; other hosts upload as a bundle and can't push backAny git host
Between sessionsEverything staysVM reclaimed when idle; background work stopsFiles, databases and services stay
Pay-per-token API keyYesNo, needs a claude.ai subscriptionYes

What specs does a VPS for Claude Code need?

Anthropic's system requirements are Ubuntu 20.04 or later, Debian 10 or later, or Alpine Linux 3.19 or later; 4 GB of RAM or more; an x64 or ARM64 processor; and an internet connection. Node.js isn't needed: the native installer downloads a standalone binary, and only the optional npm package requires Node.js 22 or later.

Claude Code is mostly network-bound: it sends your prompts and the files Claude reads to Anthropic's API and waits for the answer. CPU and RAM go to what Claude runs on the server, such as npm install, compiling, test suites, Docker containers and databases, multiplied by however many sessions run in parallel. As a rule of thumb (our guidance, not a benchmark):

  • 4 GB RAM: Anthropic's minimum, enough for one small project. Installing needs roughly 512 MB free; Anthropic's troubleshooting page says a Killed message during install usually means the server ran out of memory.
  • 8 GB RAM, 4 vCPU: comfortable for one or two active projects with Node.js, PHP or Python builds, tests and a small database.
  • 12 GB or more: Docker-heavy stacks (see our Docker on a VPS guide), large monorepos or several Claude sessions at once.

Leave disk space for dependencies, Docker images and build output too.

How to set up Claude Code on an Ubuntu 24.04 VPS

Start from a fresh Ubuntu 24.04 server with SSH keys, updates and the ufw firewall configured as in our guide to setting up a new VPS. Only SSH needs to be open. For Remote Control, Anthropic says the session "makes outbound HTTPS requests only and never opens inbound ports".

1. Create a separate user without sudo

Run Claude Code as its own user, not root and not your admin account. If Claude runs a command you didn't expect, it can only touch that user's files. As your existing sudo user:

sudo apt update && sudo apt install -y git tmux curl
sudo adduser coder                     # set a password; don't add it to the sudo group
sudo mkdir -p /home/coder/.ssh
sudo cp ~/.ssh/authorized_keys /home/coder/.ssh/
sudo chown -R coder:coder /home/coder/.ssh
sudo chmod 700 /home/coder/.ssh
sudo chmod 600 /home/coder/.ssh/authorized_keys

Then log in as the new user (ssh coder@your-server-ip) for every remaining step.

2. Install Claude Code with the native installer

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

# only if the shell says "claude: command not found":
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

The native installer is Anthropic's recommended method. It puts claude in ~/.local/bin and updates itself in the background. claude doctor checks the installation and settings without starting a session. Anthropic also publishes a signed apt repository, updated with apt instead.

3. Sign in on a server with no browser

claude auth login
claude auth status --text

claude auth login prints a login URL. Open it in a browser on your laptop or phone and sign in; the browser then shows a code, which you paste at the terminal's Paste code here prompt. This is Anthropic's documented method for SSH and container logins.

The login is saved in ~/.claude/.credentials.json, readable only by coder. It expires: claude auth status --text shows when, and the authentication docs say using Claude Code doesn't extend it, so run /login before that date. To pay per token instead, set ANTHROPIC_API_KEY to a Claude Console key; Remote Control and cloud sessions still need a claude.ai login.

4. Add an SSH deploy key for one repository

A GitHub deploy key is an SSH key that grants access to a single repository. Create a key for this project only:

ssh-keygen -t ed25519 -C "coder@claude-vps" -f ~/.ssh/myapp_deploy_key
cat ~/.ssh/myapp_deploy_key.pub      # copy this line

# then add this block to ~/.ssh/config (nano ~/.ssh/config):
Host github.com-myapp
    Hostname github.com
    IdentityFile /home/coder/.ssh/myapp_deploy_key
    IdentitiesOnly yes

ssh -T git@github.com-myapp            # answer "yes" to the host key prompt

In the repository's Settings on GitHub, open Deploy keys, click Add deploy key and paste the public key. IdentitiesOnly yes makes SSH offer only this key, even if you forwarded your laptop's SSH agent. Keys are read-only by default; tick "Allow write access" only if Claude should push branches. GitHub notes that deploy keys usually have no passphrase, so a compromised server exposes the key, which is why it should open only one repository. Protect your main branch so changes from the VPS arrive as pull requests you review.

5. Clone the project into its own folder

mkdir -p ~/projects
git clone git@github.com-myapp:OWNER/myapp.git ~/projects/myapp
git config --global user.name "Claude on VPS"
git config --global user.email "you@example.com"

Always start Claude Code inside a project folder like this one. It asks you to trust each new folder once, but in your home directory, the security docs say that trust isn't saved, so the prompt returns every time.

6. Start Claude inside tmux so it survives disconnects

Anthropic's terminal guide recommends these lines in ~/.tmux.conf so Shift+Enter inserts a new line inside tmux and desktop notifications reach terminals such as Ghostty, Kitty or iTerm2. Add them before you start tmux. If tmux is already running, run tmux source-file ~/.tmux.conf, then detach, attach again and restart Claude Code. Ubuntu 24.04 ships tmux 3.4, new enough for all four lines:

set -g allow-passthrough on
set -g focus-events on
set -s extended-keys on
set -as terminal-features 'xterm*:extkeys'
tmux new -s claude
cd ~/projects/myapp
claude
# detach: press Ctrl+B, then D. Claude keeps working.
# after you SSH in again:
tmux attach -t claude

A tmux session ends when the server reboots. Claude Code's own background sessions (claude --bg "task", managed with claude agents) are a research preview that keeps sessions running without a terminal, also until the machine shuts down.

Give Claude Code a server that never sleeps. VPS Starter has 4 vCPU and 8 GB RAM, full root and a dedicated IPv4, in Mumbai or Germany, from ₹860 a month, or about ₹774.17 a month when billed yearly. See VPS plans →

How do you use Claude Code safely on a server?

Claude Code can do anything its Linux user can, so the server set-up is your first safety layer and Claude Code's settings the second.

  • Keep production secrets off the box. Use a staging database and test API keys. Anthropic's sandbox guide warns: "Any approach that allows network egress can still leak data the agent can read." Its dev container guidance says to keep host secrets such as ~/.ssh out and "prefer repository-scoped or short-lived tokens".
  • Keep the no-sudo user from step 1. Never run Claude Code as root or your admin account.
  • Choose a permission mode deliberately. From the permission modes page:
ModeWhat runs without askingAnthropic's "best for"
default (Manual)File reads in your working foldersSensitive work, unfamiliar code
acceptEditsReads, file edits and common file commandsIterating on code you're reviewing
planReads, plus commands the classifier approves when auto mode is available; edits wait until you approve a planExploring a codebase before changing it
autoEverything, with background safety checks by a classifier modelLong tasks, reducing prompt fatigue
dontAskFile reads in your working folders and pre-approved tools; anything that would prompt is deniedLocked-down CI and scripts
bypassPermissionsEverythingIsolated containers and VMs only

From version 2.1.283, auto mode is the starting mode for interactive terminal sessions when your model and settings allow it (otherwise Claude Code starts in Manual), and Anthropic warns that it "reduces permission prompts but does not guarantee safety". Switch modes with Shift+Tab, or start with claude --permission-mode plan. Skip bypassPermissions (--dangerously-skip-permissions) on an ordinary VPS: Anthropic says to use it only in isolated environments "without internet access", and on Linux Claude Code refuses to start in that mode as root or under sudo.

Then deny Claude's tools access to secret files in ~/.claude/settings.json:

{
  "permissions": {
    "deny": [
      "Read(.env)",
      "Read(.env.*)",
      "Read(~/.ssh/**)"
    ]
  }
}

The permissions docs say these rules cover Claude's file tools and commands it recognises, such as cat, but not a script that opens files itself. For operating-system enforcement on shell commands, turn on the sandboxed Bash tool:

sudo apt-get install bubblewrap socat    # as your sudo user
# then restart Claude Code as coder and run:
/sandbox

The sandbox is off by default. Once on, shell commands can write only to the project folder, a temp directory and folders you add, and network traffic goes through a proxy whose allowed-domain list starts empty. In auto mode, a host that isn't on the list is usually refused, so add your package registry and other domains your builds need to sandbox.network.allowedDomains. Commands that fail in the sandbox can be retried outside it; turn on strict sandbox mode in the /sandbox Overrides tab to stop that. The sandbox covers shell commands only, and docker is incompatible with it. If /sandbox reports Ubuntu's AppArmor restriction on user namespaces, the sandboxing page gives the fix.

For prompt-free unattended runs, Anthropic's reference dev container adds an outbound firewall and a non-root user, though Anthropic warns that a malicious project could still exfiltrate anything in the container, including Claude's credentials. Use it only with trusted repositories.

On data: under Anthropic's data usage policy, Pro, Max and Ultra data trains models while the model-improvement setting is on (5-year retention; 30 days with it off). Team, Enterprise and API usage isn't used for training and is kept 30 days as standard.

How do you connect to Claude Code from your laptop or phone?

From a laptop, use SSH: ssh coder@your-server-ip, then tmux attach -t claude. SSH apps on phones work too, if clumsily.

The easier way from a phone is Remote Control. It connects claude.ai/code or the Claude app for Android and iOS to a session running on your VPS, while the code and commands stay on the server:

tmux new -s rc
cd ~/projects/myapp
claude remote-control --name "myapp on VPS"
# press the spacebar to show a QR code, then scan it with your phone

In the Claude app, tap Code to find the session, or run /remote-control inside a session that's already open. It works on Pro, Max, Ultra, Team and Enterprise plans (Team and Enterprise Owners must switch it on first), but not with API keys. While connected, the transcript is stored on Anthropic's servers. Turn on push notifications in /config to hear when a task finishes or needs a decision. If the VPS loses its network connection for roughly 10 minutes, claude remote-control exits; run it again in the same folder within about four hours to bring its sessions back.

Channels, a research preview, let you message a running session through your own Telegram or Discord bot.

How much does it cost to run Claude Code on a VPS?

Anthropic's plans as of November 2026, with rupee figures at ₹92.9 to the dollar (the 23 November 2026 rate):

PlanPrice (US$)About (₹)Usage
Pro$20 a month, or $17 a month billed yearly ($200 up front)₹1,860 a monthThe base level
Max$100 a month₹9,290 a month5x Pro usage
Ultra$200 a month₹18,580 a month10x Pro usage a week; no 5-hour limit for verified accounts
TeamStandard seat $25 a month, or $20 a month billed yearly (2 to 150 seats)₹2,320 per seatMore than Pro; Premium seats ($125, or $100 billed yearly) get 5x a Standard seat
API (Claude Console)Pay per tokenVariesBilled on usage; API rate limits apply

Anthropic's prices don't include applicable tax. Enterprise is US$20 per seat a month, billed yearly with a 20-seat minimum, plus usage at API rates. For API billing, Anthropic's cost guide says the average across enterprise deployments is about $13 per developer per active day (about ₹1,210) and $150 to $250 a month, with 90% of users below $30 per active day.

On HostEthical, VPS Starter in Germany costs ₹860 a month, or about ₹774.17 a month when billed yearly; Mumbai adds ₹380 a month. For a solo developer, a Pro plan plus VPS Starter is a sensible start; move up a Claude plan if you keep hitting usage limits.

Running Claude Code on HostEthical

A HostEthical Cloud VPS gives you an unmanaged KVM server with full root access, a dedicated IPv4 address, SSD storage and Ubuntu 24.04 LTS among the OS choices, built automatically after payment, usually within 5 to 15 minutes. If an experiment leaves a mess, reinstall the OS from the dashboard and repeat the steps above. You pay in rupees by UPI or binance Pay (USDT), and the price stays the same at renewal.

PlanvCPURAMStoragePaid monthlyPaid up front, per monthAt renewal
VPS Starter4 cores8 GB100 GB SSD₹860₹774.17 (yearly)Same price
VPS Pro6 cores12 GB200 GB SSD₹1,170₹1,053.33 (yearly)Same price
VPS Max8 cores24 GB300 GB SSD₹2,190₹1,971.67 (yearly)Same price

VPS Starter's 8 GB and 4 vCPU are plenty for one or two projects with their builds and a small database. Move to VPS Pro or Max for Docker-heavy stacks, monorepos or several parallel sessions. Choose Mumbai if you're in India: your SSH sessions travel a shorter distance and the repository stays on a server in India, for ₹380 a month more than Germany. Whatever Claude reads still goes to Anthropic's API wherever the server is. Our guide to VPS hosting in Mumbai covers the trade-off.

When Claude has built something worth publishing, the same VPS can host it: see deploying Next.js on a VPS. You can register the domain with us and point its A records at the server with our nameservers and DNS editor.

Run Claude Code around the clock. Pick VPS Starter in Mumbai or Germany, pay by UPI, and follow the six steps above. See Cloud VPS →

Frequently asked questions

Does Claude Code need a GPU or a powerful VPS?

No GPU is needed. The model runs on Anthropic's servers, so the VPS only runs the Claude Code program and the commands Claude starts. Anthropic's minimum is 4 GB of RAM on an x64 or ARM64 processor (as of November 2026); your builds, tests, Docker containers and databases decide how much more you need.

What happens to Claude Code sessions when the VPS reboots?

Running work stops: tmux sessions and Claude Code's background sessions both end when the server shuts down. After the reboot, SSH in, start tmux again and run claude --continue or claude --resume in the project folder to reopen the conversation, because transcripts are kept locally for 30 days by default. A claude remote-control server can bring back its sessions if you restart it within about four hours.

Can I run Claude Code from cron or scripts on a VPS?

Yes. claude -p "your prompt" runs a task non-interactively, which suits cron jobs and CI. To authenticate without a browser each time, claude setup-token creates a one-year token for a Pro, Max, Ultra, Team or Enterprise plan that you set as CLAUDE_CODE_OAUTH_TOKEN, or you can use a Claude Console API key. In claude -p runs, tool calls that need approval are denied rather than prompting, so give scripts allow rules for the tools they need (for example with --allowedTools), or use dontAsk mode, which Anthropic lists as best for locked-down CI and scripts.

Can two developers share one Claude Code VPS?

Yes, if each developer has their own Linux user and their own Claude login. Claude Code keeps credentials, settings and session history per user under ~/.claude, with the credentials file readable only by that user. On a Claude Team plan each member signs in with their own seat (a Standard seat is US$25 a month, or US$20 a month billed yearly, as of November 2026); give each person their own project folder or git worktree so sessions don't edit the same files.

Should Claude Code have access to my production server?

It's safer not to. Claude Code can run any command its Linux user can, so production SSH keys or cloud credentials on the same box put production within its reach, and Anthropic's guidance favours repository-scoped or short-lived tokens. Let Claude push to a branch with a deploy key, review the pull request, and deploy through CI or by hand.