💸

OpenClaw 智能降本专家

OpenClaw Token Optimizer · v3.2.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
效率 安全 S+ 级 榜单 #39 作者 asif2bd 公开目录收录
11.9k 下载 29 安装 27.7k 收藏 159 浏览

简介

专为 OpenClaw 2026.6.x 设计的本地 Token 成本控制工具包,通过懒加载上下文、智能模型路由、心跳调度优化实现 50-80% 成本节约,经 Oracle 安全审计认证。

原始描述

OpenClaw Token Optimizer v3.2.0 — practical cost-control toolkit for OpenClaw agents. Lazy context loading, Sonnet/Opus-aware routing, heartbeat scheduling,...

通过你的 Agent 添加

安装目录:openclaw-token-optimizer-15463/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

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

或者手动安装

Claude Code~/.claude/skills/openclaw-token-optimizer-15463/
Codex CLI~/.codex/skills/openclaw-token-optimizer-15463/
DeepSeek Harness~/.agents/skills/openclaw-token-optimizer-15463/

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

中文使用说明 来自收录源

核心用法

OpenClaw Token Optimizer 是一套面向 OpenClaw 2026.6.x 智能体的成本管控工具包,通过 Python 脚本实现五大优化维度:

  1. 懒加载上下文(context_optimizer.py):根据提示词智能推荐最小上下文组合,避免每次会话加载全部文档
  2. 模型路由(model_router.py):将常规任务导向 Sonnet,仅复杂推理触发 Opus,降低模型调用成本
  3. 心跳调度(heartbeat_optimizer.py):基于缓存 TTL 和静默时段优化检查频率,避免无效执行
  4. 本地预算追踪(token_tracker.py):运行前预警,防止费用失控
  5. 便利封装(optimize.sh):统一入口简化日常操作

典型工作流

# 获取上下文建议
python3 scripts/context_optimizer.py recommend "写部署清单"

# 本地模型路由决策
python3 scripts/model_router.py "调试这个错误"

# 预览并安装优化心跳
./scripts/optimize.sh heartbeat
./scripts/optimize.sh heartbeat install  # 带自动备份

显著优点

  • 成本削减显著:官方预期节省 50%-80%,上下文优化通常贡献最大收益
  • 安全架构极致:零第三方依赖、零网络请求、零危险函数(无 eval/exec/subprocess),纯 Python 标准库实现
  • 审计背书充分:Oracle (Matrix Zion) 2026-06-22 安全审计 + CLS S+ 级认证(满分 100)
  • 写入保护严谨:文件输出需显式 --output 参数,心跳安装自动备份原文件
  • 开源双许可:MIT/Apache 2.0,GitHub 与 ClawHub 双平台发布
  • 多租户友好:xCloud、MissionDeck 等托管部署中,节省的 Token 可跨用户复利

潜在局限

  • 环境绑定:专为 OpenClaw 2026.6.x 生态设计,其他 Agent 框架需适配
  • 本地状态局限:预算追踪依赖本地 JSON,无法同步多设备消费视图
  • 路由建议非强制:model_router.py 仅返回建议字符串,实际 API 调用仍由上层决策
  • Python 3 依赖:需预装 Python3,无独立二进制分发
  • 维护者单一:核心开发者为个人开发者 Asif2BD,虽活跃但非机构背书

适合人群

  • 运行多智能体 OpenClaw 工作空间、上下文文件繁重的团队
  • 需为心跳/定时任务优化调度频率的自动化场景
  • 希望将 Opus 保留给复杂推理、Sonnet 处理日常工作的成本敏感用户
  • 对供应链安全要求极高、需通过企业安全审计的合规环境

常规风险

风险类型 评估 说明
供应链攻击 🟢 极低 零依赖,标准库-only,SHA256 校验机制完整
数据外泄 🟢 极低 无网络请求,数据仅本地存储,GDPR/CCPA 合规
权限滥用 🟢 低 写入操作显式化,默认 stdout 输出,有备份机制
版本漂移 🟡 中低 建议定期 openclaw skills update 保持安全更新
误配置风险 🟡 中低 需理解 OpenClaw 上下文机制才能发挥最大效益

认证结论:CLS S+ 级(满分),威胁情报维度 95/100 仅因 T2 来源评级(个人开发者而非机构),实际安全实现无瑕疵。

技能正文


name: token-optimizer description: OpenClaw Token Optimizer v3.2.0 — practical cost-control toolkit for OpenClaw agents. Lazy context loading, Sonnet/Opus-aware routing, heartbeat scheduling, local token budgets, cache-TTL guidance, and security-audit-safe command behavior for current OpenClaw 2026.6.x installs. version: 3.2.0 homepage: https://github.com/Asif2BD/OpenClaw-Token-Optimizer source: https://github.com/Asif2BD/OpenClaw-Token-Optimizer author: Asif2BD metadata: { "openclaw": { "emoji": "💸", "requires": { "bins": ["python3"] }, "install": [ { "id": "github", "kind": "link", "label": "GitHub", "url": "https://github.com/Asif2BD/OpenClaw-Token-Optimizer", }, { "id": "security", "kind": "link", "label": "Security Notes", "url": "https://github.com/Asif2BD/OpenClaw-Token-Optimizer/blob/main/SECURITY.md", }, ], }, } security: verified: true auditor: Oracle (Matrix Zion) audit_date: 2026-06-22 scripts_no_network: true scripts_no_code_execution: true scripts_no_subprocess: true scripts_data_local_only: true explicit_workspace_writes: true default_commands_no_overwrite: true reference_files_describe_external_services: true optimize_sh_is_convenience_wrapper: true optimize_sh_only_calls_bundled_python_scripts: true

OpenClaw Token Optimizer v3.2.0

Version License

Built for current OpenClaw 2026.6.x agents by Asif2BD · GitHub · Security Notes

Security notice: local-only optimization toolkit. The Python scripts make no network requests and do not execute dynamic code. Commands that write files are explicit, documented, and backup-safe.


Install

openclaw skills install @asif2bd/openclaw-token-optimizer

What's New in v3.2

Modern ClawHub Card

The skill card now leads with a clearer product promise, current OpenClaw compatibility, security posture, and practical commands instead of the older long-form v3.0 copy.

Current OpenClaw Model Routing

Routine Anthropic work maps to anthropic/claude-sonnet-4-5; only explicitly complex reasoning routes to anthropic/claude-opus-4-5.

Audit-Safe Writes

  • context_optimizer.py generate-agents prints to stdout by default.
  • Writing an optimized AGENTS.md requires --output or --workspace-output.
  • ./scripts/optimize.sh heartbeat previews only by default.
  • ./scripts/optimize.sh heartbeat install writes HEARTBEAT.md only after backing up an existing file.

What It Optimizes

Context Loading

Stop loading every workspace file into every session. Recommend only the context needed for the current prompt.

python3 scripts/context_optimizer.py recommend "hi"

Typical result: SOUL.md + IDENTITY.md only for a greeting.

Model Routing

Keep standard work on Sonnet and reserve Opus for deep reasoning.

python3 scripts/model_router.py "thanks!"
python3 scripts/model_router.py "design a multi-agent architecture"

Heartbeat Scheduling

Run only checks that are due, respect quiet hours, and align heartbeat timing with prompt-cache TTL.

python3 scripts/heartbeat_optimizer.py plan
python3 scripts/heartbeat_optimizer.py cache-ttl

Token Budgets

Track local daily budget state and surface warnings before runaway spend.

python3 scripts/token_tracker.py check

Quick Start

1. Find the minimum context for a request

python3 scripts/context_optimizer.py recommend "write a deployment checklist"

2. Preview an optimized AGENTS.md

python3 scripts/context_optimizer.py generate-agents

Save a review copy only when you explicitly ask for it:

python3 scripts/context_optimizer.py generate-agents --output ~/.openclaw/workspace/AGENTS.md.optimized

3. Preview heartbeat installation

./scripts/optimize.sh heartbeat

Install with backup protection:

./scripts/optimize.sh heartbeat install

4. Route a task

python3 scripts/model_router.py "debug this error"

Savings Profile

Area Typical waste Optimizer approach
Startup context Loading docs, memory, tools, and old logs every turn Lazy-load only what the prompt needs
Routine model use Opus used for quick replies or simple checks Sonnet for routine work, Opus for complex reasoning
Heartbeats Every check runs on every heartbeat Due-check planner + quiet hours
Cache TTL Idle sessions trigger expensive cache rewrites 55-minute heartbeat guidance for 1-hour cache TTL
Budget control Spend discovered after the fact Local budget checks before expensive work

Expected savings: 50-80% in context-heavy OpenClaw workspaces, with context optimization usually delivering the biggest win.


Files

Scripts

  • scripts/context_optimizer.py — prompt classification and context bundle recommendations
  • scripts/model_router.py — Sonnet/Opus-aware task routing
  • scripts/heartbeat_optimizer.py — due-check planning, quiet hours, cache-TTL interval guidance
  • scripts/token_tracker.py — local budget tracking
  • scripts/optimize.sh — convenience wrapper around bundled scripts

Assets

  • assets/HEARTBEAT.template.md — backup-safe heartbeat template
  • assets/cronjob-model-guide.md — scheduled-task model guidance
  • assets/config-patches.json — native and optional config examples

References

  • references/PROVIDERS.md — optional external-provider strategy notes
  • SECURITY.md — complete security and data-handling breakdown

Security Posture

  • No network calls in executable scripts
  • No eval, dynamic imports, shell command execution, or downloader behavior
  • Local JSON state only under the OpenClaw workspace memory directory
  • Workspace writes require explicit commands
  • Existing HEARTBEAT.md is backed up before replacement
  • .clawhubsafe covers every published file with SHA256 hashes

Verify locally:

sha256sum -c .clawhubsafe

Native OpenClaw Diagnostics

Use OpenClaw's built-in context and usage commands alongside this skill:

/context list
/context detail
/usage tokens
/usage cost

Use the built-ins to see where tokens are going, then use Token Optimizer to reduce the recurring waste.


Best Fit

  • Multi-agent OpenClaw workspaces with large instruction files
  • Agents that run heartbeats or scheduled checks
  • Teams trying to keep Opus for hard work instead of routine work
  • xCloud, MissionDeck, or other hosted OpenClaw deployments where every saved prompt token compounds across users

More by Asif2BD

openclaw skills install @asif2bd/jarvis-mission-control
openclaw skills search asif2bd

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

标签

cost-optimizationtoken-managementlocal-onlysecurity-auditedopenclawcontext-optimizationmodel-routing

同类 Skill