Course Lessons
Welcome & Orientation Starter
Welcome to AI Like a Pro

Quick Reference
⚡ Cheat Sheet 📐 Prompt Formula 📋 CLAUDE.md Guide
← Back to Course Home
Lesson 33 of 37  —  Module 6: Advanced Claude Code 89%
Module 6: Advanced Claude Code  Advanced

Hosting and Monitoring AI Agents

Learn the practical approaches to hosting Claude Code agents so they run reliably without requiring your laptop, and how to monitor what your agents are actually doing in real time.

The Laptop Problem

The easiest way to run a Claude Code agent is also the most fragile: your laptop. Close the lid, lose the session. Turn off Wi-Fi, lose the connection. Walk away for a weekend, the agent stops.

For automation tasks that need to run on a schedule or respond to events, this is not acceptable. You need the agent running somewhere persistent -- and you need visibility into what it is doing.

This lesson covers the practical options for hosting Claude Code agents and the tools for monitoring them effectively.


Hosting Option 1: A Dedicated Local Machine

The simplest upgrade from a laptop is a dedicated machine that stays on: a spare PC, a Raspberry Pi, or a Mac Mini.

Why this works:
- No cloud costs
- Your existing Claude Code configuration and MCP setup carries over
- Full control -- you own the hardware and the data

Setup:
1. Install Claude Code on the machine
2. Configure your CLAUDE.md, skills, and MCP servers
3. Use tmux to keep sessions alive after SSH disconnects: tmux new-session -s agent
4. Start Claude Code inside the tmux session
5. Detach: Ctrl+B then D
6. The agent keeps running even after you close the SSH connection

Access: SSH from any device. On Windows, VS Code Remote SSH extension gives you the full IDE experience on the remote machine.

Limitation: You are still dependent on your home network and hardware reliability.


Hosting Option 2: Cloud VM

A cloud virtual machine (AWS EC2, Google Cloud Compute, DigitalOcean Droplet, or Hetzner) gives you a persistent environment with better reliability than home hardware.

Recommended minimal spec:
- 2 vCPU, 4GB RAM
- Ubuntu 22.04 LTS
- 20GB storage

Monthly cost: roughly $5-20 depending on provider and region.

Setup is identical to local: install Claude Code, configure your settings, use tmux for session persistence.

One additional step: set up UFW firewall rules to block all inbound traffic except SSH (port 22). Your agent does not need to be reachable from the internet -- it only makes outbound calls.


Hosting Option 3: GitHub Actions or Cloud Run

For agents triggered by specific events (a new file in Drive, a new row in a sheet, a webhook from an external service), serverless execution makes more sense than a persistent VM.

GitHub Actions approach:
- Define a workflow YAML that triggers on your event
- The workflow spins up a container, runs your Claude Code script, and terminates
- No idle cost -- you only pay for actual execution time

Cloud Run approach (Google):
- Package your agent script as a container
- Deploy to Cloud Run with the trigger configured
- Scales to zero when idle

This approach works best for batch jobs rather than ongoing monitoring. For a nightly report that runs at 2am, serverless is ideal. For a loop checking your inbox every 10 minutes, a persistent VM is simpler.


The Monitoring Gap

Running an agent without monitoring is like deploying code without logs. You know it started. You do not know if it succeeded, where it got stuck, or whether the output was correct.

Claude Code provides several ways to watch agents in real time.


Monitoring Tool 1: tmux Split Panes

When running multiple agents with the TeamCreate feature (covered in Lesson 15), tmux gives you a split-pane view where each agent gets its own panel. You can literally watch them think and act simultaneously.

In the terminal:

tmux split-window -h   # split horizontally
tmux split-window -v   # split vertically

Each pane runs an independent shell. You can attach to individual agents, send them messages, and observe their output without interrupting the others.


Monitoring Tool 2: Status Line

Claude Code shows agent activity in the VS Code status bar. When AutoDream runs, it shows "dreaming." When the loop command creates a cron job, the next scheduled run appears in status. When a sub-agent is active, the task appears.

For lightweight monitoring from the editor, the status line is sufficient.


Monitoring Tool 3: Log Files

For persistent agents on a server, structured logging is the most reliable monitoring approach. Add logging to your execution scripts:

import logging
from datetime import datetime

logging.basicConfig(
    filename=f"logs/agent_{datetime.now().strftime('%Y%m%d')}.log",
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(message)s"
)

Ship logs to a centralized service (Papertrail, Logtail, or even a simple Google Sheet) for a searchable history of everything the agent did.


Monitoring Tool 4: Agent Status Reports

For long-running agents, configure them to write a status file at regular intervals:

Every 30 minutes, write a brief status to .tmp/agent_status.md:
- What I just completed
- What I am currently working on
- Any errors or blockers encountered
- Next scheduled action

You can read this file via SSH or have it synced to Notion or a Google Doc for easy review from any device.


Handling Agent Failures

Agents fail. APIs rate-limit. Files are not where expected. External services return errors.

Build recovery into your agent configuration:

  1. Retry logic -- configure your scripts to retry failed API calls with exponential backoff
  2. Error notifications -- send a Slack message or email when an agent encounters a critical error
  3. Safe defaults -- when uncertain, do nothing and log the situation rather than guessing
  4. Checkpoint files -- write progress to a checkpoint file so a restarted agent can resume rather than starting over

The goal is not to prevent all failures -- it is to ensure failures are visible and recoverable.


Keeping Costs Under Control

Running Claude Code continuously on a cloud VM costs money -- both the VM bill and the API usage.

Cost management practices:
- Use Haiku for routine monitoring tasks (status checks, simple summaries)
- Reserve Sonnet for tasks requiring judgment
- Use Opus only for planning and complex decisions
- Set daily spending limits in your Anthropic account settings
- Log token usage per task to identify expensive operations

A well-optimized agent running routine tasks primarily uses Haiku, keeping daily costs to a few dollars rather than tens.


Watch the Originals

  • Easiest Way to Host Claude Code Agents -- youtube.com/watch?v=OUyfxhFtGCo -- 21 min
  • I Can Actually Watch My Agents -- youtube.com/watch?v=vFepZE_wrfg -- 12 min

Next lesson: Claude Code for n8n Users

HivePowered AI — AI Like a Pro Training