Scheduled Tasks (Cron)
Cron is the Gateway’s built-in scheduler. It persists jobs, wakes the agent at the right time, and can deliver output back to a chat channel or webhook endpoint.Quick start
How cron works
- Cron runs inside the Gateway process (not inside the model).
- Jobs persist at
~/.openclaw/cron/jobs.jsonso restarts do not lose schedules. - All cron executions create background task records.
- One-shot jobs (
--at) auto-delete after success by default.
Schedule types
| Kind | CLI flag | Description |
|---|---|---|
at | --at | One-shot timestamp (ISO 8601 or relative like 20m) |
every | --every | Fixed interval |
cron | --cron | 5-field or 6-field cron expression with optional --tz |
--tz America/New_York for local wall-clock scheduling.
Recurring top-of-hour expressions are automatically staggered by up to 5 minutes to reduce load spikes. Use --exact to force precise timing or --stagger 30s for an explicit window.
Execution styles
| Style | --session value | Runs in | Best for |
|---|---|---|---|
| Main session | main | Next heartbeat turn | Reminders, system events |
| Isolated | isolated | Dedicated cron:<jobId> | Reports, background chores |
| Current session | current | Bound at creation time | Context-aware recurring work |
| Custom session | session:custom-id | Persistent named session | Workflows that build on history |
--wake now or --wake next-heartbeat). Isolated jobs run a dedicated agent turn with a fresh session. Custom sessions (session:xxx) persist context across runs, enabling workflows like daily standups that build on previous summaries.
Payload options for isolated jobs
--message: prompt text (required for isolated)--model/--thinking: model and thinking level overrides--light-context: skip workspace bootstrap file injection--tools exec,read: restrict which tools the job can use
Delivery and output
| Mode | What happens |
|---|---|
announce | Deliver summary to target channel (default for isolated) |
webhook | POST finished event payload to a URL |
none | Internal only, no delivery |
--announce --channel telegram --to "-1001234567890" for channel delivery. For Telegram forum topics, use -1001234567890:topic:123. Slack/Discord/Mattermost targets should use explicit prefixes (channel:<id>, user:<id>).
CLI examples
One-shot reminder (main session):Webhooks
Gateway can expose HTTP webhook endpoints for external triggers. Enable in config:Authentication
Every request must include the hook token via header:Authorization: Bearer <token>(recommended)x-openclaw-token: <token>
POST /hooks/wake
Enqueue a system event for the main session:text(required): event descriptionmode(optional):now(default) ornext-heartbeat
POST /hooks/agent
Run an isolated agent turn:message (required), name, agentId, wakeMode, deliver, channel, to, model, thinking, timeoutSeconds.
Mapped hooks (POST /hooks/<name>)
Custom hook names are resolved viahooks.mappings in config. Mappings can transform arbitrary payloads into wake or agent actions with templates or code transforms.
Security
- Keep hook endpoints behind loopback, tailnet, or trusted reverse proxy.
- Use a dedicated hook token; do not reuse gateway auth tokens.
- Set
hooks.allowedAgentIdsto limit explicitagentIdrouting. - Keep
hooks.allowRequestSessionKey=falseunless you require caller-selected sessions. - Hook payloads are wrapped with safety boundaries by default.
Gmail PubSub integration
Wire Gmail inbox triggers to OpenClaw via Google PubSub. Prerequisites:gcloud CLI, gog (gogcli), OpenClaw hooks enabled, Tailscale for the public HTTPS endpoint.
Wizard setup (recommended)
hooks.gmail config, enables the Gmail preset, and uses Tailscale Funnel for the push endpoint.
Gateway auto-start
Whenhooks.enabled=true and hooks.gmail.account is set, the Gateway starts gog gmail watch serve on boot and auto-renews the watch. Set OPENCLAW_SKIP_GMAIL_WATCHER=1 to opt out.
Manual one-time setup
- Select the GCP project that owns the OAuth client used by
gog:
- Create topic and grant Gmail push access:
- Start the watch:
Gmail model override
Managing jobs
Configuration
cron.enabled: false or OPENCLAW_SKIP_CRON=1.
One-shot retry: transient errors (rate limit, overload, network, server error) retry up to 3 times with exponential backoff. Permanent errors disable immediately.
Recurring retry: exponential backoff (30s to 60m) between retries. Backoff resets after the next successful run.
Maintenance: cron.sessionRetention (default 24h) prunes isolated run-session entries. cron.runLog.maxBytes / cron.runLog.keepLines auto-prune run-log files.
Troubleshooting
Command ladder
Cron not firing
- Check
cron.enabledandOPENCLAW_SKIP_CRONenv var. - Confirm the Gateway is running continuously.
- For
cronschedules, verify timezone (--tz) vs the host timezone. reason: not-duein run output means manual run called without--force.
Cron fired but no delivery
- Delivery mode is
nonemeans no external message is expected. - Delivery target missing/invalid (
channel/to) means outbound was skipped. - Channel auth errors (
unauthorized,Forbidden) mean delivery was blocked by credentials.
Timezone gotchas
- Cron without
--tzuses the gateway host timezone. atschedules without timezone are treated as UTC.- Heartbeat
activeHoursuses configured timezone resolution.
Related
- Automation & Tasks — all automation mechanisms at a glance
- Background Tasks — task ledger for cron executions
- Heartbeat — periodic main-session turns
- Timezone — timezone configuration