Claude Task Runner
Use the local runner script instead of raw claude -p when the task needs any of these:
- - model switching via INLINECODE1
- durable task state under INLINECODE2
- notification on completion/failure
- structured-output enforcement via JSON Schema
- multi-file artifact validation (
--expect-file, --expect-contains, --expect-glob)
Primary script:
Quick decision
Use this skill when:
- - the user asks to run Claude Code non-interactively / in batch / in background
- you need a coding or analysis task to survive beyond a single shell command
- you want the result judged by actual outputs, not just model text
- tmux interaction is unnecessary or risky
Do not use this skill when:
- - a direct
read / edit is simpler - the user explicitly wants a live interactive tmux session
- the task needs persistent interactive back-and-forth inside Claude Code
Default workflow
- 1. Pick the model alias.
-
GLM-5.1 for architecture / long-context reasoning
-
minimax-m2.7 for deeper problem solving and robust headless runs
- 2. Decide whether the task needs validation.
- If validation is needed, prefer both:
- structured result validation with
--json-schema-file
- artifact validation with
--expect-file,
--expect-contains,
--expect-glob
- 4. Run the task with
cc-task-runner.sh run or run-file. - Inspect with
status, then log if anything looks off. - Treat missing artifact or
structured_output.status=failure as a real failure.
Command patterns
Minimal run
CODEBLOCK0
Write task with permission mode
CODEBLOCK1
Multi-file validation
All --expect-file, --expect-contains, --expect-glob support repeat usage.
--expect-contains binds to the most recent --expect-file before it.
CODEBLOCK2
Meaning:
- -
a.txt must exist AND contain "alpha" - INLINECODE26 must exist (no content check)
- INLINECODE27 glob must match at least one file
Full combo: schema + multi-file + glob
CODEBLOCK3
Prompt from file
CODEBLOCK4
Inspect state
CODEBLOCK5
Validation parameters
| Parameter | Repeatable | Binds to | Description |
|---|
| INLINECODE28 | ✅ yes | self | File must exist after task |
| INLINECODE29 |
✅ yes | previous
--expect-file | That file must contain text |
|
--expect-glob <pattern> | ✅ yes | self | Glob must match ≥1 file |
|
--json-schema-file <file> | ❌ no | self | Enforces structured output |
|
--permission-mode <mode> | ❌ no | self |
bypassPermissions or
acceptEdits |
|
--fallback-model <alias> | ❌ no | self | Retry with this model on failure |
|
--max-retries <n> | ❌ no | self | Max retry attempts (default: 1) |
Binding order example
CODEBLOCK6
Validation rules
For tasks that must produce files, always provide at least one artifact check.
Preferred combinations:
- - file creation only → INLINECODE38
- exact or critical content →
--expect-file + INLINECODE40 - one-or-more generated files → INLINECODE41
- non-file report / analysis → INLINECODE42
- implementation task → schema + artifact checks together
Permission mode: Prefer --permission-mode bypassPermissions in trusted local environments when the task must write files or run Bash. Without it, Claude may ask for manual approval and the task will hang.
Do not trust plain language like "已完成" or "done" without validation.
Exit codes
| Code | Meaning |
|---|
| 0 | Task completed, all validations passed |
| 1 |
Model/runtime error |
| 2 | Artifact validation failed |
| 3 | Structured output reported failure |
JSON schema guidance
Keep schemas small. Use them to force a machine-checkable result contract.
Good default schema for most tasks:
- -
status: INLINECODE45 - INLINECODE46 : short text
- INLINECODE47 : optional array
- INLINECODE48 : optional
- INLINECODE49 : optional
Model notes
Current local environment supports GLM-5.1 headless via:
- - base URL: INLINECODE51
- model id: INLINECODE52
The local cc-switch wrapper already special-cases this. Use the alias GLM-5.1, not a raw model id, when calling the runner.
Failure handling
If a task fails:
- 1. run INLINECODE55
- run INLINECODE56
- identify which layer failed:
- model/runtime error (exit 1)
- artifact validation failure (exit 2)
- structured schema failure (exit 3)
- 4. either rerun with a stricter prompt or fix the prompt/schema/expectations
If the model says success but artifact validation fails, trust the validator, not the prose.
Files to read when needed
Read these only when you need deeper details:
- -
references/runner-usage.md for usage notes and patterns - INLINECODE58 for a reusable schema template
- INLINECODE59 for a concrete invocation pattern
Claude 任务运行器
当任务需要以下任何功能时,使用本地运行器脚本而非原始的 claude -p:
- - 通过 cc-switch 切换模型
- 在 ~/.openclaw/state/cc-tasks/ 下持久化任务状态
- 完成/失败时发送通知
- 通过 JSON Schema 强制执行结构化输出
- 多文件产物验证(--expect-file、--expect-contains、--expect-glob)
主脚本:
- - /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh
快速决策
在以下情况下使用此技能:
- - 用户要求以非交互式/批处理/后台方式运行 Claude Code
- 你需要一个编码或分析任务在单个 shell 命令之外持续存在
- 你希望根据实际输出(而非仅模型文本)来判断结果
- tmux 交互不必要或有风险
在以下情况下不使用此技能:
- - 直接使用 read/edit 更简单
- 用户明确要求实时交互式 tmux 会话
- 任务需要在 Claude Code 内部进行持续的交互式来回对话
默认工作流程
- 1. 选择模型别名。
- 架构/长上下文推理使用 GLM-5.1
- 更深层次问题解决和稳健的无头运行使用 minimax-m2.7
- 2. 判断任务是否需要验证。
- 如果需要验证,优先同时使用:
- 使用 --json-schema-file 进行结构化结果验证
- 使用 --expect-file、--expect-contains、--expect-glob 进行产物验证
- 4. 使用 cc-task-runner.sh run 或 run-file 运行任务。
- 使用 status 检查,如果发现异常再使用 log。
- 将缺失产物或 structured_output.status=failure 视为真正的失败。
命令模式
最小化运行
bash
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh run \
任务名称 \
GLM-5.1 \
/绝对路径/工作目录 \
-- 你的任务提示词
带权限模式的写入任务
bash
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh run \
任务名称 \
GLM-5.1 \
/绝对路径/工作目录 \
--permission-mode bypassPermissions \
-- 创建 /绝对路径/工作目录/output.txt,内容为:hello world
多文件验证
所有 --expect-file、--expect-contains、--expect-glob 支持重复使用。
--expect-contains 绑定到其之前的最近一个 --expect-file。
bash
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh run \
多重检查 \
GLM-5.1 \
/绝对路径/工作目录 \
--permission-mode bypassPermissions \
--expect-file /绝对路径/工作目录/a.txt \
--expect-contains alpha \
--expect-file /绝对路径/工作目录/b.txt \
--expect-glob out/*.log \
-- 创建 a.txt(内容为alpha ok),b.txt(内容为bravo ok),以及 out/run.log
含义:
- - a.txt 必须存在且包含 alpha
- b.txt 必须存在(不检查内容)
- out/*.log 通配符必须匹配至少一个文件
完整组合:schema + 多文件 + 通配符
bash
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh run \
完整检查 \
GLM-5.1 \
/绝对路径/工作目录 \
--permission-mode bypassPermissions \
--json-schema-file /绝对路径/schema.json \
--expect-file /绝对路径/工作目录/output.txt \
--expect-contains 期望的文本 \
--expect-glob logs/*.log \
-- 你的任务提示词
从文件读取提示词
bash
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh run-file \
任务名称 \
minimax-m2.7 \
/绝对路径/工作目录 \
/绝对路径/prompt.txt \
--json-schema-file /绝对路径/schema.json
检查状态
bash
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh status 任务名称
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh log 任务名称
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh list
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh kill 任务名称
bash /Users/zhengweidong/.openclaw/workspace/scripts/cc-task-runner.sh clean
验证参数
| 参数 | 可重复 | 绑定到 | 描述 |
|---|
| --expect-file <路径> | ✅ 是 | 自身 | 任务完成后文件必须存在 |
| --expect-contains <文本> |
✅ 是 | 前一个 --expect-file | 该文件必须包含文本 |
| --expect-glob <模式> | ✅ 是 | 自身 | 通配符必须匹配 ≥1 个文件 |
| --json-schema-file <文件> | ❌ 否 | 自身 | 强制执行结构化输出 |
| --permission-mode <模式> | ❌ 否 | 自身 | bypassPermissions 或 acceptEdits |
| --fallback-model <别名> | ❌ 否 | 自身 | 失败时使用此模型重试 |
| --max-retries
| ❌ 否 | 自身 | 最大重试次数(默认:1) |
绑定顺序示例
bash
--expect-file a.txt \
--expect-contains hello \
--expect-contains world \ # 在 a.txt 中同时检查 hello 和 world
--expect-file b.txt \ # b.txt 只需存在
--expect-glob out/*.csv # 独立的通配符检查
验证规则
对于必须生成文件的任务,始终提供至少一个产物检查。
推荐组合:
- - 仅创建文件 → --expect-file
- 精确或关键内容 → --expect-file + --expect-contains
- 一个或多个生成的文件 → --expect-glob
- 非文件的报告/分析 → --json-schema-file
- 实现任务 → schema 和产物检查一起使用
权限模式:在可信的本地环境中,当任务必须写入文件或运行 Bash 时,优先使用 --permission-mode bypassPermissions。否则,Claude 可能会要求手动批准,导致任务挂起。
不要仅凭 已完成 或 done 等自然语言就信任,而不进行验证。
退出码
模型/运行时错误 |
| 2 | 产物验证失败 |
| 3 | 结构化输出报告失败 |
JSON Schema 指南
保持 schema 简洁。使用它们来强制执行机器可检查的结果契约。
大多数任务的良好默认 schema:
- - status:success|failure
- summary:简短文本
- fileschanged:可选数组
- errorcategory:可选
- suggestion:可选
模型说明
当前本地环境支持通过以下方式无头运行 GLM-5.1:
- - 基础 URL:https://open.bigmodel.cn/api/anthropic
- 模型 ID:glm-5.1
本地的 cc-switch 包装器已对此进行了特殊处理。调用运行器时使用别名 GLM-5.1,而非原始模型 ID。
失败处理
如果任务失败:
- 1. 运行 status
- 运行 log
- 识别哪个层面失败:
- 模型/运行时错误(退出码 1)
- 产物验证失败(退出码 2)
- 结构化 schema 失败(退出码 3)
- 4. 要么使用更严格的提示词重新运行,要么修复提示词/schema/期望条件
如果模型报告成功但产物验证失败,信任验证器,而非模型文本。