← All Guides

Guide

Claude Code VPS Hosting: Run Claude Code 24/7

How to run Claude Code on your own Linux server, sign in without a desktop browser, keep sessions alive, and keep an agent that can run shell commands from touching anything else. Built from Anthropic's own Claude Code documentation.

The short answer

Yes, Claude Code runs fine on a VPS. Create a non-root user on an Ubuntu, Debian or Alpine server with at least 4 GB of RAM, install it with Anthropic's native installer, sign in once over SSH, and run it inside tmux. The model runs at Anthropic, so the server is a place for the CLI, your repository and your build tools, not for inference. If you would rather not administer a server, the same CLI is pre-installed in our hosted coding workspace, covered near the end.

Why run Claude Code on a server

  • Sessions that outlive your laptop. A long refactor or test-fix loop keeps going in a detached terminal while your own machine sleeps.
  • One environment from any device. SSH in from a phone, a borrowed computer or your desk and find the same checkout, the same ~/.claude history and the same installed toolchain.
  • Scripted and scheduled runs. Claude Code has a non-interactive mode (claude -p) that Anthropic documents for scripts and CI, so a cron job on an always-on box can run it.
  • A dedicated, disposable machine. An agent that edits files and runs commands is easier to live with on a box that holds nothing else you care about.

Claude Code on a VPS versus Remote Control and cloud sessions

Anthropic offers two features people confuse with self-hosting, and they are different things. Per Anthropic's docs:

Where Claude runsWhat you need
Your own VPSThe server you rentA Linux box you maintain; any supported sign-in method
Remote ControlYour machine. The docs say Claude keeps running locally the whole time and only the claude.ai or Claude app view is remoteA Pro, Max, Team or Enterprise login; API keys are not supported
Cloud sessionsAnthropic-managed VMs by default, or an organization's self-hosted environmentA Pro, Max or Team plan (or Enterprise seats); the repository is normally cloned from your GitHub remote, and bypass-permissions mode is not available

Remote Control is the right tool when you already have a computer that stays on and you want to steer it from your phone. Cloud sessions fit GitHub-centred work you want Anthropic to host. A VPS is for when you want your own Linux shell, any repository, your own installed tools and a choice of sign-in. You can combine them: Remote Control also works on a server, through claude remote-control.

What a Claude Code server needs

From Anthropic's setup page: Ubuntu 20.04+, Debian 10+ or Alpine Linux 3.19+ (also macOS 13+ and Windows 10 1809+), 4 GB+ of RAM, an x64 or ARM64 processor, an internet connection and a supported country. The native install does not need Node.js; the npm package, which needs Node.js 22 or later, installs the same native binary. On Alpine you need apk add bash curl libgcc libstdc++ ripgrep and USE_BUILTIN_RIPGREP=0.

Size beyond 4 GB by what you run next to it: compilers, test suites, Docker and dev servers are the real load, not the CLI. Prices checked October 2026:

PlanvCPU / RAM / diskPrice
OVHcloud VPS-12 / 4 GB / 40 GB$4.54/mo billed annually
Hostinger KVM 22 / 8 GB / 100 GB$8.99/mo on a 2-year term (renews $14.99)
Hetzner CPX222 / 4 GB / 80 GB€19.49/mo before VAT
Vultr2 / 4 GB / 80 GB$20/mo
DigitalOcean Basic2 / 4 GiB / 80 GiB$24/mo

For broader VPS shopping notes see the hosting page; the comparison logic is the same one we use in best VPS for OpenClaw.

Step by step: Claude Code on a fresh VPS

1. Create a non-root user

Claude Code can run shell commands as whoever starts it, and it refuses its skip-permissions mode as root, so start unprivileged:

adduser claude
usermod -aG sudo claude   # optional; omit if the agent should not have sudo
su - claude

Leaving sudo off is the safer default. Add SSH keys, disable password login and firewall everything except SSH. Claude Code only makes outbound connections, so it needs no inbound port.

2. Install with the native installer

curl -fsSL https://claude.ai/install.sh | bash
exec bash -l          # reload so the new PATH entry applies
claude --version
claude doctor

That is the command Anthropic lists as recommended. claude doctor prints install health and settings diagnostics. If claude is not found, the docs say the install directory is not on your PATH yet; open a new shell. Anthropic also publishes signed apt, dnf and apk repositories, if you prefer your package manager.

3. Sign in over SSH

Run claude. It normally opens a browser, which a server does not have. The docs give you two ways through: press c to copy the login URL and open it on your own computer, and if your browser then shows a login code instead of redirecting back, paste it at the Paste code here if prompted prompt. Anthropic names SSH sessions as a case where this happens. Credentials are stored in ~/.claude/.credentials.json with file mode 0600 on Linux.

There are three sign-in routes for a server, each with a different billing effect:

  • Subscription login (Pro, Max, Team, Enterprise): usage comes out of your plan.
  • Long-lived token. Run claude setup-token on any machine with a browser; it prints a one-year token and does not save it. Set it on the server as CLAUDE_CODE_OAUTH_TOKEN. It authenticates with your subscription, can only make model requests, and cannot establish Remote Control sessions or fetch claude.ai connectors.
  • API key. Set ANTHROPIC_API_KEY from the Claude Console and usage is billed per token to that account. In claude -p the key is always used when present.

Watch the precedence. Anthropic's docs rank ANTHROPIC_API_KEY above CLAUDE_CODE_OAUTH_TOKEN and above a /login subscription login, and note that with both configured it uses the key once approved. A stray exported key in a shell profile can silently move you from your subscription to pay-per-token billing. Run /status to see which credential is active, and unset ANTHROPIC_API_KEY to fall back.

4. Keep sessions alive

sudo apt install tmux
tmux new -s claude
cd ~/project && claude
# detach: Ctrl-b then d      reattach: tmux attach -t claude

For unattended jobs, claude -p "your prompt" runs once and exits with a status code; --output-format json returns the result with a session ID and a cost estimate, and --continue or --resume <id> picks a conversation back up. Two documented details matter on a server: a background shell Claude started during a -p run is terminated about five seconds after the final result, and --bare skips hooks, MCP servers and CLAUDE.md for repeatable runs but also does not read OAuth tokens, so it needs an API key.

To reach a running session from the Claude app, run claude remote-control inside tmux. It stays up in server mode and prints a session URL. It needs a claude.ai subscription login, so it will not work with an API key or a setup-token token.

5. Update

Native installs update themselves in the background; claude update applies one immediately. Package-manager installs do not auto-update. If you want a slower cadence, Anthropic documents an autoUpdatesChannel setting with stable (typically about a week behind, skipping releases with major regressions) or latest, which is the default.

Permissions and the sandbox: the part that matters on a server

Claude Code asks before it does risky things; how often depends on the permission mode. Anthropic documents default, acceptEdits, plan, auto, dontAsk and bypassPermissions. On v2.1.283 or later, auto mode, where a classifier reviews actions instead of you, is the built-in starting mode for interactive terminal sessions. dontAsk denies anything that would prompt, which suits locked-down scripts, and bypassPermissions allows everything, which Anthropic says belongs only in isolated containers and VMs.

  • Use the OS sandbox. The built-in Bash sandbox restricts which files and network hosts shell commands can reach. On Linux it needs sudo apt-get install bubblewrap socat; run /sandbox to enable it. On Ubuntu 24.04 and later, Anthropic notes the default AppArmor policy blocks bubblewrap and gives a profile to allow it. The sandbox covers shell commands only: file tools, MCP servers and hooks run outside it.
  • Bypass mode only in a container. Anthropic's dev container page warns that with --dangerously-skip-permissions, a malicious project can exfiltrate anything reachable inside the container, including the Claude credentials in ~/.claude, and says not to mount host secrets such as ~/.ssh. Pair it with an egress allowlist.
  • Treat the box as exposed to the agent. It can run commands with its user's permissions. Do not put production credentials, other users' data or unrelated services on the same machine.
  • No ports to open. Unlike agents with a web UI, the terminal CLI needs no public port. Reach it with SSH, or Tailscale if you prefer; do not publish anything you add alongside it, and bind any dev server to 127.0.0.1 and use ssh -L to view it.

What Anthropic says about subscriptions, API keys and servers

A frequent search is whether Claude Code on a VPS with a subscription or key is allowed. We will not give a legal answer, but Anthropic's legal and compliance page is short and says this, paraphrased:

  • Claude Code use is governed by the Consumer Terms of Service for Free, Pro and Max users and the Commercial Terms for Team, Enterprise and API users, and by the Anthropic Usage Policy.
  • OAuth authentication is “intended exclusively for purchasers of Claude Free, Pro, Max, Team, and Enterprise subscription plans” and is designed for “ordinary use of Claude Code and other native Anthropic applications.” Advertised Pro and Max limits assume ordinary, individual usage of Claude Code and the Agent SDK.
  • Developers building products or services on Claude should use API key authentication through the Claude Console or a supported cloud provider. Third-party developers may not route requests through Free, Pro or Max credentials on behalf of their users.
  • Provisioning your own API key in a development environment is not restricted by that rule provided usage is billed to the key owner, and the page says it does not prevent an end user signing in to the unmodified Claude Code binary with their own subscription, including where a platform hosts Claude Code.

Whichever route you use, the credential should be your own, and it should be the unmodified binary. If your use is anything beyond personal work, read the page and use the contact link it gives.

Self-managed VPS versus managed

Your own VPSCoding Harness (managed)
Cost$4.54 to $24 a month for the plans above (€19.49 before VAT for Hetzner)Lite $3 first month, then $6 ($60/yr); Pro $20 ($200/yr); 30-minute free trial
SetupUser, hardening, install, sign-in, tmux, sandboxOpen the workspace card, sign in at the terminal
Updates and OS patchingYouHandled for you
Claude usageBilled by your Anthropic accountBilled by your Anthropic account
Root access and region choiceYesA browser terminal in a workspace

The managed option: OpenClaw Launch Coding Harness

A coding workspace is a hosted Linux box you open in the browser, with eight coding CLIs pre-installed: Claude Code, Codex, OpenCode, Aider, OpenClaude, Zero, Pi and DeepSeek Harness. You pick one from the workspace card and they all share the same persisted /workspace directory, which survives restarts; Reset and Wipe are available. Each CLI signs in its own native way, in the terminal. For Claude Code that is a Claude subscription login or an API key. The workspace deliberately does not inject your saved provider API keys under the variable names a CLI reads, because an ambient API key would silently override a subscription login and bill pay-per-token instead, which is the precedence trap described above.

For Telegram, click Telegram on the workspace card, paste a new bot token from @BotFather and open the one-time pairing link. After that, each message to the bot runs Codex, Claude Code or OpenCode inside the workspace, follow-ups continue the same conversation, and the result comes back in chat. Only the paired Telegram account can use it.

A workspace uses one of your plan's instance slots at normal plan pricing and is sized by plan. Lite is $3 for the first month, then $6 a month (or $60 a year): 1 vCPU, 2 GB RAM, 10 GB storage, 1 instance. Pro is $20 a month (or $200 a year): 2 vCPU, 4 GB RAM, 40 GB storage, up to 3 instances. The free trial is 30 minutes with no credit card and is sized as Lite. Model usage is billed by your own provider account or subscription. Note that Lite's 2 GB is below the 4 GB Anthropic lists for Claude Code, so choose Pro for heavy work. OpenClaw Launch also hosts chat agents (OpenClaw and Hermes Agent) on Telegram, Discord and WhatsApp; see Hermes hosting and the hosting page. A coding workspace is a developer environment, not a chatbot.

Frequently Asked Questions

Can I run Claude Code on a VPS?

Yes. Anthropic's setup page lists Ubuntu 20.04+, Debian 10+ and Alpine Linux 3.19+ on x64 or ARM64 with 4 GB or more of RAM and an internet connection. Install it with the native installer, run claude in a terminal on the server and sign in. It is a terminal program, so an SSH session is all you need to drive it.

How do I sign in to Claude Code on a headless server?

Run claude and follow the login prompt. Anthropic's authentication page says that if the browser cannot reach Claude Code's local callback server, which is common in SSH sessions, the browser shows a login code instead; paste it at the 'Paste code here if prompted' prompt in the terminal. For scripts and unattended jobs, claude setup-token prints a one-year token that you set as CLAUDE_CODE_OAUTH_TOKEN. You can also set ANTHROPIC_API_KEY with a Claude Console key.

Does Anthropic allow running Claude Code on a VPS with my subscription or an API key?

Anthropic's legal and compliance page says Claude Code is governed by the Consumer Terms for Free, Pro and Max users and the Commercial Terms for Team, Enterprise and API users. It says OAuth authentication is intended exclusively for purchasers of Claude subscription plans and is designed to support ordinary use of Claude Code and other native Anthropic applications, and that advertised Pro and Max limits assume ordinary, individual usage. It also says developers building products or services on Claude should use API key authentication, and that this does not prevent an end user from signing in to the unmodified Claude Code binary with their own subscription. We are not lawyers and this is not legal advice; read the page itself, and contact Anthropic sales if your use case is unclear. See Anthropic: Legal and compliance.

Do I need a VPS if I just want Claude Code from my phone?

Not necessarily. Anthropic's Remote Control lets claude.ai/code or the Claude mobile app steer a Claude Code session, but the session keeps running on your own machine, so something has to stay on. Cloud sessions run on Anthropic's infrastructure instead, they normally clone your GitHub remote (Claude Code can upload a local repository in some cases), and they need one of the Claude plans Anthropic lists. A VPS or a hosted workspace is the option that gives you your own always-on Linux box with a shell.

How do I keep Claude Code running after I close SSH?

Start it inside tmux or screen on the server and detach, then reattach later. For scheduled or scripted work, claude -p runs one prompt and exits, and claude -p with --continue or --resume picks a conversation back up. If you want to reach a running session from the Claude app, claude remote-control keeps a server process waiting for connections, and it needs a claude.ai subscription login rather than an API key.

Is it safe to use --dangerously-skip-permissions on a VPS?

Only inside something isolated. Anthropic's permission-modes page says bypassPermissions should be used only in isolated environments such as containers or VMs, and Claude Code refuses to start in that mode as root. Even then, a bypassed session can read anything the user can read, including the Claude credentials in ~/.claude. Use a throwaway non-root user or container, keep other secrets off the box, and consider the default auto mode or the built-in sandbox first.

How much RAM does a Claude Code VPS need?

Anthropic's stated hardware requirement is 4 GB or more of RAM. The model runs at Anthropic, so Claude Code itself is a thin client, but your repository's builds, tests and dev servers run on the VPS and can need more. Plans such as Hetzner CPX22, Vultr 2 vCPU / 4 GB, OVHcloud VPS-1 and Hostinger KVM 2 meet the 4 GB floor.

What does the managed Coding Harness cost compared with a VPS?

A workspace uses one of your OpenClaw Launch plan's instance slots at normal plan pricing. Lite is $3 for the first month, then $6 a month (or $60 a year) with 1 vCPU, 2 GB RAM and 10 GB storage. Pro is $20 a month (or $200 a year) with 2 vCPU, 4 GB RAM, 40 GB storage and up to 3 instances. The free trial is 30 minutes with no credit card. Your Claude usage is billed by your own Anthropic account or subscription. See Coding workspace hosting.

Related Guides

Skip the server

A hosted Linux workspace with Claude Code and seven other coding CLIs pre-installed. Free 30-minute trial, no credit card. Lite is $3 for the first month, then $6/month.

See the coding workspace