Scheduling

A headless agent needs to be started by something. That something is a scheduler (time-based) or a trigger (event-based). Picking the right one is architecture.

Time-based scheduling

Cron (traditional)

Old reliable. A crontab entry on a server that runs your agent script at specified intervals.

# Every weekday at 9am: generate daily report
0 9 * * 1-5 /usr/local/bin/claude-daily-report.sh

Pros: simple, free, everywhere. Cons: single-node; no retry on failure; hard to monitor.

Claude Code's /loop and /schedule

Built-in skills for recurring work. /loop 5m /my-skill runs a skill every 5 minutes; /schedule sets up remote triggers.

Cloud scheduler

Google Cloud Scheduler, AWS EventBridge, Cloudflare Cron. Managed. Better monitoring and retry than cron.

Event-based triggers

Webhooks

Service X emits an event (new email, new issue, new customer); your endpoint catches it and triggers an agent.

Polling-to-event

If the service doesn't emit webhooks, poll it on a schedule, detect changes, fire the agent only on new data.

Message queues

For high-volume or multi-tenant agent work: Redis streams, SQS, RabbitMQ. Agent workers consume from the queue.

Choosing the right cadence

Designing for scheduled runs

Overlap handling

What if run N is still going when run N+1 is scheduled? Three options:

Observability

Scheduled agents are background agents. You don't see them. You need instruments.