Skip to content
Back to Tech
GenAI · 8 min read

From Terminal to Factory — Running Headless AI Agents 24/7

The step-by-step guide to transitioning from local Claude Code sessions to persistent, headless backend agents you control from your phone. Dispatch, remote control, agent teams, and event-driven automation.

From Terminal to Factory — Running Headless AI Agents 24/7

This is the most significant architectural shift in AI-assisted coding for 2026. We’re transitioning from a local tool — where you watch a terminal, babysit an agent, and close your laptop when you’re done — to a headless backend where agents live on a server and you dispatch tasks to them from anywhere.

The difference is fundamental: your AI coding assistant is no longer a tool you use. It’s a service you operate.

I’ve been running this setup for the past few months, and it’s transformed how I think about development capacity. Here’s the complete guide to building your own headless agent infrastructure using Claude Code’s Remote Control and Dispatch features.

The Architecture: Local Tool vs. Headless Backend

Before diving into the how, understand what changes:

DimensionLocal Tool (2025)Headless Backend (2026)
ExecutionRuns on your laptopRuns on a persistent cloud VM or server
InterfaceYou type in a terminal windowYou send commands via Dispatch (mobile/web)
PersistenceStops when you close the lidRuns 24/7 via Remote Control and /loop
OversightYou watch every line changeYou review diffs, artifacts, and logs asynchronously
ScaleOne agent, one taskMultiple agents, parallel tasks, coordinated via channels

This isn’t just a convenience upgrade. It’s a capacity multiplier. Instead of coding 8-10 hours a day with AI assistance, you have agents working around the clock — triaging issues, fixing tests, reviewing PRs, and building features while you sleep, fly, or live your life.

Step 1: Prepare the Headless Server

Instead of your laptop, you need a persistent environment — a VPS, a dedicated local server, or a Docker container — that stays awake 24/7. I use a Mac Studio in my home office, but any Linux VPS (Hetzner, DigitalOcean, AWS EC2) works fine.

Install Claude Code on the server:

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

Configure for headless mode by editing ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1",
    "CLAUDE_CODE_HEADLESS": "true"
  }
}

The HEADLESS flag tells Claude Code to run without expecting interactive terminal input. The AGENT_TEAMS flag enables multi-agent coordination via channels.

Important: Always run your headless sessions inside tmux or screen. This gives you a physical “attach” fallback — if a task gets stuck, you can SSH into the server, attach to the tmux session, and intervene directly. It’s your human-in-the-loop safety net.

tmux new-session -s agent-factory

Step 2: Set Up Remote Control (The Mobile Bridge)

Remote Control is the bridge between your phone (or any device) and the server-side agent. This is what makes the setup truly “headless” — you don’t need to be at a terminal to interact with your agents.

Initialize the bridge on your server:

claude remote-control

This displays a QR code in your terminal. Scan it with the Claude Mobile App on your phone.

The result: your phone is now a remote control for the server-side agent. You can close your laptop, leave your desk, go for a run — the agent process is still alive on the server, waiting for commands via the mobile interface.

You can:

  • See what the agent is currently working on
  • Send new instructions or corrections
  • Approve or reject proposed changes
  • Kill a runaway task

This is the “I’m reviewing code from the cockpit during cruise flight” moment that makes the whole setup worth it.

Step 3: Dispatch — Structured Task Management

Instead of typing into a chat and hoping for the best, Dispatch lets you send structured tasks that the agent picks up, executes, and reports back on.

Send a dispatch job:

claude dispatch "Refactor the auth service to use the new Redis cache"

Unlike standard chat, dispatch creates a tracked job ID. You can check status from your phone or another terminal without interrupting the agent’s current work. Each dispatch job has:

  • A unique ID for tracking
  • Status (queued, running, completed, failed)
  • Full execution log
  • Diff of all changes made
  • Ability to approve/reject the result

Batch dispatching is where it gets powerful. Queue up multiple tasks before bed:

claude dispatch "Add rate limiting to the /api/orders endpoint"
claude dispatch "Write integration tests for the validation engine"
claude dispatch "Update the Swagger docs for v2 API changes"

Each task executes sequentially (or in parallel with agent teams), and you review results in the morning.

Step 4: Agent Teams for Parallel Execution

For larger projects, don’t use one agent. Use a team. With Agent Teams enabled, you can spin up multiple specialized agents that coordinate via channels.

Define roles by restricting file access:

  • Backend Agent — access restricted to /src/backend, /src/api
  • Frontend Agent — access restricted to /src/frontend, /src/components
  • DevOps Agent — access to /infrastructure, /.github/workflows
  • Test Agent — access to /tests, read-only on source files

Use channels for inter-agent communication:

When the Backend Agent finishes a new API endpoint, it can notify the Frontend Agent via a channel to update the corresponding UI component. The DevOps Agent watches for infrastructure changes and updates deployment configs accordingly.

This mimics how a real engineering team works — specialized roles, clear boundaries, asynchronous communication. Except these team members work 24/7 and never need a standup.

Step 5: Event-Driven Automation (The Factory)

The final step transforms manual dispatching into an autonomous factory with event-driven triggers.

Cron-based health checks using the native /loop protocol:

# Inside a detached Claude Code session
/loop 2h "Check for any failing tests in the CI pipeline and attempt to fix them"

This runs every 2 hours, automatically detecting and fixing test failures. It’s your overnight QA engineer.

Webhook triggers from CI/CD:

Integrate with GitHub Actions so that when a PR is opened, your server-side Claude instance automatically:

  1. Pulls the latest code
  2. Reviews the PR for issues
  3. Runs the test suite
  4. Posts review comments
  5. Optionally auto-fixes and pushes corrections
# .github/workflows/agent-review.yml
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  agent-review:
    runs-on: self-hosted  # Your agent server
    steps:
      - uses: actions/checkout@v4
      - run: claude dispatch "Review this PR: ${{ github.event.pull_request.title }}"

Scheduled maintenance tasks:

/loop 24h "Run dependency audit, check for CVEs, and create a PR if updates are needed"
/loop 12h "Review open issues labeled 'bug' and attempt to reproduce and fix"

My Current Setup

Here’s what my agent factory looks like in practice:

  • Hardware: Mac Studio M2 Ultra (always on, in my home office)
  • Sessions: 3 tmux windows — backend agent, frontend agent, maintenance agent
  • Remote control: Paired with my iPhone via Claude Mobile App
  • Dispatch queue: I batch 5-10 tasks every evening before bed
  • Loop tasks: Test monitoring (2h), dependency audit (24h), stale PR cleanup (12h)
  • Morning routine: Review overnight diffs over coffee, approve/reject, dispatch new batch

The result is roughly 3x the development throughput I had with local-only Claude Code sessions. Not because the agents are faster — but because they never stop working.

Practical Considerations

Cost: Running agents 24/7 consumes significant API credits. I use the Claude Max subscription which makes this economically viable. Monitor your usage and set budget alerts.

Security: Your server has access to your codebase and API keys. Treat it like a production server — SSH keys only, firewall configured, secrets in environment variables, regular security updates.

Quality control: Never auto-merge agent output. Always review diffs before merging. The overnight factory produces code; you still make the judgment calls about what ships. The agents are tireless junior developers, not autonomous decision-makers.

Start small: Don’t try to set up the full factory on day one. Start with remote control + single dispatch jobs. Add agent teams when you’re comfortable. Add loop automation last, once you trust the quality of unattended output.

What’s Next

The headless agent paradigm is still early. I expect 2026-2027 to bring:

  • Native cloud hosting for Claude Code agents (no self-hosted server needed)
  • Visual dashboards for monitoring agent fleet status, costs, and output quality
  • Agent-to-agent protocols beyond channels — shared context, code ownership, merge coordination
  • Self-improving agents that learn from your review patterns and adjust their approach

The shift from “AI as a tool” to “AI as a service” is happening right now. The developers who figure out how to operate agent fleets — not just use AI assistants — will have a structural advantage that compounds over time.

claude-code headless dispatch remote-control agent-teams automation devops