Heartbeat
Heartbeat runs periodic agent turns in the main session so the model can surface anything that needs attention without spamming you.
Heartbeat is a scheduled main-session turn — it does not create background task records. Task records are for detached work (ACP runs, subagents, isolated cron jobs).
Troubleshooting: Scheduled Tasks
Quick start (beginner)
Section titled “Quick start (beginner)”Pick a cadence
Leave heartbeats enabled (default is
30m, or1hfor Anthropic OAuth/token auth, including Claude CLI reuse) or set your own cadence.Add HEARTBEAT.md (optional)
Create a tiny
HEARTBEAT.mdchecklist ortasks:block in the agent workspace.Decide where heartbeat messages should go
target: "none"is the default; settarget: "last"to route to the last contact.Optional tuning
- Enable heartbeat reasoning delivery for transparency.
- Use lightweight bootstrap context if heartbeat runs only need
HEARTBEAT.md. - Enable isolated sessions to avoid sending full conversation history each heartbeat.
- Restrict heartbeats to active hours (local time).
Example config:
{ agents: { defaults: { heartbeat: { every: "30m", target: "last", // explicit delivery to last contact (default is "none") directPolicy: "allow", // default: allow direct/DM targets; set "block" to suppress lightContext: true, // optional: only inject HEARTBEAT.md from bootstrap files isolatedSession: true, // optional: fresh session each run (no conversation history) skipWhenBusy: true, // optional: also defer when this agent's subagent or nested lanes are busy // activeHours: { start: "08:00", end: "24:00" }, // includeReasoning: true, // optional: send separate `Thinking` message too }, }, },}Defaults
Section titled “Defaults”- Interval:
30m(or1hwhen Anthropic OAuth/token auth is the detected auth mode, including Claude CLI reuse). Setagents.defaults.heartbeat.everyor per-agentagents.list[].heartbeat.every; use0mto disable. - Prompt body (configurable via
agents.defaults.heartbeat.prompt):Read HEARTBEAT.md if it exists (workspace context). Follow it strictly. Do not infer or repeat old tasks from prior chats. If nothing needs attention, reply HEARTBEAT_OK. - The heartbeat prompt is sent verbatim as the user message. The system prompt includes a “Heartbeat” section only when heartbeats are enabled for the default agent, and the run is flagged internally.
- When heartbeats are disabled with
0m, normal runs also omitHEARTBEAT.mdfrom bootstrap context so the model does not see heartbeat-only instructions. - Active hours (
heartbeat.activeHours) are checked in the configured timezone. Outside the window, heartbeats are skipped until the next tick inside the window. - Heartbeats automatically defer while cron work is active or queued. Set
heartbeat.skipWhenBusy: trueto also defer an agent on its own session-keyed subagent or nested command lanes; sibling agents no longer pause just because another agent has subagent work in flight.
What the heartbeat prompt is for
Section titled “What the heartbeat prompt is for”The default prompt is intentionally broad:
- Background tasks: “Consider outstanding tasks” nudges the agent to review follow-ups (inbox, calendar, reminders, queued work) and surface anything urgent.
- Human check-in: “Checkup sometimes on your human during day time” nudges an occasional lightweight “anything you need?” message, but avoids night-time spam by using your configured local timezone (see Timezone).
Heartbeat can react to completed background tasks, but a heartbeat run itself does not create a task record.
If you want a heartbeat to do something very specific (e.g. “check Gmail PubSub stats” or “verify gateway health”), set agents.defaults.heartbeat.prompt (or agents.list[].heartbeat.prompt) to a custom body (sent verbatim).
Response contract
Section titled “Response contract”- If nothing needs attention, reply with
HEARTBEAT_OK. - Tool-capable heartbeat runs may instead call
heartbeat_respondwithnotify: falsefor no visible update, ornotify: trueplusnotificationTextfor an alert. When present, the structured tool response takes precedence over the text fallback. - During heartbeat runs, OpenClaw treats
HEARTBEAT_OKas an ack when it appears at the start or end of the reply. The token is stripped and the reply is dropped if the remaining content is ≤ackMaxChars(default: 300). - If
HEARTBEAT_OKappears in the middle of a reply, it is not treated specially. - For alerts, do not include
HEARTBEAT_OK; return only the alert text.
Outside heartbeats, stray HEARTBEAT_OK at the start/end of a message is stripped and logged; a message that is only HEARTBEAT_OK is dropped.
Config
Section titled “Config”{ agents: { defaults: { heartbeat: { every: "30m", // default: 30m (0m disables) model: "anthropic/claude-opus-4-6", includeReasoning: false, // default: false (deliver separate Thinking message when available) lightContext: false, // default: false; true keeps only HEARTBEAT.md from workspace bootstrap files isolatedSession: false, // default: false; true runs each heartbeat in a fresh session (no conversation history) skipWhenBusy: false, // default: false; true also waits for this agent's subagent/nested lanes target: "last", // default: none | options: last | none | <channel id> (core or plugin, e.g. "imessage") to: "+15551234567", // optional channel-specific override accountId: "ops-bot", // optional multi-account channel id prompt: "Read HEARTBEAT.md if it exists (workspace context). Follow it strictly. Do not infer or repeat old tasks from prior chats. If nothing needs attention, reply HEARTBEAT_OK.", ackMaxChars: 300, // max chars allowed after HEARTBEAT_OK }, }, },}Scope and precedence
Section titled “Scope and precedence”agents.defaults.heartbeatsets global heartbeat behavior.agents.list[].heartbeatmerges on top; if any agent has aheartbeatblock, only those agents run heartbeats.channels.defaults.heartbeatsets visibility defaults for all channels.channels.<channel>.heartbeatoverrides channel defaults.channels.<channel>.accounts.<id>.heartbeat(multi-account channels) overrides per-channel settings.
Per-agent heartbeats
Section titled “Per-agent heartbeats”If any agents.list[] entry includes a heartbeat block, only those agents run heartbeats. The per-agent block merges on top of agents.defaults.heartbeat (so you can set shared defaults once and override per agent).
Example: two agents, only the second agent runs heartbeats.
{ agents: { defaults: { heartbeat: { every: "30m", target: "last", // explicit delivery to last contact (default is "none") }, }, list: [ { id: "main", default: true }, { id: "ops", heartbeat: { every: "1h", target: "whatsapp", to: "+15551234567", timeoutSeconds: 45, prompt: "Read HEARTBEAT.md if it exists (workspace context). Follow it strictly. Do not infer or repeat old tasks from prior chats. If nothing needs attention, reply HEARTBEAT_OK.", }, }, ], },}Active hours example
Section titled “Active hours example”Restrict heartbeats to business hours in a specific timezone:
{ agents: { defaults: { heartbeat: { every: "30m", target: "last", // explicit delivery to last contact (default is "none") activeHours: { start: "09:00", end: "22:00", timezone: "America/New_York", // optional; uses your userTimezone if set, otherwise host tz }, }, }, },}Outside this window (before 9am or after 10pm Eastern), heartbeats are skipped. The next scheduled tick inside the window will run normally.
24/7 setup
Section titled “24/7 setup”If you want heartbeats to run all day, use one of these patterns:
- Omit
activeHoursentirely (no time-window restriction; this is the default behavior). - Set a full-day window:
activeHours: { start: "00:00", end: "24:00" }.
Multi-account example
Section titled “Multi-account example”Use accountId to target a specific account on multi-account channels like Telegram:
{ agents: { list: [ { id: "ops", heartbeat: { every: "1h", target: "telegram", to: "12345678:topic:42", // optional: route to a specific topic/thread accountId: "ops-bot", }, }, ], }, channels: { telegram: { accounts: { "ops-bot": { botToken: "YOUR_TELEGRAM_BOT_TOKEN" }, }, }, },}Field notes
Section titled “Field notes”main(default): agent main session.- Explicit session key (copy from
openclaw sessions --jsonor the sessions CLI). - Session key formats: see Sessions and Groups.
- Omitted or
"user": uses youragents.defaults.userTimezoneif set, otherwise falls back to the host system timezone. "local": always uses the host system timezone.- Any IANA identifier (e.g.
America/New_York): used directly; if invalid, falls back to the"user"behavior above. startandendmust not be equal for an active window; equal values are treated as zero-width (always outside the window).- Outside the active window, heartbeats are skipped until the next tick inside the window.
Delivery behavior
Section titled “Delivery behavior”Session and target routing
- Heartbeats run in the agent’s main session by default (`agent:
:
), or globalwhensession.scope = “global”. Set sessionto override to a specific channel session (Discord/WhatsApp/etc.). -sessiononly affects the run context; delivery is controlled bytargetandto. - To deliver to a specific channel/recipient, set target+to. With target: “last”, delivery uses the last external channel for that session. - Heartbeat deliveries allow direct/DM targets by default. Set directPolicy: “block”to suppress direct-target sends while still running the heartbeat turn. - If the main queue, target session lane, cron lane, or an active cron job is busy, the heartbeat is skipped and retried later. - IfskipWhenBusy: true, this agent's session-keyed subagent and nested lanes also defer heartbeat runs. Other agents' busy lanes do not defer this agent. - If target` resolves to no external destination, the run still happens but no outbound message is sent.
Visibility and skip behavior
- If
showOk,showAlerts, anduseIndicatorare all disabled, the run is skipped up front asreason=alerts-disabled. - If only alert delivery is disabled, OpenClaw can still run the heartbeat, update due-task timestamps, restore the session idle timestamp, and suppress the outward alert payload.
- If the resolved heartbeat target supports typing, OpenClaw shows typing while the heartbeat run is active. This uses the same target the heartbeat would send chat output to, and it is disabled by
typingMode: "never".
Session lifecycle and audit
- Heartbeat-only replies do not keep the session alive. Heartbeat metadata may update the session row, but idle expiry uses
lastInteractionAtfrom the last real user/channel message, and daily expiry usessessionStartedAt. - Control UI and WebChat history hide heartbeat prompts and OK-only acknowledgments. The underlying session transcript can still contain those turns for audit/replay.
- Detached background tasks can enqueue a system event and wake heartbeat when the main session should notice something quickly. That wake does not make the heartbeat run a background task.
Visibility controls
Section titled “Visibility controls”By default, HEARTBEAT_OK acknowledgments are suppressed while alert content is delivered. You can adjust this per channel or per account:
channels: defaults: heartbeat: showOk: false # Hide HEARTBEAT_OK (default) showAlerts: true # Show alert messages (default) useIndicator: true # Emit indicator events (default) telegram: heartbeat: showOk: true # Show OK acknowledgments on Telegram whatsapp: accounts: work: heartbeat: showAlerts: false # Suppress alert delivery for this accountPrecedence: per-account → per-channel → channel defaults → built-in defaults.
What each flag does
Section titled “What each flag does”showOk: sends aHEARTBEAT_OKacknowledgment when the model returns an OK-only reply.showAlerts: sends the alert content when the model returns a non-OK reply.useIndicator: emits indicator events for UI status surfaces.
If all three are false, OpenClaw skips the heartbeat run entirely (no model call).
Per-channel vs per-account examples
Section titled “Per-channel vs per-account examples”channels: defaults: heartbeat: showOk: false showAlerts: true useIndicator: true slack: heartbeat: showOk: true # all Slack accounts accounts: ops: heartbeat: showAlerts: false # suppress alerts for the ops account only telegram: heartbeat: showOk: trueCommon patterns
Section titled “Common patterns”| Goal | Config |
|---|---|
| Default behavior (silent OKs, alerts on) | (no config needed) |
| Fully silent (no messages, no indicator) | channels.defaults.heartbeat: { showOk: false, showAlerts: false, useIndicator: false } |
| Indicator-only (no messages) | channels.defaults.heartbeat: { showOk: false, showAlerts: false, useIndicator: true } |
| OKs in one channel only | channels.telegram.heartbeat: { showOk: true } |
HEARTBEAT.md (optional)
Section titled “HEARTBEAT.md (optional)”If a HEARTBEAT.md file exists in the workspace, the default prompt tells the agent to read it. Think of it as your “heartbeat checklist”: small, stable, and safe to consider every 30 minutes.
On normal runs, HEARTBEAT.md is only injected when heartbeat guidance is enabled for the default agent. Disabling the heartbeat cadence with 0m or setting includeSystemPromptSection: false omits it from normal bootstrap context.
On the native Codex harness, HEARTBEAT.md content is not injected into the turn. If the file exists and has non-whitespace content, the heartbeat collaboration-mode instructions point Codex at the file and tell it to read before proceeding.
If HEARTBEAT.md exists but is effectively empty (only blank lines and markdown headers like # Heading), OpenClaw skips the heartbeat run to save API calls. That skip is reported as reason=empty-heartbeat-file. If the file is missing, the heartbeat still runs and the model decides what to do.
Keep it tiny (short checklist or reminders) to avoid prompt bloat.
Example HEARTBEAT.md:
# Heartbeat checklist
- Quick scan: anything urgent in inboxes?- If it's daytime, do a lightweight check-in if nothing else is pending.- If a task is blocked, write down _what is missing_ and ask Peter next time.tasks: blocks
Section titled “tasks: blocks”HEARTBEAT.md also supports a small structured tasks: block for interval-based checks inside heartbeat itself.
Example:
tasks:
- name: inbox-triage interval: 30m prompt: "Check for urgent unread emails and flag anything time sensitive."- name: calendar-scan interval: 2h prompt: "Check for upcoming meetings that need prep or follow-up."
# Additional instructions
- Keep alerts short.- If nothing needs attention after all due tasks, reply HEARTBEAT_OK.Behavior
- OpenClaw parses the
tasks:block and checks each task against its owninterval. - Only due tasks are included in the heartbeat prompt for that tick.
- If no tasks are due, the heartbeat is skipped entirely (
reason=no-tasks-due) to avoid a wasted model call. - Non-task content in
HEARTBEAT.mdis preserved and appended as additional context after the due-task list. - Task last-run timestamps are stored in session state (
heartbeatTaskState), so intervals survive normal restarts. - Task timestamps are only advanced after a heartbeat run completes its normal reply path. Skipped
empty-heartbeat-file/no-tasks-dueruns do not mark tasks as completed.
Task mode is useful when you want one heartbeat file to hold several periodic checks without paying for all of them every tick.
Can the agent update HEARTBEAT.md?
Section titled “Can the agent update HEARTBEAT.md?”Yes — if you ask it to.
HEARTBEAT.md is just a normal file in the agent workspace, so you can tell the agent (in a normal chat) something like:
- “Update
HEARTBEAT.mdto add a daily calendar check.” - “Rewrite
HEARTBEAT.mdso it’s shorter and focused on inbox follow-ups.”
If you want this to happen proactively, you can also include an explicit line in your heartbeat prompt like: “If the checklist becomes stale, update HEARTBEAT.md with a better one.”
Manual wake (on-demand)
Section titled “Manual wake (on-demand)”You can enqueue a system event and trigger an immediate heartbeat with:
openclaw system event --text "Check for urgent follow-ups" --mode nowIf multiple agents have heartbeat configured, a manual wake runs each of those agent heartbeats immediately.
Use --mode next-heartbeat to wait for the next scheduled tick.
Reasoning delivery (optional)
Section titled “Reasoning delivery (optional)”By default, heartbeats deliver only the final “answer” payload.
If you want transparency, enable:
agents.defaults.heartbeat.includeReasoning: true
When enabled, heartbeats will also deliver a separate message prefixed Thinking (same shape as /reasoning on). This can be useful when the agent is managing multiple sessions/codexes and you want to see why it decided to ping you — but it can also leak more internal detail than you want. Prefer keeping it off in group chats.
Cost awareness
Section titled “Cost awareness”Heartbeats run full agent turns. Shorter intervals burn more tokens. To reduce cost:
- Use
isolatedSession: trueto avoid sending full conversation history (~100K tokens down to ~2-5K per run). - Use
lightContext: trueto limit bootstrap files to justHEARTBEAT.md. - Set a cheaper
model(e.g.ollama/llama3.2:1b). - Keep
HEARTBEAT.mdsmall. - Use
target: "none"if you only want internal state updates.
Context overflow after heartbeat
Section titled “Context overflow after heartbeat”If a heartbeat previously left an existing session on a smaller local model, for example an Ollama model with a 32k window, and the next main-session turn reports context overflow, reset the session runtime model back to the configured primary model. OpenClaw’s reset message calls this out when the last runtime model matches configured heartbeat.model.
Current heartbeats preserve the shared session’s existing runtime model after the run completes. You can still use isolatedSession: true to run heartbeats in a fresh session, combine it with lightContext: true for the smallest prompt, or choose a heartbeat model with a context window large enough for the shared session.
Related
Section titled “Related”- Automation — all automation mechanisms at a glance
- Background Tasks — how detached work is tracked
- Timezone — how timezone affects heartbeat scheduling
- Troubleshooting — debugging automation issues