Skill flagged — suspicious patterns detected

ClawHub Security flagged this skill as suspicious. Review the scan results before using.

token-optimizer-off

v1.0.0

自动压缩会话输入token,智能管理上下文和任务记忆,将token数量从10万+压缩至8,000以内,降低成本。

0· 178·0 current·0 all-time

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for thanksandyou/token-optimizer-off.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "token-optimizer-off" (thanksandyou/token-optimizer-off) from ClawHub.
Skill page: https://clawhub.ai/thanksandyou/token-optimizer-off
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install token-optimizer-off

ClawHub CLI

Package manager switcher

npx clawhub@latest install token-optimizer-off
Security Scan
VirusTotalVirusTotal
Suspicious
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
The name/description describe session-token compression and the shipped scripts implement that: session detection, compression via an LLM, memory indexing, and state management. The skill reads OpenClaw configuration (~/.openclaw/config.json) and memory (~/.openclaw/memory/) which is coherent with its goal to replace full history with summaries. No unrelated services or surprising credentials are requested.
Instruction Scope
SKILL.md and samples instruct the agent to run the provided scripts, read and write files under ~/.openclaw/memory and ~/.openclaw/workspace/skills/token-optimizer, and call compress_session which uses the OpenAI client. This is within scope, but it means the skill will access potentially sensitive files (OpenClaw config may contain API keys) and will write latest-summary.md, backups, and a .session_state.json. The integration example uses subprocess.run with cwd set to a tilde path (not expanded) — a minor implementation detail to fix. Overall the instruction set is explicit and limited to the task, not open-ended.
Install Mechanism
No install spec from external/untrusted URLs is included; files are provided in the skill bundle and requirements.txt only lists the openai library. This is a low-risk install model (instruction/code bundle) with no network download/install step from arbitrary hosts.
Credentials
The skill does not declare required env vars but will read ~/.openclaw/config.json for ai/llm settings and accepts TOKEN_OPTIMIZER_* environment overrides (API key, model, URL). That is proportionate to doing LLM-based compression, but users should be aware the skill will attempt to use/read their OpenClaw config (which may contain credentials). No unrelated credentials or external tokens are requested.
Persistence & Privilege
The skill is not always-enabled and does not request elevated platform privileges. It writes/updates files in the user's OpenClaw memory directory (latest-summary.md, backups, .session_state.json) which is expected behavior for a memory/optimizer skill. It does not modify other skills or global agent settings beyond the memory files it owns.
Assessment
This skill appears to do what it claims: compress conversation history using an LLM and manage per-task memory files. Before installing: (1) review ~/.openclaw/config.json because the scripts will read it and may use its apiKey to call an LLM; ensure you trust that configuration and its permissions; (2) expect the skill to read/write files under ~/.openclaw/memory and create backups and a .session_state.json — back up anything important first; (3) the skill uses the OpenAI client (openai package) and will make network calls to whatever API URL/model you configure; provide an API key only if you trust the code and provider; (4) inspect the provided scripts (they are plain Python and readable) and run them in a safe environment or sandbox before granting access to production data; (5) integration example uses subprocess.run with a path containing '~' (tilde) which may not expand — fix path expansion in your agent code. If you want greater assurance, run the unit tests locally (they mock/require a TOKEN_OPTIMIZER_API_KEY env var) and verify no unexpected network endpoints or logging of secrets occur. If you observe the skill contacting unknown remote endpoints or printing full contents of config/API keys, treat that as suspicious and stop using it.

Like a lobster shell, security has layers — review code before you run it.

latestvk97da5nqa3zz53r3d2r2hzm81x835d6e
178downloads
0stars
1versions
Updated 22h ago
v1.0.0
MIT-0

token-optimizer

将会话输入 token 从 10万+ 压缩至 8,000 以内的完整解决方案。 三层索引 + 会话摘要压缩 + 任务隔离,开箱即用,自动使用 OpenClaw AI 配置。


核心原理

输入token来源分析:
  系统提示    ~2,000  (固定,不可压缩)
  会话历史   ~90,000  ← 主要元凶
  记忆文件    ~5,000  ← 可优化
  当前消息      ~500  (正常)

优化后:
  系统提示    ~2,000
  latest-summary  ~1,500  ← 替代完整历史
  任务记忆    ~1,000  ← 按需加载
  近5轮对话   ~3,000  ← 滑动窗口
  当前消息      ~500
  ─────────────────
  总计        ~8,000  ✅ 压缩92%

快速开始

1. 安装(从 ClawHub)

claw install token-optimizer

2. 无需配置!

自动使用 OpenClaw 的 AI 配置,开箱即用 🎉

3. 初始化记忆目录

cd ~/.openclaw/workspace/skills/token-optimizer
python3 scripts/new_session.py init

重要: 记忆文件存储在 ~/.openclaw/memory/(OpenClaw全局记忆目录),不在技能目录内。

4. 每次新会话开始时

加载顺序(严格按此顺序,总计<8000 token):
① INDEX.md          (本技能的索引,<1KB,必读)
② latest-summary.md (上次会话压缩摘要,<2KB)
③ 任务专属记忆       (按TaskID按需加载,<1KB)
④ 近5轮对话         (滑动窗口,不加载更早历史)

4. 会话结束时压缩

# 预览压缩效果(不保存)
python3 scripts/compress_session.py --dry-run

# 实际压缩并保存
python3 scripts/compress_session.py

三层索引体系

层1:任务层(TaskID)

格式:{类型}-{日期}-{序号}
示例:STOCK-20260227-001 / DEPLOY-20260227-002
TaskID前缀场景加载记忆
STOCK-*股票/行情/交易stock.md
DEPLOY-*部署/安装/运维ops.md
CODE-*编写/修改代码
QUERY-*一次性查询
REMIND-*定时提醒

层2:记忆层(按需加载)

~/.openclaw/memory/          # OpenClaw 全局记忆目录
├── index/
│   ├── INDEX.md            # 必读,<1KB
│   └── RULES.md            # 规则详情
├── sessions/
│   ├── latest-summary.md   # 最新压缩摘要,替代完整历史
│   ├── SESSION-RULES.md    # 会话规范
│   └── {日期}-summary.md   # 历史归档
└── {domain}/               # 领域专属记忆(stock/ops等)
    └── {domain}.md

注意: 记忆文件存储在 ~/.openclaw/memory/,不在技能目录内。详见 MEMORY_STRUCTURE.md

层3:内容层(关键词匹配)

匹配度 ≥ 0.8 才纳入上下文:

  • 股票/行情/持仓/止损 → 加载 stock.md
  • 部署/安装/报错/systemd → 加载 ops.md
  • 天气/新闻/彩票 → 仅加载 INDEX.md

压缩规则

保留(必须)

  • 关键配置参数(API地址、路径、密钥前缀)
  • 已验证的解决方案
  • 错误教训(避免重复踩坑)
  • 服务状态和部署路径

删除(必须)

  • 过程性对话和重复确认
  • 调试输出和临时日志
  • 格式说明和冗余解释
  • 已完成的中间步骤

压缩目标

  • 单次压缩率 ≥ 60%
  • latest-summary.md ≤ 2KB(约1500 token)

自动触发机制

session_guard.py 会在每次对话时自动检查 token 使用情况:

条件触发动作
上下文 < 4万 token正常,无操作
上下文 4~7万 token自动压缩,静默执行
上下文 > 7万 token自动压缩 + 提示用户新开会话
会话轮数 > 25 轮自动压缩 + 提示用户新开会话

使用方式:

# 每次对话前调用
python3 scripts/session_guard.py check \
  --message "用户消息" \
  --context-size 当前token数

# 新会话开始后重置状态
python3 scripts/session_guard.py reset

Agent 会自动执行压缩,无需用户手动干预 ✅


脚本说明

脚本功能
scripts/session_guard.py⭐ 核心:自动判断是否需要压缩/新开会话
scripts/compress_session.py压缩当前会话摘要,更新 latest-summary.md
scripts/new_session.py初始化新会话,输出本次应加载的记忆清单
scripts/status.py显示当前token使用估算和记忆文件大小

集成到 OpenClaw Agent

在你的 Agent 中集成:

import subprocess
import json

def check_session_health(user_message: str, context_size: int):
    """检查会话健康度"""
    result = subprocess.run(
        ['python3', 'scripts/session_guard.py', 'check',
         '--message', user_message,
         '--context-size', str(context_size)],
        capture_output=True,
        text=True,
        cwd='~/.openclaw/workspace/skills/token-optimizer'
    )
    
    # 解析输出
    if 'compress' in result.stdout.lower():
        # 执行压缩
        subprocess.run(
            ['python3', 'scripts/compress_session.py'],
            cwd='~/.openclaw/workspace/skills/token-optimizer'
        )
        return 'compressed'
    elif 'new_session' in result.stdout.lower():
        return 'new_session_needed'
    else:
        return 'continue'

# 在每次对话前调用
action = check_session_health(user_message, current_token_count)
if action == 'new_session_needed':
    print("💡 建议新开会话以获得最佳体验")

高级配置(可选)

虽然默认使用 OpenClaw 配置,但你也可以通过环境变量自定义:

# 自定义阈值
export TOKEN_OPTIMIZER_WARN_TOKENS="40000"
export TOKEN_OPTIMIZER_CRITICAL_TOKENS="70000"
export TOKEN_OPTIMIZER_MAX_ROUNDS="25"

# 自定义任务关键词
export TOKEN_OPTIMIZER_TASK_KEYWORDS='{"MYTASK": ["关键词1", "关键词2"]}'

# 覆盖 AI 配置(高级用户)
export TOKEN_OPTIMIZER_API_KEY="your-key"
export TOKEN_OPTIMIZER_MODEL="gpt-4"

Token节省效果

场景优化前优化后节省
长会话(50轮)~100,000~8,00092%
中等会话(20轮)~40,000~6,00085%
新会话~5,000~4,00020%

为什么选择 token-optimizer?

开箱即用 - 自动使用 OpenClaw AI 配置,无需额外配置
智能判断 - 自动检测何时需要压缩或新开会话
任务隔离 - 避免不同任务的上下文污染
高效压缩 - 92% token 节省,显著降低成本
易于集成 - 简单的 Python 脚本,易于集成到任何 Agent


许可证

MIT License - 详见 LICENSE


贡献

欢迎贡献!请访问 GitHub

Comments

Loading comments...