Skip to content
雲里
里雾

06 OpenClaw 自动化——Cron、Webhook 与 Standing Orders

openclaw guide AI 更新于 2026/3/26

原文:docs/automation/ 目录(cron-jobs.md, webhook.md, standing-orders.md, cron-vs-heartbeat.md, poll.md)

三种自动化模式

模式触发方式适用
Cron定时(schedules.json)定期检查、日报、清理
Webhook外部 HTTP 请求GitHub Push、Stripe 支付、邮件到达
Standing Orders每次 Agent 运行后检查始终有效的长期指令

Cron(定时任务)

配置在 workspace 的 schedules.json 中:

[
  {
    "cron": "0 9 * * 1-5",
    "prompt": "检查邮箱,总结重要邮件",
    "skill": "email-checker",
    "channel": "whatsapp"
  }
]

与 Claude Code 的对比

Claude CodeOpenClaw
配置方式UI / CLI / APIschedules.json
运行环境独立 Claude Code 进程 / 云端Gateway 内嵌 Agent 运行
结果通知通知当前会话发送到指定 channel
持久性关闭 CLI 后停止(除云端)Gateway 长驻,始终执行

Cron vs Heartbeat

CronHeartbeat
触发固定时间表Gateway 心跳事件
适用”每天 9 点做 X""每隔 N 分钟检查 Y”
精度分钟级受心跳间隔影响

Webhook(外部触发)

OpenClaw 可以接收外部 HTTP 请求并触发 Agent 运行:

curl -X POST http://localhost:18789/__openclaw__/webhook/my-hook \
  -H "Content-Type: application/json" \
  -d '{"event": "push", "repo": "my-project"}'

经典用法

对比 Claude Code:Claude Code 的 Hook 是”内部事件”触发,没有外部 HTTP 入口。GitHub Actions 是 Claude Code 的外部触发方案,但运行在 CI 环境而非本地。

Standing Orders(长效指令)

“无论何时运行,都要检查这些”——嵌入到 Agent 的每次运行中:

# Standing Orders
- 如果用户提到日程,检查日历有无冲突
- 如果讨论到代码,运行 lint 检查
- 每次结束前,更新 MEMORY.md

这是 OpenClaw 特有的概念。Claude Code 最接近的是 CLAUDE.md 中的”始终执行”规则,但 CLAUDE.md 是”建议性”的,Standing Orders 更接近”义务性”的。

与 Claude Code 自动化对比

自动化需求Claude Code 方案OpenClaw 方案
定时任务Scheduled Tasks / /loop / GitHub ActionsCron(schedules.json)
外部事件触发GitHub Actions(CI 事件)Webhook(直接 HTTP)
始终检查CLAUDE.md 规则Standing Orders
轮询/loopPoll 机制
邮件监控无内置Gmail Pub/Sub
Auth 监控无内置auth-monitoring

知识检测

概念理解题

  1. Cron、Webhook、Standing Orders 三者各自的触发机制和适用场景有什么区别?

  2. Standing Orders 和 CLAUDE.md 中的”始终执行”规则有什么本质区别?为什么 OpenClaw 要单独设计这个概念?

应用题

  1. 你想让你的 OpenClaw Agent 做以下事情:(a) 每天早上 8 点总结昨天的 GitHub 提交 (b) 每当有新 PR 就自动审查 (c) 每次对话结束前保存笔记。分别用什么自动化机制?写出配置。

迁移思考题

  1. 如果你要在 Claude Code 中实现 OpenClaw 的 Webhook 功能(接收外部 HTTP 请求触发 Agent 运行),你会怎么设计?(提示:考虑 -p 模式 + 一个简单的 HTTP server)

参见

参考答案

1. 三种自动化模式的区别

Cron:时间驱动——“每天 9 点做 X”。不关心外部发生了什么,到点就执行。适合定期检查、日报、清理。
Webhook:事件驱动——“当外部系统通知我 Y 发生了,做 Z”。被动等待触发,适合对外部事件做出即时反应(GitHub push、支付通知)。
Standing Orders:始终有效——“无论何时运行,都检查 W”。嵌入到每次 Agent 运行中,不需要额外触发。适合不变的长期规则。
三者互补:Cron 定时发起,Webhook 被动响应,Standing Orders 保底检查。

2. Standing Orders vs CLAUDE.md 的区别

CLAUDE.md 是”上下文”——Claude 看到后作为参考,可能遵守可能不遵守。Standing Orders 更接近”义务”——它们被注入到 Agent 的每次运行中作为明确的待办事项。概念上的差异:CLAUDE.md 是”你应该知道的事情”(偏声明性),Standing Orders 是”你每次都必须做的事情”(偏命令性)。OpenClaw 单独设计这个概念是因为服务型 Agent 需要更可靠的”始终检查”机制——Agent 可能被不同渠道的不同用户触发,Standing Orders 确保无论谁触发、从哪个渠道来,某些检查总是执行。

3. 三种自动化的配置

(a) 每天 8 点总结 GitHub 提交 → Cron:

[{
  "cron": "0 8 * * 1-5",
  "prompt": "用 gh CLI 获取昨天的所有 commit,按项目分组总结",
  "skill": "github-summary",
  "channel": "whatsapp"
}]

(b) 新 PR 自动审查 → Webhook:配置 GitHub webhook 指向 http://gateway:18789/__openclaw__/webhook/pr-review,Handler 收到 PR 事件后触发 Agent 审查。
(c) 每次对话结束前保存笔记 → Standing Orders(嵌入 AGENTS.md):

## Standing Orders
- 每次结束对话前,将本次讨论的关键决策和待办写入 memory/daily-notes.md

4. 在 Claude Code 中实现 Webhook

写一个简单的 HTTP server(Node.js 或 Python Flask):

from flask import Flask, request
import subprocess
app = Flask(__name__)

@app.route('/webhook/<hook_name>', methods=['POST'])
def handle(hook_name):
    data = request.json
    prompt = f"Webhook '{hook_name}' received: {json.dumps(data)}\nProcess this event."
    result = subprocess.run(
        ['claude', '--bare', '-p', prompt, '--allowedTools', 'Read,Edit,Bash'],
        capture_output=True, text=True
    )
    return {'status': 'ok', 'output': result.stdout}

局限:每次 webhook 触发都是冷启动(无状态),没有流式输出,不能利用之前的对话上下文。OpenClaw 的 Gateway 避免了这些问题。