PRECC Token Saver
PRECC (Predictive Error Correction) intercepts every shell command before it runs.
In under 3ms it:
- - Fixes wrong-directory errors — detects the correct project root and prepends INLINECODE0
- Compresses CLI output — rewrites commands through RTK (60–90% smaller output)
- Applies learned skills — uses patterns mined from past sessions to prevent repeated failures
- Translates git→jj — auto-converts git commands in Jujutsu repos (saves ~40 tokens per
git add)
Measured results (29 real sessions, 5,384 bash calls):
- - 34% cost saving ($296 saved from $878 baseline)
- 98% of failures prevented (352/358)
- 2.93ms average hook latency
How it works in OpenClaw
Note: OpenClaw does not yet have a native PreToolUse hook (unlike Claude
Code). This skill works via prompt-level instruction: the SKILL.md is loaded
into the agent's context and the agent is instructed to manually pipe every shell
command through precc-hook before executing it. Interception is LLM-enforced,
not OS-level. A native hook equivalent is tracked in
openclaw/openclaw#7597.
When PRECC Token Saver is active, the agent follows this pattern for every shell
command it wants to run:
- 1. Construct the JSON payload for INLINECODE4
- Pipe it through
precc-hook on stdin - Read the (possibly rewritten) command from stdout
- Execute the rewritten command instead of the original
CODEBLOCK0
Setup
CODEBLOCK1
Commands
Once the skill is loaded, you can address the agent directly:
- -
@precc report — show token savings and command statistics - INLINECODE7 — list active correction skills
- INLINECODE8 — update PRECC binaries to the latest release
- INLINECODE9 — show dollar-value savings estimate
Skill behaviour
This skill is loaded as a system-level instruction into the agent's context.
The agent (not the platform) is responsible for enforcing the hook pattern.
The agent is instructed to:
- 1. Always route shell/bash tool calls through
precc-hook by constructing the
hook JSON payload and parsing the response before execution.
- 2. On session start, run
precc init if the databases are absent. - On session end, optionally run
precc report and summarise savings. - Never skip the hook even for simple commands — the latency is <3ms and the
hook is fail-open (any error → original command is used unchanged).
Hook invocation pattern
CODEBLOCK2
Parse the JSON response:
- - If
.hookSpecificOutput.updatedInput.command is non-empty → use it - Otherwise → use the original command unchanged
Advanced: savings report
CODEBLOCK3
License
MIT — https://github.com/yijunyu/precc-cc
PRECC Token Saver
PRECC(预测性错误纠正)会在每个 shell 命令执行前进行拦截。
在 3 毫秒内,它可以:
- - 修复目录错误 — 检测正确的项目根目录,并在命令前添加 cd /correct/path &&
- 压缩 CLI 输出 — 通过 RTK 重写命令(输出减少 60–90%)
- 应用已学技能 — 利用从历史会话中挖掘的模式,防止重复失败
- 将 git 转换为 jj — 在 Jujutsu 仓库中自动转换 git 命令(每次 git add 节省约 40 个 token)
实测结果(29 个真实会话,5,384 次 bash 调用):
- - 节省 34% 成本(从 878 美元基线节省 296 美元)
- 98% 的失败被阻止(352/358)
- 平均钩子延迟 2.93 毫秒
在 OpenClaw 中的工作原理
注意: OpenClaw 尚未原生支持 PreToolUse 钩子(与 Claude Code 不同)。
此技能通过提示级别指令工作:SKILL.md 被加载到代理的上下文中,代理被指示在执行每个 shell 命令前手动通过 precc-hook 管道处理。拦截由 LLM 强制执行,而非操作系统级别。原生钩子的等效功能正在跟踪中,详见
openclaw/openclaw#7597。
当 PRECC Token Saver 激活时,代理对每个要执行的 shell 命令遵循以下模式:
- 1. 为 precc-hook 构建 JSON 负载
- 通过标准输入将其管道传递给 precc-hook
- 从标准输出读取(可能被重写的)命令
- 执行重写后的命令,而非原始命令
代理想要执行:cargo build
↓
precc-hook 接收: {tool_input: {command: cargo build}}
precc-hook 输出: {hookSpecificOutput: {updatedInput: {command: cd /path/to/project && rtk cargo build}}}
↓
代理执行: cd /path/to/project && rtk cargo build
安装
bash
安装 PRECC
curl -fsSL https://raw.githubusercontent.com/yijunyu/precc-cc/main/scripts/install.sh | bash
初始化(一次性)
precc init
挖掘现有会话历史(可选)
precc ingest --all
命令
加载技能后,您可以直接与代理对话:
- - @precc report — 显示 token 节省和命令统计
- @precc skills list — 列出活跃的纠正技能
- @precc update — 将 PRECC 二进制文件更新到最新版本
- @precc savings — 显示以美元计价的节省估算
技能行为
此技能作为系统级指令加载到代理的上下文中。
代理(而非平台)负责强制执行钩子模式。
代理被指示:
- 1. 始终通过 precc-hook 路由 shell/bash 工具调用,即在执行前构建钩子 JSON 负载并解析响应。
- 在会话开始时,如果数据库不存在,则运行 precc init。
- 在会话结束时,可选运行 precc report 并总结节省情况。
- 绝不跳过钩子,即使对于简单命令也是如此——延迟小于 3 毫秒,且钩子为故障开放模式(任何错误 → 使用原始命令不变)。
钩子调用模式
bash
通过 precc-hook 包装任何命令:
echo {tool
input:{command:YOURCOMMAND_HERE}} | precc-hook
解析 JSON 响应:
- - 如果 .hookSpecificOutput.updatedInput.command 非空 → 使用它
- 否则 → 使用原始命令不变
高级:节省报告
bash
precc report # 完整分析仪表板
precc savings # 美元价值明细
precc skills list # 活跃技能
precc skills show # 查看单个技能的详细信息
许可证
MIT — https://github.com/yijunyu/precc-cc