Claude Code 新功能:/loop 让 AI 自动帮你"值班"
一、3月7日上线的新功能
Claude Code 内置了 /loop 命令,会话内的定时任务调度器。
能干什么:
- 自动重复执行提示词
- 后台监控项目状态
- 设置一次性提醒
举个例子:
/loop 10m check if deployment finished
/loop every morning at 9:00 summarize my Slack mentions
remind me at 3pm to push the release branch
二、怎么用
三种写法
前置间隔:
/loop 5m check the build
后置 every:
/loop check the build every 2 hours
不写间隔(默认10分钟):
/loop babysit all my PRs
时间单位
-
s秒(会向上取整到分钟) -
m分钟 -
h小时 -
d天
一次性提醒
remind me at 3pm to push the release branch
in 45 minutes, check whether the tests passed
三、管理任务
查看:
what scheduled tasks do I have?
取消:
cancel the deploy check job
cancel task abc12345
每个会话最多 50 个任务。
四、实际场景
部署监控:
/loop 10m check deployment status and alert on errors
PR 自动修复:
/loop babysit all my PRs. When builds fail auto-fix
每日晨报:
/loop every morning at 9:05 use Slack MCP to summarize mentions
CI 检查:
/loop 15m check main branch CI, notify if red
循环执行命令:
/loop 20m /review-pr 1234
五、工作原理
时区:用本地时区,不是 UTC。0 9 * * * 就是本地早上9点。
时间抖动:
- 循环任务延迟最多 10%(上限15分钟)
- 整点提醒可能提前90秒
避坑:用 9:07 别用 9:00。
执行时机:Claude 空闲时执行,不打断当前回复。
六、限制
会话级别:关闭终端任务就没了,不会保存到磁盘。
3天过期:创建后72小时自动删除,删除前最后执行一次。
无补偿:错过的不会补跑,只等下一次。
生产环境:长期任务用 Desktop Scheduled Tasks 或 GitHub Actions。
七、开始用
更新 Claude Code:https://code.claude.com
试试:
/loop 10m check if main branch build is green
查看:
what scheduled tasks do I have?
八、总结
/loop 让 AI 从被动回答变成主动干活。
适合短期监控、开发调试、临时任务。
不适合长期无人值守、生产环境、需要持久化的任务。
官方文档:https://code.claude.com/docs/en/scheduled-tasks
本文完
Top comments (0)