Setting up Claude Code on a remote server gives you a powerful AI coding assistant accessible from anywhere. This guide walks through installing Claude Code on a DigitalOcean droplet, providing you with a cloud-based development environment powered by AI.
Prerequisites
Before starting, you’ll need:
- A DigitalOcean account
- An Anthropic account with either API access or Claude Pro/Max subscription
- Basic familiarity with SSH and terminal commands
Step 1: Create Your Droplet
First, create a new droplet in DigitalOcean:
- Choose Ubuntu 22.04 or 24.04 LTS as your operating system (I went with 24.04)
- Select at least 4GB RAM for optimal performance (I started with 1GB and upgraded to 2GB, which seems to work fine)
- Enable SSH key authentication during creation (See: How to set up SSH keys on DigitalOcean and your Mac)
- Choose your preferred datacenter location (Usually the one closest to you is fine)
Once created, note your droplet’s IP address.
Step 2: Initial Server Setup
SSH into your new droplet:
ssh root@your-droplet-ipUpdate the system packages:
apt update && apt upgrade -yCreate a Non-Root User (Recommended)
For security, create a dedicated user instead of using root (replace “yourname” with a username you want to use):
# Create new user
adduser yourname
# Grant sudo privileges
usermod -aG sudo yourname
# Copy SSH keys to new user
rsync --archive --chown=yourname:yourname ~/.ssh /home/yourname
# Switch to new user
su - yournameStep 3: Install Node.js
Claude Code requires Node.js 18 or higher. Install it using NodeSource’s repository:
# Download and run NodeSource setup script
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
# Install Node.js
sudo apt-get install -y nodejs
# Verify installation
node --version
npm --versionStep 4: Install Claude Code
You have two installation methods:
Method 1: Native Installer (Recommended)
curl -fsSL https://claude.ai/install.sh | bashMethod 2: NPM Installation
npm install -g @anthropic-ai/claude-codeVerify the installation:
claude --versionStep 5: Configure Authentication
Claude Code needs to connect to your Anthropic account. You have two options:
Option A: API Key Authentication
If you have API access through console.anthropic.com:
# Set your API key as an environment variable
export ANTHROPIC_API_KEY="sk-ant-..."
# Make it permanent
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc
source ~/.bashrcOption B: Claude Pro/Max Authentication
If you have a Claude Pro or Max subscription:
claude loginFollow the prompts to authenticate through your browser.
Step 6: Test Your Installation
Create a test project to verify everything works:
# Create a test directory
mkdir ~/test-project
cd ~/test-project
# Start Claude Code
claude
# Test with a simple command
/ask "Create a simple Python hello world script"If Claude responds and creates the file, your installation is successful!
Working with Projects
Since you’re on a headless server, you’ll interact with Claude Code entirely through SSH. Here are some tips:
Clone Your Projects
# Clone existing projects
git clone https://github.com/yourusername/your-project.git
cd your-project
claudeFile Management
Remember that files you create are stored on the droplet. To download them:
# Use SCP from your local machine
scp yourname@your-droplet-ip:~/project/file.py ./
# Or use rsync for directories
rsync -av yourname@your-droplet-ip:~/project/ ./local-project/Optimization Tips
1. Set Up Persistent Sessions
Use tmux or screen to keep Claude Code running even if your SSH connection drops:
# Install tmux
sudo apt install tmux -y
# Start a new session
tmux new -s claude
# Start Claude Code
claude
# Detach with Ctrl+B then D
# Reattach later with:
tmux attach -t claude2. Configure Firewall
Secure your droplet with UFW:
sudo ufw allow OpenSSH
sudo ufw enable3. Monitor Usage
Keep an eye on your API usage if using API billing:
# Check Claude Code configuration
claude configCost Considerations
- DigitalOcean Droplet: ~$24/month (4GB RAM droplet)
- Claude Access:
- API: Pay per token used
- Claude Pro: $20/month
- Claude Max: $100/month
For regular development work, a Claude Pro subscription often provides better value than pay-per-use API access.
Advantages of Cloud-Based Claude Code
Running Claude Code on a droplet offers several benefits:
- Consistent Environment: Same setup accessible from any device
- Always Available: No need to install on multiple machines
- Better Performance: Dedicated resources for your AI assistant
- Team Collaboration: Share the environment with team members
- Integration Ready: Easy to connect with other cloud services
Troubleshooting
If you encounter issues:
- Command not found: Check your PATH with
echo $PATH - Permission denied: Ensure you’re using
sudofor system operations - Connection issues: Verify your API key or authentication status
- Out of memory: Consider upgrading to a larger droplet
Conclusion
You now have Claude Code running on your DigitalOcean droplet, providing a powerful cloud-based AI coding assistant. This setup gives you the flexibility to code from anywhere while maintaining a consistent development environment.
Remember to regularly update both your system and Claude Code to get the latest features and security patches:
# Update system
sudo apt update && sudo apt upgrade
# Claude Code updates automatically, or manually:
npm update -g @anthropic-ai/claude-codeHappy coding with your cloud-powered AI assistant!
