Claude Code on a VPS: Deploy and Run on Remote Servers
Run Claude Code on a VPS with SSH, Docker, and headless mode. Setup guide with real commands, monitoring, and security hardening.
Agentic Orchestration Kit for Claude Code.
Problem: You can build apps with Claude Code locally, but running it on a remote server feels like uncharted territory. Maybe you want Claude Code available 24/7 for long-running tasks. Maybe you need it accessible from multiple machines without syncing environments. Or maybe you just want to keep resource-heavy AI work off your laptop.
Running Claude Code on a VPS is straightforward once you know the moving parts: SSH access, Node.js, authentication, and optionally Docker for isolation. This guide walks through the entire process with real commands you can run on a fresh Ubuntu server.
Prerequisites and VPS Selection
Claude Code needs more resources than a typical Node.js app. The AI model runs remotely on Anthropic's servers, but the local process still handles context management, file operations, and tool execution.
Minimum VPS specs:
- 2 vCPUs (4 recommended for multi-agent workloads)
- 4 GB RAM (8 GB recommended)
- 40 GB SSD storage
- Ubuntu 22.04 or 24.04 LTS
Providers that work well: Any major VPS provider handles this fine. AWS Lightsail, DigitalOcean, Hetzner, and Linode all offer plans in the $10-20/month range that meet these specs. Hetzner gives the best price-to-performance ratio for European developers. Lightsail is the simplest if you're already in the AWS ecosystem.
What you'll need before starting:
- An Anthropic API key (from console.anthropic.com) or a Pro/Max subscription
- SSH access to your server
- A domain name (optional, for Remote Control access)
SSH Setup and Secure Access
Start with a fresh Ubuntu server. Most providers give you root access via password. Your first job is making it secure.
Set up a basic firewall before installing anything else:
From this point forward, always connect as your non-root user: ssh deploy@your-server-ip.
Installing Claude Code on a Headless Server
Claude Code requires Node.js 18+. Install it with the NodeSource repository for the latest LTS version:
Authentication: On a headless server without a browser, you'll need to authenticate using an API key. For background on how Claude Code manages credentials and permissions, see the permission management guide.
If you have a Pro or Max subscription and want to use OAuth instead, run claude once, copy the auth URL it provides, open it in a browser on any device, and paste the code back into the terminal.
Running Claude Code in Non-Interactive Mode
On a server, you'll typically run Claude Code in headless mode rather than interactive chat. If you're new to the CLI, the installation guide covers the basics. This is where it gets useful for automation.
Single command execution:
The -p flag (print mode) runs Claude Code non-interactively. It processes the prompt, outputs the result, and exits. No chat interface, no waiting for input.
Combining with SSH for remote management: This is where a VPS-hosted Claude Code becomes powerful. From your local machine:
You can also use Remote Control to connect to a running interactive session from your phone or another device, which is useful for monitoring long-running agent tasks.
Docker Deployment Workflow
Docker adds isolation and reproducibility. If something goes wrong, you tear down the container and start fresh. No cleaning up a polluted server environment.
Create a docker-compose.yml for your Claude Code workspace:
Start the workspace and use it:
The tail -f /dev/null command keeps the container running so you can exec into it repeatedly. The claude-cache volume persists Claude's authentication and session data between container restarts.
For project-specific containers, create separate compose files per project. Each gets its own isolated environment with only the files it needs mounted.
Monitoring and Log Management
Long-running Claude Code sessions on a VPS need monitoring. You don't want a process to crash silently at 3 AM.
Use tmux or screen for persistent sessions that survive SSH disconnects:
Systemd service for always-on Claude Code workers:
Common Errors and Real Fixes
"EACCES: permission denied, mkdir '/usr/lib/node_modules'"
You installed Node.js as root but npm needs write access for global installs. Fix with:
"Error: Unable to open browser for authentication"
Expected on headless servers. Use the API key method described above, or copy the auth URL to a device with a browser.
Claude Code process killed by OOM (Out of Memory)
Your VPS doesn't have enough RAM. Multi-agent sessions that spawn many sub-agents consume memory per agent. Solutions:
SSH connection drops during long Claude Code sessions
Configure SSH keep-alive on your local machine:
Or use tmux (described above) so the session persists regardless of your SSH connection.
Security Considerations
Running an AI coding agent on a server with real credentials requires extra caution.
Never store API keys in committed files. Use environment variables or a secrets manager:
Restrict Claude Code's file access when running automated tasks. The --sandbox flag limits filesystem and network access:
Set up Fail2ban to block brute-force SSH attempts:
Keep your server updated:
For a complete VPS security hardening setup with UFW firewall templates, Fail2ban rules, and SSH key-only authentication pre-configured, the ClaudeFast Code Kit includes an InfraOps skill that gives Claude a full DevOps reference. Instead of Googling nginx configs or Docker commands, you ask Claude and it pulls from a curated operations handbook.
What's Next
A VPS-hosted Claude Code opens up workflows that aren't possible locally: 24/7 availability, scheduled tasks that run while you sleep, and multi-agent sessions that don't drain your laptop battery. Pair it with git worktrees for isolated branch work, or use Remote Control to manage sessions from your phone.
Start simple. Get Claude Code running on a basic VPS with SSH access. Add Docker once you need isolation. Add systemd services once you need automation. Scale up from there.
Last updated on
