Skip to content
Rezha Julio

openclaw

Reducing OpenClaw Heartbeat Token Usage

4 min read

Running an AI agent 24/7 sounds cool until you see the token bill. Here's how to cut your heartbeat costs.

Running an AI agent 24/7 sounds cool until you see the token bill. One of the biggest culprits? Heartbeats, those periodic check-ins that keep your agent aware.

Here’s how I cut mine down.

What are heartbeats?

In OpenClaw (formerly Clawdbot), heartbeats are periodic polls that wake your agent to check for pending tasks. The default behavior:

  1. Agent receives a heartbeat prompt
  2. Agent reads HEARTBEAT.md and workspace context
  3. Agent either takes action or replies HEARTBEAT_OK

Every heartbeat consumes tokens for:

  • The system prompt and agent identity
  • Reading HEARTBEAT.md and referenced files
  • Any actions taken or responses generated

At the default 30-minute interval, that’s 48 heartbeats per day. The tokens add up fast.

Strategy 1: Slim down HEARTBEAT.md

Your HEARTBEAT.md gets read on every single heartbeat. Keep it minimal.

Before (token-heavy):

# Heartbeat Checklist
## Routine Checks
1. Daily Log: Check if memory/YYYY-MM-DD.md exists...
2. Inbox Check: Check urgent emails or notifications...
3. Moltbook Check: Read skills/moltbook/HEARTBEAT.md for full routine...
4. Log Rotation: Check date header in memory/moltbook_activity.md...
5. Self-Correction: If IDENTITY.md or SOUL.md is missing...
## Pending Tasks
- [ ] Retry Moltbook Post (Security)...
- [ ] Retry Moltbook Post (Sandboxing)...

After (lean):

# Heartbeat
- Ensure `memory/YYYY-MM-DD.md` exists
- Check DMs if due (see heartbeat-state.json)

Move pending tasks to cron jobs instead of tracking them in HEARTBEAT.md. Cron jobs run in isolated sessions and don’t bloat your main context.

Strategy 2: Increase the interval

Edit your ~/.openclaw/openclaw.json (or %USERPROFILE%\.openclaw\openclaw.json on Windows) and add heartbeat configuration:

{
"agents": {
"defaults": {
"heartbeat": {
"every": "60m"
}
}
}
}

The every field accepts duration strings (ms, s, m, h); default unit is minutes. Going from 30 to 60 minutes cuts your heartbeat tokens in half. Hourly check-ins are fine for most agents.

Warning

Don’t go higher than your actual responsiveness needs. A 4-hour interval means up to 4 hours of latency on inbound signals. If you’re using heartbeats to catch DMs or webhook events, this is the wrong lever.

Strategy 3: Use a cheaper model

Heartbeats are usually simple “check and respond” operations. They don’t need your most powerful model.

{
"agents": {
"defaults": {
"heartbeat": {
"model": "qwen-portal/coder-model"
}
}
}
}

A lighter model means:

  • Faster responses
  • Lower token costs (if using paid APIs like OpenAI/Anthropic)
  • Less compute for simple yes/no decisions

Note: This saves on generation costs. The input context (files, memory) is still loaded, so keeping HEARTBEAT.md small (Strategy 1) is still crucial.

Strategy 4: Replace heartbeats with cron jobs

Heartbeats are convenient but inefficient for scheduled tasks. Compare:

FeatureHeartbeatCron Job
SessionMain (carries context)Isolated (clean slate)
TimingApproximate (~30 min)Exact (cron expression)
Token costHigh (loads full context)Low (minimal context)
Best forQuick checks, batchingScheduled tasks, reports

If your heartbeat is mostly running scheduled tasks, migrate them to cron:

Terminal window
openclaw cron add --name "daily-log-check" \
--schedule "0 9 * * *" \
--message "Ensure memory/$(date +%Y-%m-%d).md exists"

Strategy 5: Disable heartbeats entirely

Important

Only disable heartbeats if you’ve confirmed cron jobs, webhooks, and direct messages cover all your triggers. Once disabled, the agent won’t wake up to check anything on its own.

If you’re fully cron-driven, turn off heartbeats:

{
"agents": {
"defaults": {
"heartbeat": {
"enabled": false
}
}
}
}

Your agent will only wake for:

  • Direct messages
  • Cron job triggers
  • Webhook events

No more background token burn.

Quick wins

  • Audit your HEARTBEAT.md. Delete anything that could be a cron job.
  • Remove nested file reads (don’t reference other HEARTBEAT.md files).
  • Set every to "60m" or higher.
  • Use a lighter model for heartbeat responses.
  • Track check timestamps in memory/heartbeat-state.json to avoid redundant work.

The math

Say your heartbeat consumes ~2,000 tokens per cycle:

IntervalDaily HeartbeatsDaily Tokens
15 min96192,000
30 min4896,000
60 min2448,000
2 hours1224,000

Doubling your interval = halving your cost. Simple.

Heartbeats are easy to over-use. Trim your HEARTBEAT.md, bump the interval to 60 minutes, move scheduled work to cron jobs, and consider a lighter model.

Your agent can still respond when you need it without running up the bill.


0reposts0favorites

Comments

You can comment on this blog post by publicly replying to this post using a Mastodon or other ActivityPub/Fediverse account. Known non-private replies are displayed below.

Open Post

Related Posts


Previous Post
Adding a Links Section to My Blog
Next Post
The Reality of AI Pair Programming: It's Not Magic, It's Management