cc-monitor
Skill0 starsChanged 6 months agoMITView on GitHub
Enables Claude Code's event-driven Monitor tool for watching long-running background processes (deep learning training, CI/CD pipelines, dev servers, test suites) without polling. Use when the user wants to run a background task and only be notified on meaningful events—errors, milestones, or completion—while spending zero tokens waiting. Triggers on phrases like "monitor training", "watch logs", "notify me when done", "run in background and alert", "deep learning training progress", "non-polling background watch".
In this repository9 other files it gives its agents.
The file
Files
Claude Code Monitor Skill
让 Claude Code 以事件驱动方式监控长时间运行的后台任务,等待期间零 token 消耗。
核心原理
Monitor 工具将 Claude Code 从"轮询模型"切换为"中断模型":
- 旧方式(轮询):每 N 分钟发一次完整 API 请求问"完成了吗?" → 浪费 token
- 新方式(Monitor):注册一个 shell 命令,其 stdout 每行 = 一个事件;命令静默时 Claude 不消耗任何 token,有输出时才唤醒
使用步骤
Step 1:在后台启动长时间任务
# 示例:深度学习训练
python train.py --epochs 100 --output-dir ./runs/exp1 > training.log 2>&1 &
echo "Training PID: $!"使用 Ctrl+B 或显式告诉 Claude 后台运行:
"在后台运行训练脚本,完成后通知我"
Step 2:附加 Monitor
Claude Code 会自动构造 Monitor。你也可以明确指定:
帮我监控 training.log,当出现 "Epoch" 进度、loss 变化或 ERROR 时提醒我Step 3:选择合适的监控脚本
根据场景选择 scripts/ 下对应脚本(见下表):
| 场景 | 脚本 | 说明 |
| 深度学习训练 | scripts/monitor-training.sh | 过滤 Epoch/loss/ERROR/GPU |
| 通用日志文件 | scripts/monitor-log.sh | 可自定义关键字过滤 |
| 进程存活监控 | scripts/monitor-process.sh | 检测进程退出/崩溃 |
| GPU 显存监控 | scripts/monitor-gpu.sh | nvidia-smi 周期采样 |
Monitor 参数速查
| 参数 | 说明 | 推荐值 |
description | 通知标签(显示在每条事件中) | 简短描述,如 "training errors" |
command | 事件流命令(stdout 每行=事件) | 见脚本或下方示例 |
timeout_ms | 超时自动终止(ms) | 训练用 3600000(1h),可叠加多个 |
persistent | true = 整个 session 持续运行 | 开发服务器用 true;训练用 false |
常用 Monitor 命令模板
深度学习训练监控
# 监控训练日志,过滤关键事件
tail -f training.log | grep --line-buffered -E "Epoch|loss|acc|ERROR|Traceback|CUDA|KeyboardInterrupt|Finished"任意进程完成通知
# 等待进程结束后发出通知
bash scripts/monitor-process.sh <PID>GPU 显存告警
# 每 30s 采样,显存超过 90% 时告警
bash scripts/monitor-gpu.sh 90自定义日志关键字
# 等价于 monitor-log.sh
tail -f /path/to/app.log | grep --line-buffered -E "ERROR|WARN|成功|完成"⚠️ 三条关键规则
- 必须加
--line-buffered:管道里 grep 不加此参数会缓冲输出,导致事件延迟数分钟 - poll loop 需处理失败:循环里的 API 调用后加
|| true,避免单次超时杀死整个 monitor - 控制 stdout 输出量:每行输出都会消耗 token,只过滤真正关键的信息
Token 效益对比
| 方式 | 10 分钟训练(2 分钟检查一次) | 实际有效调用 |
| /loop 轮询 | 5 次完整 API 调用 | 1 次(完成时) |
| Monitor 工具 | 1 次(有事件时才触发) | 1 次 |
长时间训练(如 8h)节省效果更显著:轮询 ≈ 240 次 API 调用 vs Monitor ≈ 若干次事件推送。
完整示例:深度学习训练
用户:帮我在后台跑 train.py,训练过程中监控 loss 和错误,训练完成告知我结果
Claude 会执行:
1. python train.py > training.log 2>&1 & (后台启动)
2. 附加 Monitor,command = "tail -f training.log | grep --line-buffered -E ..."
3. 等待——期间零 token 消耗
4. 训练结束或出现异常时,Monitor 推送事件,Claude 唤醒并汇报详细参数说明和高级用法见 references/REFERENCE.md。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

