DEV Community

Cover image for Your AI Coding Agent Deserves Its Own Cloud Machine
Timothy Olaleke
Timothy Olaleke

Posted on

Your AI Coding Agent Deserves Its Own Cloud Machine

I've been running Claude Code locally for months. It works, but my laptop fan sounds like a jet engine, my battery drains in two hours, and if I close the lid mid-session — gone.

Last week I moved my entire dev environment to a cloud VM. Claude Code runs there, my full stack runs there, and I SSH tunnel everything back to localhost. From my laptop it feels identical. From my phone, I can check on my AI coding agent while grabbing coffee.

Here's the exact setup. Every command is copy-pasteable. I verified each step end-to-end.

Step 0: Get Free Google Cloud Credits

If you don't have a GCP account yet, you get $300 in free credits for 90 days — no charge until you explicitly upgrade. That's more than enough to run this setup for months.

  1. Go to cloud.google.com/free
  2. Click Get started for free
  3. Sign in with your Google account, add a payment method (you won't be charged)
  4. You now have $300 in credits

Already have an account? Check your remaining credits at Billing → Overview in the console.

What this setup costs: about $0.13/hour for the VM. With the free tier, you can run it ~2,300 hours — roughly 3 months of 24/7 usage, or 6+ months during work hours only.

If you're a startup, apply for the Google for Startups Cloud Program — up to $200k in credits.

Why a Remote Dev Machine?

Three reasons pushed me off localhost:

  1. Battery and thermals — AI coding agents hammer your CPU. A cloud VM doesn't care.
  2. Session persistence — Close your laptop, hop on your phone, come back to your desk. The session is still running.
  3. Dev environment consistency — Docker, databases, everything runs 24/7 on the VM. No more "let me spin up Postgres first."

The tradeoff is latency. SSH tunneling adds a few milliseconds. I can't feel it.

The Architecture

┌─────────────┐     SSH Tunnel      ┌──────────────────────┐
│   Laptop    │ ──────────────────> │     Cloud VM          │
│  localhost  │  port forwarding    │  ├── Your App         │
└─────────────┘                     │  ├── API Server       │
                                    │  ├── PostgreSQL       │
┌─────────────┐     Happy (E2E)     │  ├── Redis            │
│   Phone     │ ──────────────────> │  └── Claude Code      │
│  Happy App  │  encrypted sync     │     (in tmux)         │
└─────────────┘                     └──────────────────────┘
Enter fullscreen mode Exit fullscreen mode

Your laptop and phone are thin clients. The VM does all the work.

Step 1: Create the VM

I'm using Google Cloud because my Claude Code runs on Vertex AI (covered that in my previous post). But this works with any cloud provider.

First, make sure you have the gcloud CLI installed. If not:

# macOS
brew install google-cloud-sdk

# Or download from https://cloud.google.com/sdk/docs/install
Enter fullscreen mode Exit fullscreen mode

Then authenticate and set your project:

gcloud auth login
gcloud config set project YOUR_PROJECT_ID
Enter fullscreen mode Exit fullscreen mode

Create the VM:

gcloud compute instances create my-dev-vm \
  --zone=us-central1-a \
  --machine-type=e2-standard-4 \
  --boot-disk-size=50GB \
  --boot-disk-type=pd-ssd \
  --image-family=ubuntu-2404-lts-amd64 \
  --image-project=ubuntu-os-cloud
Enter fullscreen mode Exit fullscreen mode

That's 4 vCPUs, 16GB RAM, 50GB SSD. Costs about $0.13/hour — covered by your free credits.

Step 2: Install Everything on the VM

SSH in:

gcloud compute ssh my-dev-vm --zone=us-central1-a
Enter fullscreen mode Exit fullscreen mode

Then run these on the VM:

# Docker
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
newgrp docker

# Node.js 22 + pnpm
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt-get install -y nodejs
sudo npm install -g pnpm@9

# Claude Code
sudo npm install -g @anthropic-ai/claude-code

# Happy (mobile access to Claude Code)
sudo npm install -g happy

# tmux (persistent sessions)
sudo apt-get install -y tmux
Enter fullscreen mode Exit fullscreen mode

Verify everything installed:

docker --version    # Docker 29+
node --version      # v22+
claude --version    # Claude Code 2.x
tmux -V             # tmux 3.x
Enter fullscreen mode Exit fullscreen mode

Step 3: Clone Your Project and Start Services

git clone https://github.com/your-org/your-project.git
cd your-project
docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Verify everything is running:

docker compose ps
Enter fullscreen mode Exit fullscreen mode

You should see your containers up with status (healthy):

NAME             STATUS              PORTS
my-app-api       Up 3 min (healthy)  0.0.0.0:3000->3000/tcp
my-app-web       Up 3 min (healthy)  0.0.0.0:3100->3100/tcp
my-app-postgres  Up 5 min (healthy)  0.0.0.0:5432->5432/tcp
my-app-redis     Up 5 min (healthy)  0.0.0.0:6379->6379/tcp
Enter fullscreen mode Exit fullscreen mode

Your full stack is running on the VM. Your laptop isn't doing anything yet.

Step 4: SSH Tunnel to Localhost

This is the key part. From your local machine (not the VM), forward the ports you need:

gcloud compute ssh my-dev-vm --zone=us-central1-a -- \
  -L 3100:localhost:3100 \
  -L 3000:localhost:3000 \
  -N
Enter fullscreen mode Exit fullscreen mode

What this does:

  • -L 3100:localhost:3100 — requests to localhost:3100 on your laptop go to port 3100 on the VM
  • -N — don't open a shell, just forward ports

Now open your browser:

  • http://localhost:3100 — your web app
  • http://localhost:3000 — your API

It's localhost. Your browser doesn't know the difference. Hot reload works. DevTools work.

Save it as an alias (add to ~/.zshrc or ~/.bashrc on your local machine):

alias dev-tunnel='gcloud compute ssh my-dev-vm --zone=us-central1-a -- \
  -L 3100:localhost:3100 -L 3000:localhost:3000 -N'
Enter fullscreen mode Exit fullscreen mode

Step 5: Run Claude Code in tmux

SSH back into the VM and start Claude Code in a tmux session so it survives disconnects:

gcloud compute ssh my-dev-vm --zone=us-central1-a
Enter fullscreen mode Exit fullscreen mode

On the VM:

tmux new -s claude
cd ~/your-project
claude
Enter fullscreen mode Exit fullscreen mode

If you're using Vertex AI (GCP credits for Claude), add these to ~/.bashrc on the VM first:

export CLAUDE_CODE_USE_VERTEX=1
export ANTHROPIC_VERTEX_PROJECT_ID=YOUR_PROJECT_ID
export CLOUD_ML_REGION=global
export ANTHROPIC_MODEL=claude-opus-4-6
Enter fullscreen mode Exit fullscreen mode

Then source ~/.bashrc before running claude.

Claude Code now has your full project right there — files, Docker services, databases, everything. No latency.

tmux basics:

  • Ctrl+b d — detach (session keeps running in the background)
  • tmux attach -t claude — reattach from any SSH session
  • Close your laptop, come back tomorrow — session is exactly where you left it

Step 6: Code from Your Phone with Happy

This changed my workflow. Happy is an open-source mobile client for Claude Code. End-to-end encrypted.

On the VM, in a new tmux session:

tmux new -s happy
happy claude -- --dangerously-skip-permissions
Enter fullscreen mode Exit fullscreen mode

The --dangerously-skip-permissions flag runs Claude Code in "yolo mode" — no permission prompts. Remove it if you want the default safety checks.

Happy shows a QR code. Scan it with the Happy app:

That's it. You control Claude Code from your phone. When you get back to your desk, press any key on your keyboard and control switches back.

I use this constantly. Standing in line? Check if tests passed. On a call? Glance at what Claude is building.

My Daily Workflow

Morning:

dev-tunnel  # alias from Step 4
Enter fullscreen mode Exit fullscreen mode

Open localhost:3100. Everything is already running from yesterday. No cold start.

During the day:
Claude Code runs in tmux on the VM. Attach when I need it, detach when I don't. Laptop stays cool.

Away from desk:
Happy app on my phone. "Run the test suite." "Show me the API logs."

End of day:
Close the laptop. VM keeps running. Tomorrow: dev-tunnel and I'm back in 2 seconds.

Cost

Resource Spec Monthly
VM (e2-standard-4) 4 vCPU, 16GB RAM ~$97 (or ~$39 spot)
Disk (50GB SSD) pd-ssd ~$8.50
Network SSH tunnel overhead ~$1-2
Total ~$107 (or ~$49 spot)

All covered by the $300 free credits for about 3 months.

Auto-stop to save money:

gcloud compute resource-policies create vm-maintenance workday-schedule \
  --start-schedule="0 8 * * 1-5" \
  --stop-schedule="0 20 * * 1-5" \
  --timezone=UTC
Enter fullscreen mode Exit fullscreen mode

Tips

Use autossh for reliable tunnels — SSH tunnels drop. autossh reconnects:

# Install: brew install autossh (macOS) or apt install autossh (Linux)
autossh -M 0 -f -N \
  -o "ServerAliveInterval 30" \
  -o "ServerAliveCountMax 3" \
  -L 3100:localhost:3100 \
  -L 3000:localhost:3000 \
  my-dev-vm
Enter fullscreen mode Exit fullscreen mode

VS Code Remote SSH — connect your IDE directly to the VM:

Cmd+Shift+P → "Remote-SSH: Connect to Host" → my-dev-vm
Enter fullscreen mode Exit fullscreen mode

Multiple projects on one VM:

cd ~/project-a && docker compose -p project-a up -d  # ports 3000-3100
cd ~/project-b && docker compose -p project-b up -d  # ports 4000-4100
Enter fullscreen mode Exit fullscreen mode

Quick Reference

What Command
Get free credits cloud.google.com/free
Create VM gcloud compute instances create my-dev-vm --machine-type=e2-standard-4 --boot-disk-size=50GB ...
SSH in gcloud compute ssh my-dev-vm
Start stack docker compose up -d
Tunnel ports gcloud compute ssh my-dev-vm -- -L 3100:localhost:3100 -L 3000:localhost:3000 -N
Claude Code tmux new -s claude then claude
Mobile access happy claude → scan QR
Stop VM gcloud compute instances stop my-dev-vm
Start VM gcloud compute instances start my-dev-vm

Your laptop should be a thin client. Let the cloud do the heavy lifting.


Part 2 of my Claude Code on Google Cloud series. Part 1: Run Claude Code on Google Cloud

Top comments (0)