Persistent VMs are now available.Learn more

Claude Code in the Cloud: Running It on a Persistent VM

Engineering
Eli Mernit13 min read
Claude Code in the Cloud: Running It on a Persistent VM

Most people run Claude Code in the cloud in one of two ways. Anthropic's cloud sessions run it on an Anthropic-managed VM that you start from claude.ai/code or with claude --cloud. The other way is to install Claude Code on a cloud VM of your own and start it inside tmux. Both keep working after you close your laptop. Your own VM also keeps its disk, tools and running services between sessions, at whatever size you choose.

This guide compares the two and walks through the VM setup.

sh
# On your laptop: a 4 vCPU / 8 GiB VM on the Shared CPU tier
beam vm new claude-box --cpu-tier shared --cpu 4 --memory 8192 --no-desktop
beam vm ssh claude-box

# Inside the VM: clone your project and start Claude Code in tmux
apt-get update && apt-get install -y tmux git
git clone https://github.com/your-org/your-repo.git /workspace/your-repo
tmux new -A -s claude
cd /workspace/your-repo
claude

# Detach with Ctrl+B then D. Later, from any machine with the Beam CLI:
beam vm ssh claude-box
tmux attach -t claude

The --cpu-tier flag needs beam-client 0.2.236 or later.

Two ways to run Claude Code in the cloud

Running Claude Code in the cloud means the agent, your repository and its shell commands live on a remote machine, not your laptop. Anthropic hosts that machine for you with cloud sessions, or you bring a VM and run the same CLI you use locally. The table shows where they differ.

Anthropic cloud sessionsClaude Code on your own VM
Where it runsAn Anthropic-managed VM, one per sessionA VM or VPS you create
How you start itclaude.ai/code, the Claude apps, or claude --cloudSSH in and run claude, usually inside tmux
Sign-inA Claude subscription onlyA Claude subscription, an API key or a cloud provider
Machine sizeAbout 4 vCPUs, 16 GB of RAM and 30 GB of diskWhatever you provision
Getting code inClones from GitHub, or uploads a bundle of your local repoAny git host, or copy files over
When it's idleThe VM pauses after a few minutes and can later be reclaimedIt stays up until you stop or pause it
What you pay forPlan usage; no separate charge for the VMModel usage plus the VM

Cloud sessions are the shortest path when your code is on GitHub and the work fits in that machine. Anthropic's docs list them on Pro, Max, Ultra and Team plans and on some Enterprise seats, and they always use your subscription, even if an API key is set in the environment. When a paused session VM has been reclaimed, reopening the session gives you a fresh VM with the conversation history. Background commands that were still running don't come back. Organizations can also route cloud sessions to a self-hosted environment on their own infrastructure, which this guide doesn't cover.

Your own VM is the other route, and it's the one people mean by "Claude Code on a VPS". Nothing about Claude Code changes. You get the same terminal UI, the same ~/.claude directory and the same commands, on a machine that doesn't sleep when your laptop does.

What Claude Code needs from a cloud server

Claude Code needs a small Linux machine with a persistent disk and outbound internet access. It doesn't need a GPU, because the model runs on Anthropic's side and the server only runs the CLI and your project's own tools. Five things matter:

  • A supported OS and enough memory. The setup docs ask for Ubuntu 20.04 or later, or Debian 10 or later, with at least 4 GB of RAM on an x64 or ARM64 processor. Size above that for your build and test suite, not for Claude Code.
  • A disk that persists. Sign-in credentials, settings and conversation history live under ~/.claude. If the disk is wiped between sessions, you sign in again and lose the history that claude --continue reads.
  • A way to sign in without a browser. A server has no browser for the login flow, so you finish it from your laptop or use a key or token. The setup steps below cover all three.
  • A session that outlives SSH. A process started in a plain SSH session stops when the connection closes. Anthropic's Remote Control docs say to start claude inside tmux or screen on a remote machine for this reason.
  • No inbound ports. Claude Code makes outbound HTTPS requests only. You don't need to open anything except whatever you use for SSH.

How to run Claude Code on a cloud VM

Running Claude Code on a VM takes five steps: create the machine, put your code on it, sign in, start a tmux session, and detach. The commands below use a Beam VM, a CPU microVM with its own kernel, systemd, SSH and a root disk that persists. Beam's prepared VM images already include the Claude Code CLI. On any other Ubuntu or Debian server, install it first with curl -fsSL https://claude.ai/install.sh | bash, and the remaining steps are the same.

1. Create the VM. The default Beam VM has 4 vCPUs, 8 GiB of RAM and a 50 GiB disk on Ubuntu 24.04. This command keeps that size, opts into the Shared CPU tier and skips the browser desktop that the CLI adds by default:

sh
beam vm new claude-box --cpu-tier shared --cpu 4 --memory 8192 --no-desktop
beam vm ssh claude-box

beam vm ssh connects as root through an authenticated tunnel, so there's no public SSH port to harden. A VM has no idle timeout unless you set one. It keeps running, and billing, after you close the terminal.

2. Put your code on it. Clone the repository inside the VM so Claude Code has the git history and can commit:

sh
apt-get update && apt-get install -y tmux git
git clone https://github.com/your-org/your-repo.git /workspace/your-repo

beam vm sync claude-box ./my-project also uploads a local directory to /workspace, but it leaves out .git, so use it for files and not for a repository you want Claude to commit to. For a private repository, add a deploy key or a fine-grained token with access to that one repository instead of copying your personal SSH key to the server.

3. Sign in. Pick one of three ways:

  • Subscription login. Run claude, or claude auth login from the shell, and choose your Claude account. No browser opens on a server, so open the login URL on your laptop, sign in, and paste the code the browser shows back into the terminal. This is the only sign-in that supports Remote Control. The login has an end date, and using Claude Code doesn't extend it. On Claude Code 2.1.318 or later, claude auth status --text prints a Sign-in ends line, and /login renews the login before that date.
  • Long-lived token. On your laptop, run claude setup-token. It prints a one-year token tied to your subscription. On the VM, set it as CLAUDE_CODE_OAUTH_TOKEN. The token can make model requests only, so it can't start a Remote Control session.
  • API key. Set ANTHROPIC_API_KEY with a key from the Claude Console. Usage is then billed to the API account, not your subscription, and Remote Control is unavailable while the key is set.

4. Start Claude Code in tmux. The -A flag attaches to the session if it already exists, so the same command works every time you connect:

sh
tmux new -A -s claude
cd /workspace/your-repo
claude

5. Detach and come back. Press Ctrl+B, then D. The tmux session and Claude Code keep running on the VM. Close your laptop, and reconnect from any machine that has the Beam CLI:

sh
beam vm ssh claude-box
tmux attach -t claude

If the Claude Code process itself has exited, claude --continue in the project directory reopens the last conversation from the history on disk.

For a single task you don't need tmux at all. beam vm prompt runs Claude Code headless on the VM as a background systemd unit and keeps a log you can follow:

sh
beam vm prompt claude-box "Explain how to run this project's tests" --agent claude --background
beam vm logs claude-box --session PROMPT_SESSION -f

The first command prints the prompt-... session ID that the second one takes. beam vm prompt doesn't pass a permission mode, so it suits read-only questions and work you've already approved with allow rules.

How to keep Claude Code running after you close your laptop

Claude Code keeps running when three things are true: the process isn't tied to your SSH connection, the machine stays on, and nothing puts the machine to sleep while the agent is working. tmux handles the first. A cloud VM handles the second. The third depends on the host's idle timer, and it's the one that catches people.

  • Leave the idle timeout off for long tasks. On a Beam VM, an idle timeout counts SSH sessions, tunnels and SDK calls as activity. A command running inside the VM doesn't count on its own. A VM with --ttl 300 would go to sleep five minutes after you detach, with Claude Code in the middle of a task. A Remote Control message from your phone can't wake it either, because Remote Control only makes outbound requests from the VM. New VMs have no timeout, so the default is already right for unattended work. When Claude has finished, pause the VM yourself.
  • Steer it from your phone with Remote Control. Inside the tmux session, start Claude Code with claude --remote-control. The session then shows up at claude.ai/code and in the Claude mobile app, where you can read progress and answer permission prompts. Remote Control needs a claude.ai subscription login from claude auth login or /login. It doesn't work with a setup-token token, and an ANTHROPIC_API_KEY set on the VM turns it off even when you're signed in. On Team and Enterprise plans, an Owner has to turn Remote Control on for the organization first.
  • Pause between working sessions. beam vm pause claude-box saves the VM's RAM and running processes along with the disk and releases compute. beam vm resume claude-box brings the tmux session back as you left it. Connections to outside services can close while a VM is paused, so a request that was in flight may need a retry.
  • Stop when you only need the files. beam vm stop claude-box keeps the root disk and discards RAM and processes. After beam vm start, attach tmux again and run claude --continue.

If you want the VM to sleep by itself when nobody is connected, beam vm update claude-box --ttl 300 --idle-action pause --auto-resume pauses it after five idle minutes and wakes it on the next SSH session. Use that only while you work over SSH yourself. For a task Claude runs while you're away, leave the timeout off and run beam vm pause claude-box when the work is done.

Permissions for unattended Claude Code on a server

An unattended agent stalls at its first permission prompt unless you've decided in advance what it may do. Claude Code gives you three levels: allow rules for specific tools, a permission mode such as acceptEdits or auto, and --dangerously-skip-permissions, which turns prompts off.

For most server work the first two are enough. In headless runs, claude -p "Run the test suite and fix any failures" --allowedTools "Bash,Read,Edit" approves those tools and nothing else, and --permission-mode acceptEdits lets Claude write files without asking. With Remote Control connected, you can also leave prompts on and approve them from your phone.

Skipping permissions has a catch on a VM. Claude Code refuses that mode when it runs as root, and beam vm ssh connects as root, so you create a regular user first. This guide stays with the interactive tmux and Remote Control workflow, so none of its commands turn prompts off. For fully unattended runs, our guide to running Claude Code in a sandbox has a section on running Claude Code unattended in an isolated VM. It covers the non-root user, an outbound allowlist and a way to keep the API key outside the agent's reach. The same approach works for other agents, including Codex.

What it costs to run Claude Code in the cloud

The cost has two parts: Claude usage and the machine. Cloud sessions fold the machine into your plan, with no separate VM charge, and count against the same usage limits as your other Claude Code work. On your own VM you pay for the VM on top of a subscription or API usage.

Beam VMSizeHours billedCompute cost
Shared tier, working hours4 vCPU, 8 GiB RAM160$14.08
Shared tier, always on4 vCPU, 8 GiB RAM720$63.36
Shared tier, always on2 vCPU, 4 GiB RAM720$31.68
Performance tier, working hours4 vCPU, 8 GiB RAM160$44.80

The inputs: Beam's Shared tier is $0.011 per vCPU-hour plus $0.0055 per GiB-hour, for VMs up to 8 vCPUs and 16 GiB. That makes a 4 vCPU, 8 GiB VM $0.088 an hour and a 2 vCPU, 4 GiB VM $0.044 an hour, billed per second while the VM runs. The Performance tier is $0.05 per vCPU-hour plus $0.01 per GiB-hour, or $0.28 an hour at 4 vCPUs and 8 GiB. New accounts default to Performance, so pass --cpu-tier shared as the examples do. The 160-hour rows assume 8 hours a day for 20 working days, and they assume you pause or stop the VM yourself at the end of each day, because no idle timeout is set. The 720-hour rows are 24 hours a day for 30 days.

A paused or stopped VM has no compute charge. Storage isn't billed yet. The planned rate is $0.0001 per GB-hour for retained VM disk and snapshots, including while the VM is stopped. The Developer plan is $20 a month and includes $20 of usage credits, and there are no egress fees. Current rates are on the pricing page.

A fixed-price VPS bills the same amount whether Claude Code is working or not. Our OpenClaw hosting guide lists monthly prices for 2 vCPU servers from several VPS providers next to the same Beam sizes.

Choosing between cloud sessions and your own VM

Use Anthropic's cloud sessions when the repository is on GitHub, the task fits in about 4 vCPUs and 16 GB of RAM, and what you want back is a branch or a pull request. There's nothing to set up or shut down, and several sessions can run in parallel.

Your own VM fits better when:

  • The build needs more than the session VM. Anthropic's docs say the session VM may stop tasks that need much more memory than its ceiling, and they point to your own hardware for those.
  • State should survive between sessions. Installed toolchains, a seeded database, Docker images and a half-finished debugging session all stay on a VM's disk. A reclaimed cloud session starts again from a fresh VM.
  • Services run next to the agent. A dev server, a database or a queue worker can stay up on the VM, and Claude Code can test against them.
  • You pay for Claude through an API key or a cloud provider. Cloud sessions use subscription credentials only.
  • Your code isn't on GitHub. Cloud sessions can take a GitLab or Bitbucket repository as an uploaded bundle, but they can't push results back to that remote.

On a Beam VM in particular you also get three things a plain VPS doesn't have. beam vm pause keeps memory, so a session resumes mid-task. beam vm fork claude-box attempt-b copies the root disk into a second VM, so two agents can try different approaches without touching each other's files. And beam vm expose claude-box 3000 --protected publishes a dev server at a stable URL that only loads after a Beam sign-in, which makes it easy to look at what Claude built.

Two limits apply. Beam VMs are CPU-only, so GPU work belongs on a sandbox or an endpoint that the VM calls. And the Spot tier can be interrupted with 30 seconds' notice and has to be restarted by hand, which rules it out for an agent you leave running overnight.

If you're hosting an agent you built yourself, not Claude Code, our guide to AI agent hosting walks through the same choice.

FAQ

Can Claude Code run in the cloud?

Yes. Anthropic's cloud sessions run Claude Code on an Anthropic-managed VM that you start from claude.ai/code, the Claude apps or claude --cloud. You can also install the Claude Code CLI on any cloud VM running Ubuntu or Debian and use it over SSH.

Does Claude Code keep running when I close my laptop?

A local session stops making progress while the laptop is asleep. A cloud session keeps running, and so does Claude Code on a cloud VM if you started it inside tmux or screen and the VM has no idle timeout.

Can I run Claude Code on a VPS?

Yes. Claude Code supports Ubuntu 20.04 or later and Debian 10 or later with at least 4 GB of RAM. Install it with curl -fsSL https://claude.ai/install.sh | bash, sign in, and start it in a tmux session so it survives an SSH disconnect.

How do I log in to Claude Code on a server with no browser?

Run claude, open the login URL it gives you in a browser on your own computer, and paste the code back into the terminal. You can also run claude setup-token on your laptop and set the result as CLAUDE_CODE_OAUTH_TOKEN on the server, or set ANTHROPIC_API_KEY.

Can I use my Claude subscription on a remote server?

Yes. Both the interactive login and a claude setup-token token use your subscription. The token works on Pro, Max, Ultra, Team and Enterprise plans and can make model requests only, so Remote Control needs the interactive login.

How much RAM does Claude Code need on a server?

Anthropic's system requirements list 4 GB or more. Your project usually needs more than Claude Code does, so size the VM for your build, tests and any services the agent will run.

How much does it cost to run Claude Code in the cloud?

Cloud sessions have no separate VM charge and count against your plan's usage limits. On your own VM you add the machine: a 4 vCPU, 8 GiB Beam VM on the Shared tier is $0.088 an hour, which is $14.08 for 160 hours or $63.36 for 720 hours.

Can I control Claude Code on a server from my phone?

Yes. Start it with claude --remote-control inside tmux, and the session appears at claude.ai/code and in the Claude mobile app. Remote Control needs a claude.ai subscription login, and it makes outbound requests only, so no port has to be opened on the server.

Give Claude Code a machine that stays on

A Beam VM gives Claude Code a persistent disk, SSH through an authenticated tunnel, the CLI already installed and a pause that keeps memory, billed per second while it runs. Create a Beam account and run the commands at the top of this page, or read more about Beam virtual machines.

Eli MernitPublished November 24, 2026

Pay as you go
billed by the second

Give your agents their own machines

Sign up, install the CLI, and launch a sandbox, VM, or GPU from your terminal or your coding agent.