📑 Table of contents

Cron + AI: Automating Smart Tasks 24/7

Cron + AI: Automating Smart Tasks 24/7

Automatisation 🟡 Intermediate ⏱️ 13 min read 📅 2026-02-24

🔄 Classic Cron vs AI Cron: two philosophies

Traditional cron: reliable but blind

Unix cron has been around since the 1970s. Its principle is simple: execute a command at a specific time, based on a time expression (the famous * * * * * syntax).

For example, it is commonly used to schedule daily backups at 3 AM or disk space checks every hour via dedicated shell scripts.

The problem? This script executes no matter what. Even if the backup is useless (no modifications), even if the disk space is perfect. It doesn't know how to adapt its behavior to the context.

AI cron: contextual and intelligent

With an AI agent, the paradigm changes completely. The agent receives an instruction, but it reasons before acting:

  • It checks if the action is necessary
  • It adapts its response to the context
  • It can escalate (alert) or ignore depending on severity
  • It produces readable summaries for the human
Criterion Classic Cron AI Cron (OpenClaw)
Execution Blind, always Contextual, intelligent
Response Return code (0/1) Natural language analysis
Adaptation None Adjusts according to context
Escalation Manual if/else script Autonomous decision
Cost Almost zero LLM tokens (optimizable)
Maintenance Scripts to maintain Natural language prompts
Monitoring Raw logs Intelligent summaries
Multi-tasking 1 cron = 1 script 1 heartbeat = N checks

🧠 OpenClaw's two mechanisms: Heartbeat and Cron

OpenClaw offers two complementary mechanisms for time-based automation. Understanding their differences is essential for properly architecting your automations.

The Heartbeat: your agent's pulse

The heartbeat is a periodic agent turn in the main session. By default, it triggers every 30 minutes. The agent "wakes up", checks its checklist (HEARTBEAT.md), and decides what to do.

Configuration is done in OpenClaw's settings, where you define the interval (for example "30m"), the delivery target, and the active hours (like from 08:00 to 22:00).

Heartbeat strengths:

  • Batch multiple checks: a single agent turn can check email, calendar, notifications, and the status of a project
  • Contextual: the agent has access to the entire history of the main session
  • Economical: a single API call instead of 5 separate cron jobs
  • Intelligent suppression: if nothing requires attention, the agent responds HEARTBEAT_OK and no message is delivered

The HEARTBEAT.md file serves as the checklist at the core of this mechanism: it contains instructions such as scanning for urgent emails, checking the calendar for the next 2 hours, summarizing the results of completed background tasks, checking the status of monitored services, or doing a light check-in in case of prolonged inactivity.

The OpenClaw Cron: precision and isolation

The OpenClaw cron is a scheduler integrated into the Gateway. It persists jobs, wakes the agent at the right time, and can optionally deliver the result to a chat.

Two execution modes:

  1. Main session (main): injects a system event processed at the next heartbeat
  2. Isolated session (isolated): launches a dedicated agent turn in cron:<jobId>, without polluting the main history

To create a recurring isolated job with delivery on Telegram, we use the openclaw cron add command by specifying the name, the cron expression, the timezone, the isolated session mode, the task prompt, and the destination channel.

Decision matrix: Heartbeat or Cron?

Use case Recommended Why
Check emails every 30 min Heartbeat Combines with other checks
Daily report at exactly 9 AM Cron (isolated) Exact timing necessary
Calendar monitoring Heartbeat Suited for periodic checks
In-depth weekly analysis Cron (isolated) Autonomous task, can use a different model
Reminder in 20 minutes Cron (main, --at) One-shot with precise timing
Temporary file cleanup Heartbeat Piggybacks on the existing cycle
Nighttime content generation Cron (isolated) Isolation + dedicated model

🛠️ Setting up your first AI Cron Jobs

Prerequisites

Before you start, make sure you have:

  • OpenClaw installed and the Gateway running
  • An LLM provider configured (Claude, GPT, or via OpenRouter)
  • A communication channel configured (Telegram, WhatsApp, Discord...)

Job 1: One-shot reminder

The simplest. You want a reminder in 20 minutes. The openclaw cron add command with the --at "20m" flag allows you to schedule a system event in the main session. The agent receives the reminder and, since it runs in the main session, it has all the context of your recent conversations to prepare the summary. The --delete-after-run flag ensures the job does not persist.

Job 2: Recurring morning briefing

Every morning at 7:30 AM, a comprehensive report is generated and sent to Telegram via an isolated cron. We configure the cron expression, the Europe/Paris timezone, and a prompt requesting the generation of a morning briefing (weather, emails, calendar, tech news).

Why isolated? This job doesn't need the context of the main session. It performs an autonomous task and delivers the result directly.

Why --model opus? For a high-quality briefing, we can use a more powerful model. Isolated jobs allow you to choose the model independently of the main session.

Job 3: Intelligent monitoring

A job configured every 15 minutes checks the status of services by querying a configuration file (like /root/services.json). If a service is down, the agent analyzes recent logs and provides a diagnosis. If everything is OK, it responds HEARTBEAT_OK. Unlike a classic monitoring script, it analyzes the logs in case of a problem and provides a natural language diagnosis.

Job 4: Weekly review with high thinking

Every Monday at 9 AM, an isolated cron launches an in-depth analysis of the week with the Opus model. The --thinking high flag activates the model's extended reasoning, ideal for complex analyses that require reflection (project progress, key metrics, blockers, recommendations).


📋 Concrete automation examples

Intelligent website monitoring

Instead of a simple ping, the AI agent can:

  1. Check response time
  2. Compare with history
  3. Detect trends (gradual degradation)
  4. Analyze page content (visual errors, missing content)
  5. Suggest corrective actions

An isolated cron every 30 minutes is enough to check a website: response time, HTTP code, content, and comparison with previous checks. The agent only alerts if an anomaly is detected.

Scheduled content generation

Every night at 2 AM, the agent consults the database of pending articles. For the next article in draft status, it writes the complete content following the brief, then updates the status to need_review_human. The Opus model is recommended here for writing quality.

To go further on this topic, check out our guide Generate content automatically with AI.

Intelligent backups

Instead of blindly backing up every night, an isolated cron at 3 AM checks the files modified since the last backup. If significant changes exist, it launches the incremental backup, verifies the backup's integrity, cleans up backups older than 30 days, and summarizes the actions taken. The agent decides if a backup is necessary, verifies its integrity, and manages rotation — all in a single prompt.

Automated competitive intelligence

An isolated cron configured on Mondays and Thursdays at 10 AM performs competitive monitoring: it visits the sites of competitors listed in a JSON file, detects price changes, new features, blog articles, and summarizes the important points using the Opus model.


⚡ Combining Heartbeat and Cron: the optimal configuration

The most efficient configuration uses both mechanisms together:

Heartbeat (every 30 min)
├── Scan urgent emails
├── Calendar check (2h)
├── Status of current tasks
└── Light check-in if inactive

Isolated Cron (precise timings)
├── 07:30 → Morning briefing (Opus)
├── 02:00 → Nighttime content generation
├── */15  → Services monitoring
├── Monday 09:00 → Weekly review (Opus + thinking high)
└── One-shots → Reminders and deadlines

Complete configuration

Configuration is done in OpenClaw's settings. We define the default heartbeat with a 30-minute interval, a delivery target (like Telegram), and active hours (for example from 07:00 to 23:00, Europe/Paris timezone). We also enable the cron module with a maximum number of concurrent runs set to 1.

The associated HEARTBEAT.md remains concise to limit costs: scan for urgent emails with an alert if critical, check the calendar for the next 2 hours, track the progress of current tasks, and respond HEARTBEAT_OK if nothing is urgent.


💰 Cost optimization

AI cron jobs consume tokens. Here is how to optimize:

Strategy Estimated savings How
Batching via heartbeat ~70% 1 heartbeat instead of 5 cron jobs
HEARTBEAT_OK suppression ~30% No delivery if nothing to report
Model adapted per job ~50% Flash for monitoring, Opus for analysis
Active hours ~30-50% No heartbeat at night
target: "none" ~10% Internal processing only
Short prompts ~20% Fewer input tokens

Example of an economical configuration

For frequent monitoring (every 15 minutes), we use an economical model like Flash with an ultra-short prompt ("Ping services. OK or alert."). For in-depth weekly analysis (every Monday at 9 AM), we prefer the Opus model with high thinking, the lower frequency offsetting the higher cost of the model.


🔧 Management and debugging

Essential CLI commands

OpenClaw provides several commands to manage your cron jobs: openclaw cron list to list all jobs, openclaw cron runs --id <jobId> --limit 50 to view the execution history, openclaw cron run <jobId> to force immediate execution, openclaw cron edit <jobId> to modify an existing job (prompt, activation, etc.), and openclaw cron remove <jobId> to delete a job.

Retry and error handling

OpenClaw automatically handles errors with exponential backoff:

  • 1st error → retry after 30 seconds
  • 2nd error → retry after 1 minute
  • 3rd error → retry after 5 minutes
  • 4th error → retry after 15 minutes
  • 5th error+ → retry after 60 minutes

The backoff automatically resets after a successful run.

Automatic staggering

For recurring jobs scheduled at the start of the hour (like 0 * * * *), OpenClaw applies a deterministic offset of 0 to 5 minutes to avoid load spikes. You can control this behavior with the --exact flag to force exact timing (no stagger) or --stagger 30s to set a custom offset.


🔒 Best practices and security

  1. Do not put secrets in prompts: cron job messages are stored in plain text in ~/.openclaw/cron/jobs.json. Reference configuration files instead.

  2. Use isolated sessions for sensitive tasks: they do not share the main session's history.

  3. Limit active hours: no need for a heartbeat at 3 AM if you are sleeping (except for critical monitoring in an isolated cron).

  4. Keep HEARTBEAT.md short: this file is included in the prompt at every heartbeat. The longer it is, the more it costs.

  5. Monitor your costs: regularly check openclaw cron runs to identify jobs that consume too much.

  6. To send an immediate system event without creating a persistent job, use the openclaw system event command with the --mode now option.


❌ Common mistakes

  • Leaving secrets in prompts: this is the most frequent mistake. Cron prompts are stored in plain text. Always use environment variables or external config files.
  • Using only cron jobs for everything: heartbeat is more economical for grouped regular checks. Do not create 5 cron jobs when one heartbeat is enough.
  • Neglecting active hours: a heartbeat running 24/7 for no reason multiplies costs by two or three depending on the inactive period.
  • Choosing the wrong session mode: a job that does not need main context should be in isolated, otherwise it pollutes the history and consumes more tokens.
  • Forgetting the --delete-after-run flag on one-shots: one-off reminders accumulate in the job list and complicate management.

🎯 The essentials

  • OpenClaw's AI cron replaces blind execution with contextual reasoning: the agent decides if an action is necessary before acting.
  • Two complementary mechanisms exist: heartbeat (grouped and periodic checks) and cron (precise timings and isolated tasks).
  • Isolated sessions allow choosing a different model per job and prevent polluting the main history.
  • Cost optimization relies on batching (heartbeat), short prompts, active hours, and the appropriate choice of model (Flash for monitoring, Opus for analysis).
  • Start simple: a heartbeat with a few checks and one or two cron jobs, then expand gradually.

❓ FAQ

What is the difference between a heartbeat and a cron?
The heartbeat is a periodic agent turn in the main session, ideal for grouping several lightweight checks. The cron is a scheduler that triggers jobs at precise timings, in the main or isolated session.

Can we use a different model for each cron job?
Yes, with isolated sessions. Each isolated job can specify its own model via the --model flag, independently of the main session.

What happens if the AI agent does not respond?
OpenClaw applies an automatic exponential backoff: 30s, 1min, 5min, 15min, then 60min between each retry. The backoff resets after a successful run.

Does the heartbeat run 24/7?
No, you can limit active hours via the activeHours parameter in the configuration. For nighttime monitoring, we use an isolated cron instead.

How much does an AI cron cost compared to a traditional cron?
A traditional cron is almost free. An AI cron consumes LLM tokens, but optimization strategies (batching, HEARTBEAT_OK, adapted model) can reduce the bill by 50 to 70% depending on the case.


  • OpenClaw: orchestration platform to configure your AI cron jobs, heartbeats, and autonomous agents.
  • Telegram / Discord / WhatsApp: recommended delivery channels to receive alerts and reports from your cron jobs.
  • Claude (Opus) / GPT: recommended LLM models for complex analysis tasks and content generation.
  • OpenRouter: model aggregator allowing you to easily switch between economical (Flash) and premium (Opus) models depending on the job.

🎯 Conclusion

Moving from traditional cron to AI cron represents a paradigm shift in automation. Where traditional cron mechanically executes scripts, OpenClaw's AI cron reasons, contextualizes, and adapts.

By combining the heartbeat (for regular and grouped checks) with isolated cron jobs (for precise and autonomous tasks), you get a complete automation system that runs 24/7 with minimal human intervention.

The key is to start simple — a heartbeat with a few checks and one or two cron jobs — then gradually expand based on your actual needs. The advantage of natural language prompts is that you can iterate quickly without rewriting scripts.