👷

智能守护你的自动化编码代理

claude-code-supervisor · vv1.0.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
开发 安全 S 级 作者 johba37 公开目录收录
3.9k 下载 814 安装 18.4k 收藏 18k 浏览

简介

基于 Bash 预过滤与 LLM 智能分类的 Claude Code 会话监控方案,实现无人值守任务的错误检测、自动恢复与状态通知,提升自动化编码代理的可靠性。

原始描述

Supervise Claude Code sessions running in tmux. Uses Claude Code hooks with bash pre-filtering (Option D) and fast LLM triage to detect errors, stuck agents, and task completion. Harness-agnostic — works with OpenClaw, webhooks, ntfy, or any notification backend. Use when: (1) launching long-running Claude Code tasks that need monitoring, (2) setting up automatic nudging for API errors or premature stops, (3) getting progress reports from background coding agents, (4) continuing work after session/context limits reset. Requires: tmux, claude CLI.

通过你的 Agent 添加

安装目录:claude-code-supervisor/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/claude-code-supervisor/
Codex CLI~/.codex/skills/claude-code-supervisor/
DeepSeek Harness~/.agents/skills/claude-code-supervisor/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Claude Code Supervisor 是一套专为长时间运行的 Claude Code 会话设计的监控基础设施。它通过拦截 Claude Code 的生命周期钩子(Stop、Error、Notification),结合 Bash 预过滤与轻量级 LLM 智能分类,实现对代理状态的实时感知与自动干预。

部署流程简洁:运行安装脚本将钩子注入目标项目,配置 YAML 文件指定分类模型与通知后端,随后在 tmux 中启动 Claude Code 任务即可。系统会自动识别会话异常(API 错误、上下文耗尽、任务完成等),并通过用户自定义的通知渠道(OpenClaw、Webhook、ntfy 等)上报,支持自动"轻推"(nudge)恢复或人工升级处理。

显著优点

分层架构降低开销:Bash 预过滤层(Option D)先处理明显场景(如正常停止、瞬态 429 错误),仅将模糊情况提交 LLM 分类,大幅减少 API 调用成本与延迟。

Harness 无关设计:不绑定特定代理框架,通过可配置的 notify.command 适配任意通知后端,从个人脚本到企业级编排系统均可集成。

双重保障机制:除钩子驱动的主动监控外,独立的 Watchdog 脚本以纯 Bash 实现(零 LLM 依赖),定期检测进程存活状态,防止 Claude Code 崩溃、OOM 或账户限流导致的监控盲区。

精细的状态分类:LLM 分类器输出五种明确状态(FINE / NEEDS_NUDGE / STUCK / DONE / ESCALATE),为下游自动化决策提供结构化输入。

潜在缺点与局限性

基础设施依赖:强制要求 tmux 与 Claude CLI,Windows 原生环境支持有限;本地 LLM 选项(如 Ollama)虽可降低云 API 依赖,但增加了部署复杂度。

配置门槛:YAML 配置、状态文件管理、tmux socket 权限等环节需要用户具备一定运维经验,非技术用户上手成本较高。

通知延迟风险:Bash 预过滤虽提升效率,但极端情况下可能误判(如将"接近完成"误判为"正常工作中"),导致通知延迟或遗漏。

权限边界模糊:通过 send-keys 向 tmux 会话注入输入的操作,若目标会话被恶意劫持,可能造成命令注入风险(尽管此风险主要源于 tmux 本身的安全配置)。

适合的目标群体

  • 需要夜间/无人值守运行 Claude Code 任务的开发者与团队
  • 已采用 OpenClaw、n8n、Huginn 等代理编排框架的高级用户
  • 追求自动化故障恢复、减少人工监控成本的工程团队
  • 具备 Bash 与 tmux 基础、愿意投入配置时间的运维人员

使用风险

配置注入风险:triage.command 与 notify.command 执行用户配置的任意命令,若配置文件被篡改,可能导致恶意代码执行。建议将配置文件纳入版本控制并设置只读权限。

tmux 会话安全:共享 tmux socket 或宽松权限设置可能允许未授权进程注入输入。应确保 socket 文件权限为 600,并限制访问用户。

LLM 服务依赖:云 API(Claude Haiku)可能因限流、故障或成本超支失效;本地模型虽可降级,但需额外维护 Ollama 等服务。

日志与隐私:尽管设计为本地优先,但通知内容可能包含项目路径、错误摘要等信息,若配置 webhook 指向第三方服务,需评估数据出境合规性。

资源占用:长时间监控大量会话时,Watchdog 的轮询机制与 LLM 分类调用可能产生不可忽视的计算与 API 成本。

技能正文


name: claude-code-supervisor description: > Supervise Claude Code sessions running in tmux. Uses Claude Code hooks with bash pre-filtering (Option D) and fast LLM triage to detect errors, stuck agents, and task completion. Harness-agnostic — works with OpenClaw, webhooks, ntfy, or any notification backend. Use when: (1) launching long-running Claude Code tasks that need monitoring, (2) setting up automatic nudging for API errors or premature stops, (3) getting progress reports from background coding agents, (4) continuing work after session/context limits reset. Requires: tmux, claude CLI. metadata: { "openclaw": { "emoji": "👷", "os": ["darwin", "linux"], "requires": { "bins": ["tmux"], "anyBins": ["claude"] }, }, }

Claude Code Supervisor

Bridge between Claude Code's lifecycle hooks and your agent harness.

Architecture

Claude Code (in tmux)
  │  Stop / Error / Notification
  ▼
Bash pre-filter (Option D)
  │  obvious cases handled directly
  │  ambiguous cases pass through
  ▼
Fast LLM triage (claude -p with Haiku, or local LLM)
  │  classifies: FINE | NEEDS_NUDGE | STUCK | DONE | ESCALATE
  │  FINE → logged silently
  ▼
Notify command (configurable)
  │  openclaw wake, webhook, ntfy, script, etc.
  ▼
Agent harness decides + acts
  │  nudge (send-keys to tmux), wait, escalate to human

Quick Start

1. Install hooks into a project

{baseDir}/scripts/install-hooks.sh /path/to/your/project

Creates:

  • .claude/hooks/supervisor/ — hook scripts + triage
  • .claude/settings.json — wired into Claude Code lifecycle
  • .claude-code-supervisor.yml — configuration (edit this)

2. Configure

Edit .claude-code-supervisor.yml:

triage:
  command: "claude -p --no-session-persistence"  # or: ollama run llama3.2
  model: "claude-haiku-4-20250414"

notify:
  command: "openclaw gateway call wake --params"  # or: curl, ntfy, script

3. Register a supervised session

Create ~/.openclaw/workspace/supervisor-state.json (or wherever your harness keeps state):

{
  "sessions": {
    "my-task": {
      "socket": "/tmp/openclaw-tmux-sockets/openclaw.sock",
      "tmuxSession": "my-task",
      "projectDir": "/path/to/project",
      "goal": "Fix issue #42",
      "successCriteria": "Tests pass, committed",
      "maxNudges": 5,
      "escalateAfterMin": 60,
      "status": "running"
    }
  }
}

4. Launch Claude Code in tmux

SOCKET="/tmp/openclaw-tmux-sockets/openclaw.sock"
tmux -S "$SOCKET" new -d -s my-task
tmux -S "$SOCKET" send-keys -t my-task "cd /path/to/project && claude 'Fix issue #42'" Enter

Hooks fire automatically. Triage assesses. You get notified only when it matters.

How the Pre-Filter Works (Option D)

Not every hook event needs an LLM call. Bash catches the obvious cases first:

on-stop.sh

Signal Bash decision LLM triage?
max_tokens Always needs attention ✅ Yes
end_turn + shell prompt back Agent might be done ✅ Yes
end_turn + no prompt Agent is mid-work ❌ Skip
stop_sequence Normal ❌ Skip

on-error.sh

Signal Bash decision LLM triage?
API 429 / rate limit Transient, will resolve ❌ Log only
API 500 Agent likely stuck ✅ Yes
Other tool error Unknown severity ✅ Yes

on-notify.sh

Signal Bash decision LLM triage?
auth_* Internal, transient ❌ Skip
permission_prompt Needs decision ✅ Yes
idle_prompt Agent waiting ✅ Yes

Triage Classifications

The LLM returns one of:

Verdict Meaning Typical action
FINE Agent is working normally Log silently, no notification
NEEDS_NUDGE Transient error, should continue Send "continue" to tmux
STUCK Looping or not progressing Try different approach or escalate
DONE Task completed successfully Report to human
ESCALATE Needs human judgment Notify human with context

Handling Notifications (for agent harness authors)

Wake events arrive with the prefix cc-supervisor: followed by the classification:

cc-supervisor: NEEDS_NUDGE | error:api_500 | cwd=/home/user/project | ...
cc-supervisor: DONE | stopped:end_turn:prompt_back | cwd=/home/user/project | ...

Nudging via tmux

tmux -S "$SOCKET" send-keys -t "$SESSION" "continue — the API error was transient" Enter

Escalation format

See references/escalation-rules.md for when to nudge vs escalate and quiet hours.

Watchdog (Who Watches the Watchman?)

Hooks depend on Claude Code being alive. If the session hard-crashes, hits account limits, or the process gets OOM-killed, no hooks fire. The watchdog catches this.

scripts/watchdog.sh is a pure bash script (no LLM, no Claude Code dependency) that:

  1. Reads supervisor-state.json for all "running" sessions
  2. Checks: is the tmux socket alive? Is the session there? Is Claude Code still running?
  3. If something is dead and no hook reported it → notifies via the configured command
  4. Updates lastWatchdogAt in state for tracking

Run it on a timer. Choose your poison:

System cron:

*/15 * * * * /path/to/claude-code-supervisor/scripts/watchdog.sh

OpenClaw cron:

{
  "schedule": { "kind": "every", "everyMs": 900000 },
  "payload": { "kind": "systemEvent", "text": "cc-supervisor: watchdog — run /path/to/scripts/watchdog.sh and report" },
  "sessionTarget": "main"
}

systemd timer, launchd, or whatever runs periodically on your box.

The watchdog is deliberately dumb — no LLM, no complex logic, just "is the process still there?" This means it works even when the triage model is down, the API is melting, or your account hit its limit. Belts and suspenders.

Files

  • scripts/install-hooks.sh — one-command setup per project
  • scripts/hooks/on-stop.sh — Stop event handler with bash pre-filter
  • scripts/hooks/on-error.sh — PostToolUseFailure handler with bash pre-filter
  • scripts/hooks/on-notify.sh — Notification handler with bash pre-filter
  • scripts/triage.sh — LLM triage (called by hooks for ambiguous cases)
  • scripts/lib.sh — shared config loading and notification functions
  • scripts/watchdog.sh — dead session detector (pure bash, no LLM dependency)
  • references/state-patterns.md — terminal output pattern matching guide
  • references/escalation-rules.md — when to nudge vs escalate vs wait
  • supervisor.yml.example — example configuration

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

automationdevopsdevelopment-engineeringbackendproductivitymonitoringcli

同类 Skill