Building a Gateway Daemon for Claude Code Multi-Agent Scheduling

Fazm Team··2 min read

Building a Gateway Daemon for Claude Code Multi-Agent Scheduling

Running multiple Claude Code agents manually works for a few hours. But when you want agents running overnight, on a schedule, or kicking off in response to events, you need a gateway daemon. The architecture is simpler than it sounds: tmux sessions with individual agents, launchd for scheduling, and a thin coordination layer.

The Architecture

Each agent runs in its own tmux session. This gives you isolation - one agent crashing does not take down the others - and visibility, since you can attach to any session to see what an agent is doing.

Launchd handles scheduling. A plist file tells macOS when to spin up agent sessions: nightly builds at 2 AM, test suite runs after each commit, documentation updates every Monday. Launchd is more reliable than cron on macOS because it handles missed executions when the machine was asleep.

The Coordination Layer

The gateway daemon is a lightweight script that sits between launchd triggers and agent sessions. It checks if an agent slot is available, reads the task queue, assigns work, and monitors output for completion signals.

The task queue is a simple directory of markdown files. Each file describes a task with acceptance criteria. The daemon picks the next file, creates a tmux session, starts Claude Code with the task as a prompt, and watches the session for the completion marker.

Knowing When to Intervene

This is the hardest part. An agent might be stuck in a loop, making the wrong architectural decision, or successfully completing something you did not actually want. The daemon needs heuristics for flagging sessions that need human attention.

Simple signals work well: no git commits in 15 minutes, repeated error messages, or the agent asking questions to stdin. The daemon can send you a notification when these thresholds are hit, and you attach to the tmux session to course-correct.

Start Simple

Do not over-engineer the daemon. Start with a bash script that manages two tmux sessions and a launchd plist for one scheduled task. Add complexity only when you hit a real limitation.

More on This Topic

Fazm is an open source macOS AI agent. Open source on GitHub.

Related Posts