零轮询 Claude Code 工作流,省 80% token
简介
基于回调通知的Claude Code工作流,通过消除轮询机制节省80%+监控token,智能判断何时启动后台任务。
原始描述
Token-efficient Claude Code workflow. Other skills burn tokens polling tmux every 30s — this one uses completion callbacks and only checks when notified. Obs...
通过你的 Agent 添加
安装目录:claude-code-pro/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
Claude Code Pro 是一套生产级的 Claude Code 后台任务管理方案,核心创新在于用回调通知替代轮询机制。
典型工作流:
- 智能判断:评估任务是否涉及3+文件,简单任务直接编辑,复杂任务才启动后台会话
- 启动任务:使用
start.sh创建带完成回调的 tmux 会话,任务结束时自动发送通知 - 零成本等待:任务执行期间不消耗任何 token 监控状态
- 结果确认:收到通知后,用
monitor.sh轻量读取50行输出确认结果
关键命令:
# 启动带回调的任务
bash scripts/start.sh --label feature-x --workdir ~/project --task "重构任务...完成后运行: openclaw system event --text 'Done: 完成' --mode now"
# 轻量监控
bash scripts/monitor.sh --session feature-x --lines 50 --json
显著优点
指标
传统轮询方案
本方案
20分钟任务 token 消耗
~10,000-20,000
~500
监控方式
每30-60秒轮询
事件驱动回调
状态判断准确性
推测性
确定性
多任务并行
轮询成本叠加
零边际成本
| 指标 | 传统轮询方案 | 本方案 |
|---|---|---|
| 20分钟任务 token 消耗 | ~10,000-20,000 | ~500 |
| 监控方式 | 每30-60秒轮询 | 事件驱动回调 |
| 状态判断准确性 | 推测性 | 确定性 |
| 多任务并行 | 轮询成本叠加 | 零边际成本 |
智能调度规则避免不必要的会话创建,从源头节省资源。
潜在局限
- 依赖 tmux 环境:需要目标系统安装 tmux
- Claude CLI 必需:需已配置
claude 命令行工具
- 回调可靠性:任务若崩溃或中途退出,可能无法触发通知(建议15分钟无通知后备援轮询)
- 学习曲线:相比直接轮询,需要理解回调机制并正确配置完成命令
适合人群
- 频繁使用 Claude Code 处理多文件开发任务的开发者
- 需要并行管理多个后台编码任务的团队
- 对 token 成本敏感、追求高效工作流的高级用户
- 已有 tmux 使用经验的系统用户
常规风险
风险类型
说明
缓解措施
通知丢失
任务异常退出导致回调未执行
设置15分钟超时后备援检查
权限问题
tmux socket 或 Claude CLI 权限配置不当
预先验证 tmux -L cc 和 claude 可用性
任务冲突
多个会话操作同一工作目录
使用 --label 明确区分,避免重叠
输出截断
监控行数设置过低遗漏关键信息
首次检查可用 --lines 200,后续用 --lines 50
claude 命令行工具- 频繁使用 Claude Code 处理多文件开发任务的开发者
- 需要并行管理多个后台编码任务的团队
- 对 token 成本敏感、追求高效工作流的高级用户
- 已有 tmux 使用经验的系统用户
常规风险
风险类型
说明
缓解措施
通知丢失
任务异常退出导致回调未执行
设置15分钟超时后备援检查
权限问题
tmux socket 或 Claude CLI 权限配置不当
预先验证 tmux -L cc 和 claude 可用性
任务冲突
多个会话操作同一工作目录
使用 --label 明确区分,避免重叠
输出截断
监控行数设置过低遗漏关键信息
首次检查可用 --lines 200,后续用 --lines 50
| 风险类型 | 说明 | 缓解措施 |
|---|---|---|
| 通知丢失 | 任务异常退出导致回调未执行 | 设置15分钟超时后备援检查 |
| 权限问题 | tmux socket 或 Claude CLI 权限配置不当 | 预先验证 tmux -L cc 和 claude 可用性 |
| 任务冲突 | 多个会话操作同一工作目录 | 使用 --label 明确区分,避免重叠 |
| 输出截断 | 监控行数设置过低遗漏关键信息 | 首次检查可用 --lines 200,后续用 --lines 50 |
安全等级说明:S 级——纯本地脚本执行,无网络外联,无代码注入风险,依赖项均为成熟开源工具(tmux、bash)。
技能正文
name: claude-code-pro
description: >
Token-efficient Claude Code workflow. Other skills burn tokens polling tmux every 30s —
this one uses completion callbacks and only checks when notified. Observable tmux sessions,
smart dispatch rules (know when NOT to spawn Claude Code), and structured JSON monitoring.
Saves 80%+ supervision tokens vs polling-based approaches.
Use when: multi-file coding tasks that need background execution.
NOT for: simple single-file fixes (just read+edit directly — that's the point).
Requires: tmux, claude CLI.
metadata:
{
"openclaw":
{
"emoji": "⚡",
"os": ["darwin", "linux"],
"requires": { "bins": ["tmux", "bash"], "anyBins": ["claude"] },
},
}
Claude Code Pro ⚡
Production-grade Claude Code workflow that doesn't waste your tokens.
The Problem with Other Skills
Most Claude Code tmux skills work like this:
Start task → Poll every 30s → Poll → Poll → Poll → Done
🔥 tokens 🔥 🔥 🔥
Each poll reads 100-200 lines of terminal output, feeds it to your agent, and burns tokens deciding "is it done yet?" A 20-minute task = 40 polls = thousands of wasted tokens.
How This Skill Works
Start task (with callback) → Wait → 📩 Notification → Read result (50 lines)
😴 zero tokens ⚡ one read
Start task (with callback) → Wait → 📩 Notification → Read result (50 lines)
😴 zero tokens ⚡ one read
The task itself tells you when it's done. Your agent sleeps until notified. One lightweight check confirms the result. That's it.
Token Savings Breakdown
Approach
20-min task
Tokens burned
Poll every 30s
40 reads × ~500 tokens
~20,000
Poll every 60s
20 reads × ~500 tokens
~10,000
This skill
1 notification + 1 read
~500
| Approach | 20-min task | Tokens burned |
|---|---|---|
| Poll every 30s | 40 reads × ~500 tokens | ~20,000 |
| Poll every 60s | 20 reads × ~500 tokens | ~10,000 |
| This skill | 1 notification + 1 read | ~500 |
80-97% token savings on supervision alone.
Smart Dispatch: Know When NOT to Start
Before spawning Claude Code, ask:
| Situation | Action |
|---|---|
| < 3 files involved | Don't start CC. Just read + edit directly. |
| Single bug fix | Don't start CC. Faster to fix inline. |
| Need extensive context exploration | ✅ Start CC |
| Multi-file refactor | ✅ Start CC |
| New feature (5+ files) | ✅ Start CC |
The fastest token savings come from not spawning a session at all.
Quick Start
# Start a task — note the callback at the end
bash {baseDir}/scripts/start.sh --label auth-refactor --workdir ~/project --task "Refactor auth module to use JWT.
When completely finished, run: openclaw system event --text \"Done: JWT auth refactor complete\" --mode now"
# Start a task — note the callback at the end
bash {baseDir}/scripts/start.sh --label auth-refactor --workdir ~/project --task "Refactor auth module to use JWT.
When completely finished, run: openclaw system event --text \"Done: JWT auth refactor complete\" --mode now"
That's the key line: openclaw system event --text "Done: ..." --mode now. The task notifies your agent on completion. No polling needed.
Task from file (complex requirements)
bash {baseDir}/scripts/start.sh --label my-feature --workdir ~/project \
--task-file /path/to/requirements.md --mode auto
bash {baseDir}/scripts/start.sh --label my-feature --workdir ~/project \
--task-file /path/to/requirements.md --mode auto
Write detailed requirements once upfront → fewer mid-task corrections → fewer tokens.
Monitor (Only When Needed)
# Lightweight check — 50 lines, minimal tokens
bash {baseDir}/scripts/monitor.sh --session my-task --lines 50
# JSON mode — structured, even fewer tokens for agent parsing
bash {baseDir}/scripts/monitor.sh --session my-task --json
# Send follow-up (use sparingly — write requirements upfront instead)
bash {baseDir}/scripts/send.sh --session my-task --text "Also add unit tests"
# Compact context when running long
bash {baseDir}/scripts/send.sh --session my-task --compact
Manage Sessions
# List all active sessions
bash {baseDir}/scripts/list.sh # human-readable
bash {baseDir}/scripts/list.sh --json # structured
# Stop sessions
bash {baseDir}/scripts/stop.sh --session my-task
bash {baseDir}/scripts/stop.sh --all
Attach (Human SSH Access)
tmux -L cc attach -t cc-<label>
Agent Workflow
1. DECIDE — Is this a 3+ file task? No → just edit. Yes → continue.
2. START — start.sh with detailed task + completion callback
3. WAIT — Do other work. Zero tokens spent watching.
4. NOTIFIED — Receive "Done: ..." event
5. CHECK — monitor.sh --lines 50 to confirm result
6. CLEANUP — stop.sh to end session
# Lightweight check — 50 lines, minimal tokens
bash {baseDir}/scripts/monitor.sh --session my-task --lines 50
# JSON mode — structured, even fewer tokens for agent parsing
bash {baseDir}/scripts/monitor.sh --session my-task --json
# Send follow-up (use sparingly — write requirements upfront instead)
bash {baseDir}/scripts/send.sh --session my-task --text "Also add unit tests"
# Compact context when running long
bash {baseDir}/scripts/send.sh --session my-task --compact
# List all active sessions
bash {baseDir}/scripts/list.sh # human-readable
bash {baseDir}/scripts/list.sh --json # structured
# Stop sessions
bash {baseDir}/scripts/stop.sh --session my-task
bash {baseDir}/scripts/stop.sh --all
Attach (Human SSH Access)
tmux -L cc attach -t cc-<label>
Agent Workflow
1. DECIDE — Is this a 3+ file task? No → just edit. Yes → continue.
2. START — start.sh with detailed task + completion callback
3. WAIT — Do other work. Zero tokens spent watching.
4. NOTIFIED — Receive "Done: ..." event
5. CHECK — monitor.sh --lines 50 to confirm result
6. CLEANUP — stop.sh to end session
tmux -L cc attach -t cc-<label>
1. DECIDE — Is this a 3+ file task? No → just edit. Yes → continue.
2. START — start.sh with detailed task + completion callback
3. WAIT — Do other work. Zero tokens spent watching.
4. NOTIFIED — Receive "Done: ..." event
5. CHECK — monitor.sh --lines 50 to confirm result
6. CLEANUP — stop.sh to end session
Fallback: If no notification after 15 minutes, one lightweight poll with --json.
Completion Callback Template
Always append to your task prompt:
When completely finished, run this command to notify:
openclaw system event --text "Done: [brief description]" --mode now
This is what makes the whole approach work. The task signals completion; your agent doesn't need to guess.
Modes
Mode
Flag
Behavior
auto
--mode auto
Full permissions, runs freely (default)
Design Choices
- Isolated tmux socket (
-L cc) — doesn't interfere with your tmux sessions
cc- prefix on all sessions — easy to list/filter
- Bracketed paste for multi-line prompts — no escaping issues
- JSON output from list/monitor — agent-friendly, fewer tokens to parse
Files
Script
Purpose
scripts/start.sh
Launch CC in tmux with task
scripts/monitor.sh
Lightweight output capture
scripts/send.sh
Send prompts / compact / approve
scripts/list.sh
List active sessions
scripts/stop.sh
Kill sessions
| Mode | Flag | Behavior |
|---|---|---|
| auto | --mode auto |
Full permissions, runs freely (default) |
- Isolated tmux socket (
-L cc) — doesn't interfere with your tmux sessions cc-prefix on all sessions — easy to list/filter- Bracketed paste for multi-line prompts — no escaping issues
- JSON output from list/monitor — agent-friendly, fewer tokens to parse
Files
Script
Purpose
scripts/start.sh
Launch CC in tmux with task
scripts/monitor.sh
Lightweight output capture
scripts/send.sh
Send prompts / compact / approve
scripts/list.sh
List active sessions
scripts/stop.sh
Kill sessions
| Script | Purpose |
|---|---|
scripts/start.sh |
Launch CC in tmux with task |
scripts/monitor.sh |
Lightweight output capture |
scripts/send.sh |
Send prompts / compact / approve |
scripts/list.sh |
List active sessions |
scripts/stop.sh |
Kill sessions |
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。