GuidesClaude Code
Back

How to run Claude Code on a VPS

Install Claude Code on a remote Linux server, keep it alive with a persistent terminal, secure access, and reconnect after your laptop closes.

Matrix OS5 min read

To run Claude Code on a VPS, provision a Linux server, create a non-root user, install your development toolchain and Claude Code, authenticate through Claude’s supported login flow, clone the repository, and run the agent inside tmux or another persistent terminal. The VPS now provides the uptime, so your laptop can disconnect or sleep.

What size VPS do you need?

Claude Code itself is not the only workload. Budget for the repository, package manager, language server, tests, database, builds, and preview server.

WorkloadStarting pointWatch for
One agent, small project2 vCPU, 4 GB RAMLarge dependency installs
Agent plus dev server and database4 vCPU, 8 GB RAMBrowser tests and builds
Multiple agents8+ vCPU, 16+ GB RAMConcurrent tests and disk use

These are starting points, not guarantees. Measure CPU, memory, disk, and build time against your own repository.

1. How should you secure the VPS user?

Use your provider’s console to create an Ubuntu or Debian-style VPS. Connect using the provider’s documented SSH process, update the system, create a developer user, and use SSH keys rather than a reusable password. Keep the application, database, and agent ports behind the firewall unless you intentionally proxy them through an authenticated TLS endpoint.

Do not run an autonomous coding agent as root. A mistaken command should not automatically become a machine-wide change.

2. How do you install Claude Code on the VPS?

Install Git, your language runtime, build tools, and Claude Code using Anthropic’s current official instructions. Commands change, so verify the install method against the official documentation on publication day.

Launch claude interactively and complete its supported account authentication. Do not copy browser cookies, laptop private keys, or undocumented credential files to the server.

3. How should the VPS access GitHub?

The GitHub CLI provides a supported browser/device flow:

gh auth login --hostname github.com --web
mkdir -p ~/projects
cd ~/projects
git clone git@github.com:owner/repo.git

If you use SSH, generate a new key on the VPS and register only its public key. Give the server access only to repositories it needs.

4. How do you keep Claude Code running after SSH disconnects?

Install and start tmux:

tmux new -s claude
cd ~/projects/repo
claude

Detach with Ctrl-b, then d. Later, reconnect and attach:

ssh developer@your-server
tmux attach -t claude

tmux protects the terminal session from an SSH disconnect. It does not survive a stopped VPS or reboot by itself. It also cannot save a process killed by low memory, a full disk, expired credentials, or a crash.

A common mistake is to start claude directly after SSH login, close the laptop, and assume the server will keep it alive. The server is still running, but the foreground process may receive a hangup when SSH disappears. Start tmux first.

5. What should an unattended VPS session be allowed to do?

Use a dedicated branch, restrict the task, require tests, and stop before deployment or destructive operations. Keep production credentials off the development VPS. Add spending alerts with the model provider and infrastructure provider, and inspect disk usage before large builds.

When is a managed workspace easier than a raw VPS?

A raw VPS gives maximum control, but you own SSH hardening, TLS, session tooling, backups, updates, browser access, routing, and recovery. Matrix Cloud provisions a dedicated remote computer with persistent terminals, files, browser access, and agent workflows around it. Matrix can also be self-hosted on your own VPS.

If you want the persistent machine without operating every layer, follow the Matrix quickstart. For the full tradeoff, see Matrix OS versus a raw VPS.

Common questions about running Claude Code on a VPS

Will Claude Code keep running after SSH disconnects?

Only if it is running inside a persistent session such as tmux, screen, or a durable platform terminal. A foreground process tied directly to a dropped SSH connection can terminate.

Does a VPS make unattended Claude Code safe?

No. It improves uptime, not judgment. Use least privilege, isolated branches, no production secrets, bounded tasks, logs, tests, and human review.

Is a cheap VPS enough?

It may be enough for one agent on a small repository. Builds, test suites, browser automation, databases, and parallel agents determine the real requirement.