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:

  1. Choose Ubuntu 22.04 or 24.04 LTS as your operating system (I went with 24.04)
  2. Select at least 4GB RAM for optimal performance (I started with 1GB and upgraded to 2GB, which seems to work fine)
  3. Enable SSH key authentication during creation (See: How to set up SSH keys on DigitalOcean and your Mac)
  4. 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-ip

Update the system packages:

apt update && apt upgrade -y

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 - yourname

Step 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 --version

Step 4: Install Claude Code

You have two installation methods:

curl -fsSL https://claude.ai/install.sh | bash

Method 2: NPM Installation

npm install -g @anthropic-ai/claude-code

Verify the installation:

claude --version

Step 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 ~/.bashrc

Option B: Claude Pro/Max Authentication

If you have a Claude Pro or Max subscription:

claude login

Follow 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
claude

File 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 claude

2. Configure Firewall

Secure your droplet with UFW:

sudo ufw allow OpenSSH
sudo ufw enable

3. Monitor Usage

Keep an eye on your API usage if using API billing:

# Check Claude Code configuration
claude config

Cost 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:

  1. Consistent Environment: Same setup accessible from any device
  2. Always Available: No need to install on multiple machines
  3. Better Performance: Dedicated resources for your AI assistant
  4. Team Collaboration: Share the environment with team members
  5. 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 sudo for 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-code

Happy coding with your cloud-powered AI assistant!