简介
什么是PRECC?
PRECC (Claude Code 预测性错误纠正) 是一个Rust工具,通过官方的PreToolUse钩子机制拦截Claude Code的bash命令。它在错误发生之前修复它们,节省token并消除重试循环。
对社区用户免费。
问题
Claude Code在可预防的错误上浪费大量token:
- 目录错误 – 在没有
Cargo.toml的父目录中运行cargo build,然后在读取错误后重试。 - 重试循环 – 失败的命令产生冗长的输出,Claude读取、推理并重试。每个循环消耗数百个token。
- 冗长输出 –
find或ls -R等命令输出数千行,Claude必须处理这些内容。
四大支柱
上下文修复 (cd-prepend)
检测到 cargo build 或 npm test 等命令在错误的目录中运行时,在执行前添加 cd /正确/路径 &&。
GDB调试
检测附加GDB进行更深入调试的机会,提供结构化的调试信息而不是原始的核心转储。
会话挖掘
挖掘Claude Code会话日志中的失败-修复对。当同样的错误再次发生时,PRECC已经知道修复方法并自动应用。
自动化技能
内置和挖掘技能库,匹配命令模式并重写它们。技能定义为TOML文件或SQLite行,便于检查、编辑和共享。
工作原理(30秒版本)
- Claude Code即将运行一个bash命令。
- PreToolUse钩子将命令作为JSON通过stdin发送给
precc-hook。 precc-hook在3毫秒内通过管道(技能、目录修正、压缩)处理命令。- 修正后的命令作为JSON通过stdout返回。
- Claude Code执行修正后的命令。
琐碎错误被合并;重写原因随钩子响应一起返回,因此每次修正都可审计,而非悄然发生。
安全边界
PRECC仅在语义等价可证明保留或用户可验证时才进行重写。破坏性命令(rm、git push --force、git reset --hard)即使匹配技能也绝不重写。每次变换必须是有界的——重写后的命令仍须包含原始命令的核心token。无界重写会被自动还原。每次应用的重写都会被记录并显示,以便您审计、禁用或撤销。
自适应压缩
如果命令在压缩后失败,PRECC会自动在重试时跳过压缩,以便Claude获得完整的未压缩输出来调试。
实时使用统计
当前版本 –:
| 指标 | 值 |
|---|---|
| 节省的token | – |
| 节省比率 | –% |
| 钩子延迟 | – ms (p50) |
| 独立用户 | – |
| crates.io downloads | – |
crates.io downloads count CI, docs.rs and mirror traffic — they are not a measure of unique users.
各版本节省情况
这些数字会从匿名遥测数据自动更新。
链接
- GitHub: https://github.com/peri-a-i/precc-cc
- 网站: https://peria.ai
- 文档: https://precc.cc
安装
快速安装 (Linux / macOS)
curl -fsSL https://peria.ai/install.sh | bash
这会下载适用于您平台的最新版本二进制文件,验证SHA256校验和,并将其放置在 ~/.local/bin/ 中。
安装后,初始化PRECC:
precc init
precc init 在Claude Code中注册PreToolUse钩子,创建数据目录,并初始化技能数据库。
安装选项
SHA256验证
默认情况下,安装程序会根据已发布的SHA256校验和验证二进制文件。要跳过验证(不推荐):
curl -fsSL https://peria.ai/install.sh | bash -s -- --no-verify
自定义安装前缀
安装到自定义位置:
curl -fsSL https://peria.ai/install.sh | bash -s -- --prefix /opt/precc
OpenCLI (–opencli) — WebFetch token savings
PRECC can also install OpenCLI, a third-party Node.js tool that turns ~148 websites (HackerNews, Reddit, arxiv, bilibili, zhihu, x.com, …) into structured-output commands. When installed, PRECC’s two built-in webfetch-opencli-* skills auto-rewrite raw curl/wget calls into the corresponding opencli <site> command for 5–50× smaller output.
precc init --opencli
This runs npm install -g @jackwener/opencli (requires Node.js 20+) and prints the URL for OpenCLI’s optional Chrome extension. The extension is only needed to reuse logged-in cookies on private pages; public sources work without it.
Skipping --opencli keeps PRECC fully self-contained — the auto-rewrite skill inlines a command -v opencli check that falls back to the original command when OpenCLI isn’t installed, so the skill is safe to ship default-on.
The Chrome extension requests broad permissions (debugger, <all_urls>, cookies). Operators should review them before installing it; --opencli only handles the npm package, not the extension.
附加工具 (–extras)
PRECC附带可选的附加工具。使用 --extras 安装它们:
curl -fsSL https://peria.ai/install.sh | bash -s -- --extras
这将安装:
| 工具 | 用途 |
|---|---|
| RTK | 命令重写工具包 |
| lean-ctx | CLAUDE.md和提示文件的上下文压缩 |
| nushell | 用于高级管道的结构化Shell |
| cocoindex-code | 代码索引以加快上下文解析 |
Windows (PowerShell)
irm https://peria.ai/install.ps1 | iex
然后初始化:
precc init
手动安装
- 从 GitHub Releases 下载适用于您平台的发布二进制文件。
- 根据版本中的
.sha256文件验证SHA256校验和。 - 将二进制文件放置在
PATH中的目录中(例如~/.local/bin/)。 - 运行
precc init。
更新
precc update
强制更新到特定版本:
precc update --force --version 0.3.0
启用自动更新:
precc update --auto
在 OpenClaw / ClawHub 下安装
PRECC 在 plugins/openclaw/openclaw.plugin.json 提供插件清单(id 为 precc-token-saver)。每当发布公开版本时,GitHub Actions 工作流 clawhub-publish.yml 会将技能包推送到 ClawHub 注册表,因此最终用户可以通过 ClawHub CLI 而不是 curl 安装器来安装 PRECC:
# ClawHub CLI
clawhub install precc
# Or pin the plugin manifest (id: precc-token-saver) via OpenClaw's
# plugin marketplace UI or its CLI equivalent.
节省如何在 OpenClaw 下呈现
在 Claude Code 下可用的每一个 PRECC 报告界面在 OpenClaw 下同样可用——precc savings、precc savings --all、本地化的状态行(设置 PRECC_LANG=zh,状态行会以你的语言显示)以及本地改写审计日志,都从你机器上同一组 SQLCipher 数据库读取数据。docs/symposium-plan/openclaw-savings-reporting.md 中的另一份规范描述了未来在每个钩子响应中加入结构化的 preccSavings 字段,以及在默认阈值 $0.05 时发送一行会话结束通知;这一部分尚未发布。
验证安装
$ precc --version
precc 0.3.0
$ precc savings
Session savings: 0 tokens (no commands intercepted yet)
如果找不到 precc,请确保 ~/.local/bin 在您的 PATH 中。
快速入门
5分钟内启动PRECC。
步骤1:安装
curl -fsSL https://peria.ai/install.sh | bash
步骤2:初始化
$ precc init
[precc] Hook registered with Claude Code
[precc] Created ~/.local/share/precc/
[precc] Initialized heuristics.db with 8 built-in skills
[precc] Ready.
步骤3:验证Hook已激活
$ precc skills list
# Name Type Triggers
1 cargo-wrong-dir built-in cargo build/test/clippy outside Rust project
2 git-wrong-dir built-in git * outside a repo
3 go-wrong-dir built-in go build/test outside Go module
4 make-wrong-dir built-in make without Makefile in cwd
5 npm-wrong-dir built-in npm/npx/pnpm/yarn outside Node project
6 python-wrong-dir built-in python/pytest/pip outside Python project
7 jj-translate built-in git * in jj-colocated repo
8 asciinema-gif built-in asciinema rec
步骤4:正常使用Claude Code
打开Claude Code并照常工作。PRECC在后台静默运行。当Claude发出一个会失败的命令时,PRECC会在执行前修正它。
示例:错误目录的Cargo Build
假设你的项目在 ~/projects/myapp/,Claude发出:
cargo build
从 ~/projects/(高了一级,那里没有 Cargo.toml)。
没有PRECC: Claude收到错误 could not find Cargo.toml in /home/user/projects or any parent directory,读取、推理,然后用 cd myapp && cargo build 重试。代价:浪费约2,000个token。
使用PRECC: Hook检测到缺失的 Cargo.toml,在 myapp/ 中找到它,并将命令重写为:
cd /home/user/projects/myapp && cargo build
Claude永远看不到错误。零token浪费。
步骤5:查看节省情况
会话结束后,查看PRECC节省了多少token:
$ precc savings
Session Token Savings
=====================
Total estimated savings: 4,312 tokens
Breakdown:
Pillar 1 (cd prepends): 2,104 tokens (3 corrections)
Pillar 4 (skill activations): 980 tokens (2 activations)
RTK rewrites: 1,228 tokens (5 rewrites)
后续步骤
许可证
PRECC提供两个层级:Community(免费)和Pro。
Community层(免费)
Community层包括:
- 所有内置技能(错误目录修正、jj翻译等)
- 支持完整Pillar 1和Pillar 4的Hook管道
- 基本的
precc savings摘要 - 使用
precc ingest进行会话挖掘 - 无限本地使用
Pro层
Pro解锁额外功能:
- 详细节省分析 –
precc savings --all逐命令分析 - GIF录制 –
precc gif用于创建终端动画GIF - IP地理围栏合规 – 适用于受监管的环境
- 电子邮件报告 –
precc mail report发送分析报告 - GitHub Actions分析 –
precc gha用于调试失败的工作流 - 上下文压缩 –
precc compress用于CLAUDE.md优化 - 优先支持
激活许可证
$ precc license activate XXXX-XXXX-XXXX-XXXX --email you@example.com
[precc] License activated for you@example.com
[precc] Plan: Pro
[precc] Expires: 2027-04-03
检查许可证状态
$ precc license status
License: Pro
Email: you@example.com
Expires: 2027-04-03
Status: Active
GitHub Sponsors激活
如果您通过GitHub Sponsors赞助PRECC,您的许可证将通过您的GitHub邮箱自动激活。无需密钥——只需确保您的赞助者邮箱匹配:
$ precc license status
License: Pro (GitHub Sponsors)
Email: you@example.com
Status: Active (auto-renewed)
设备指纹
每个许可证都绑定到设备指纹。使用以下命令查看:
$ precc license fingerprint
Fingerprint: a1b2c3d4e5f6...
如果需要将许可证转移到新机器,请先停用:
precc license deactivate
然后在新机器上激活。
许可证过期?
当Pro许可证到期时,PRECC会恢复到Community层。所有内置技能和核心功能继续工作。只有Pro特有功能变为不可用。详情请参阅FAQ。
钩子管道
precc-hook 二进制文件是PRECC的核心。它位于Claude Code和shell之间,在5毫秒内处理每个bash命令。
Claude Code如何调用钩子
Claude Code支持PreToolUse钩子——可以在执行前检查和修改工具输入的外部程序。当Claude即将运行bash命令时,它通过stdin将JSON发送给 precc-hook 并从stdout读取响应。
管道阶段
Claude Code
|
v
+---------------------------+
| 1. Parse JSON stdin | Read the command from Claude Code
+---------------------------+
|
v
+---------------------------+
| 2. Skill matching | Query heuristics.db for matching skills (Pillar 4)
+---------------------------+
|
v
+---------------------------+
| 3. Directory correction | Resolve correct working directory (Pillar 1)
+---------------------------+
|
v
+---------------------------+
| 4. GDB check | Detect debug opportunities (Pillar 2)
+---------------------------+
|
v
+---------------------------+
| 5. RTK rewriting | Apply command rewrites for token savings
+---------------------------+
|
v
+---------------------------+
| 6. Emit JSON stdout | Return modified command to Claude Code
+---------------------------+
|
v
Shell executes corrected command
示例:JSON输入和输出
输入(来自Claude Code)
{
"tool_input": {
"command": "cargo build"
}
}
PRECC检测到当前目录没有 Cargo.toml,但 ./myapp/Cargo.toml 存在。
输出(到Claude Code)
{
"hookSpecificOutput": {
"updatedInput": {
"command": "cd /home/user/projects/myapp && cargo build"
}
}
}
如果不需要修改,updatedInput.command 为空,Claude Code使用原始命令。
阶段详情
阶段1:解析JSON
从stdin读取完整的JSON对象。提取 tool_input.command。如果解析失败,钩子立即退出,Claude Code使用原始命令(fail-open设计)。
阶段2:技能匹配
查询SQLite启发式数据库,寻找触发模式与命令匹配的技能。技能按优先级顺序检查。内置TOML技能和挖掘的技能都会被评估。
阶段3:目录修正
对于构建命令(cargo、go、make、npm、python 等),检查预期的项目文件是否存在于当前目录中。如果不存在,扫描附近目录寻找最近匹配并添加 cd <dir> && 前缀。
目录扫描使用缓存的文件系统索引,TTL为5秒,以保持高速。
阶段4:GDB检查
如果命令可能产生崩溃(例如运行调试二进制文件),PRECC可以建议或注入GDB包装器来捕获结构化的调试输出,而不是原始崩溃日志。
阶段5:RTK重写
应用RTK(重写工具包)规则,缩短冗长命令、抑制嘈杂输出或重构命令以提高token效率。
阶段6:输出JSON
将修改后的命令序列化回JSON并写入stdout。如果没有更改,输出信号Claude Code使用原始命令。
性能
整个管道在5毫秒(p99)内完成。关键优化:
- SQLite使用WAL模式实现无锁并发读取
- 预编译的正则表达式模式用于技能匹配
- 缓存的文件系统扫描(5秒TTL)
- 热路径中无网络调用
- Fail-open:任何错误都回退到原始命令
手动测试钩子
你可以直接调用钩子:
$ echo '{"tool_input":{"command":"cargo build"}}' | precc-hook
{"hookSpecificOutput":{"updatedInput":{"command":"cd /home/user/myapp && cargo build"}}}
技能
技能是PRECC用来检测和纠正命令的模式匹配规则。它们可以是内置的(作为TOML文件分发)或从会话日志中挖掘的。
内置技能
| 技能 | 触发条件 | 动作 |
|---|---|---|
cargo-wrong-dir | 在Rust项目外运行 cargo build/test/clippy | 在命令前添加 cd 到最近的 Cargo.toml 目录 |
git-wrong-dir | 在git仓库外运行 git * | 在命令前添加 cd 到最近的 .git 目录 |
go-wrong-dir | 在Go模块外运行 go build/test | 在命令前添加 cd 到最近的 go.mod 目录 |
make-wrong-dir | 当前目录没有Makefile时运行 make | 在命令前添加 cd 到最近的Makefile目录 |
npm-wrong-dir | 在Node项目外运行 npm/npx/pnpm/yarn | 在命令前添加 cd 到最近的 package.json 目录 |
python-wrong-dir | 在Python项目外运行 python/pytest/pip | 在命令前添加 cd 到最近的Python项目 |
jj-translate | 在jj共存仓库中运行 git * | 重写为等效的 jj 命令 |
asciinema-gif | asciinema rec | 重写为 precc gif |
列出技能
$ precc skills list
# Name Type Triggers
1 cargo-wrong-dir built-in cargo build/test/clippy outside Rust project
2 git-wrong-dir built-in git * outside a repo
3 go-wrong-dir built-in go build/test outside Go module
4 make-wrong-dir built-in make without Makefile in cwd
5 npm-wrong-dir built-in npm/npx/pnpm/yarn outside Node project
6 python-wrong-dir built-in python/pytest/pip outside Python project
7 jj-translate built-in git * in jj-colocated repo
8 asciinema-gif built-in asciinema rec
9 fix-pytest-path mined pytest with wrong test path
显示技能详情
$ precc skills show cargo-wrong-dir
Name: cargo-wrong-dir
Type: built-in
Source: skills/builtin/cargo-wrong-dir.toml
Description: Detects cargo commands run outside a Rust project and prepends
cd to the directory containing the nearest Cargo.toml.
Trigger: ^cargo\s+(build|test|clippy|run|check|bench|doc)
Action: prepend_cd
Marker: Cargo.toml
Activations: 12
将技能导出为TOML
$ precc skills export cargo-wrong-dir
[skill]
name = "cargo-wrong-dir"
description = "Prepend cd for cargo commands outside a Rust project"
trigger = "^cargo\\s+(build|test|clippy|run|check|bench|doc)"
action = "prepend_cd"
marker = "Cargo.toml"
priority = 10
编辑技能
$ precc skills edit cargo-wrong-dir
这将在您的 $EDITOR 中打开技能定义。保存后,技能会自动重新加载。
Advise 命令
precc skills advise 分析您最近的会话,并根据重复模式建议新技能:
$ precc skills advise
Analyzed 47 commands from the last session.
Suggested skills:
1. docker-wrong-dir: You ran `docker compose up` outside the project root 3 times.
Suggested trigger: ^docker\s+compose
Suggested marker: docker-compose.yml
2. terraform-wrong-dir: You ran `terraform plan` outside the infra directory 2 times.
Suggested trigger: ^terraform\s+(plan|apply|init)
Suggested marker: main.tf
Accept suggestion [1/2/skip]?
聚类技能
$ precc skills cluster
将相似的挖掘技能分组,帮助识别冗余或重叠的模式。
挖掘技能与内置技能
内置技能随PRECC一起分发,定义在 skills/builtin/*.toml 中。它们涵盖了最常见的目录错误。
挖掘技能由 precc ingest 或 precc-learner 守护进程从您的会话日志创建。它们存储在 ~/.local/share/precc/heuristics.db 中,特定于您的工作流程。详情请参阅挖掘。
节省
PRECC追踪每次拦截的估计token节省。使用 precc savings 查看PRECC阻止了多少浪费。
快速摘要
$ precc savings
Session Token Savings
=====================
Total estimated savings: <span data-stat="session_tokens_saved">8,741</span> tokens
Breakdown:
Pillar 1 (cd prepends): <span data-stat="session_p1_tokens">3,204</span> tokens (<span data-stat="session_p1_count">6</span> corrections)
Pillar 4 (skill activations): <span data-stat="session_p4_tokens">1,560</span> tokens (<span data-stat="session_p4_count">4</span> activations)
RTK rewrites: <span data-stat="session_rtk_tokens">2,749</span> tokens (<span data-stat="session_rtk_count">11</span> rewrites)
Lean-ctx wraps: <span data-stat="session_lean_tokens">1,228</span> tokens (<span data-stat="session_lean_count">2</span> wraps)
详细分类(Pro)
$ precc savings --all
Session Token Savings (Detailed)
================================
Total estimated savings: <span data-stat="session_tokens_saved">8,741</span> tokens
Command-by-command:
# Time Command Saving Source
1 09:12 cargo build 534 tk cd prepend (cargo-wrong-dir)
2 09:14 cargo test 534 tk cd prepend (cargo-wrong-dir)
3 09:15 git status 412 tk cd prepend (git-wrong-dir)
4 09:18 npm install 824 tk cd prepend (npm-wrong-dir)
5 09:22 find . -name "*.rs" 387 tk RTK rewrite (output truncation)
6 09:25 cat src/main.rs 249 tk RTK rewrite (lean-ctx wrap)
7 09:31 cargo clippy 534 tk cd prepend (cargo-wrong-dir)
...
Pillar Breakdown:
Pillar 1 (context resolution): <span data-stat="session_p1_tokens">3,204</span> tokens <span data-stat="session_p1_pct">36.6</span>%
Pillar 2 (GDB debugging): 0 tokens 0.0%
Pillar 3 (mined preventions): 0 tokens 0.0%
Pillar 4 (automation skills): <span data-stat="session_p4_tokens">1,560</span> tokens <span data-stat="session_p4_pct">17.8</span>%
RTK rewrites: <span data-stat="session_rtk_tokens">2,749</span> tokens <span data-stat="session_rtk_pct">31.5</span>%
Lean-ctx wraps: <span data-stat="session_lean_tokens">1,228</span> tokens <span data-stat="session_lean_pct">14.1</span>%
如何估算节省
每种修正类型都有基于没有PRECC时会发生什么的估计token成本:
| 修正类型 | 估计节省 | 原因 |
|---|---|---|
| cd prepend | ~500 tokens | 错误输出 + Claude推理 + 重试 |
| 技能激活 | ~400 tokens | 错误输出 + Claude推理 + 重试 |
| RTK rewrite | ~250 tokens | Claude需要阅读的冗长输出 |
| Lean-ctx wrap | ~600 tokens | 大文件内容被压缩 |
| 挖掘预防 | ~500 tokens | 已知的失败模式被避免 |
这些是保守估计。实际节省通常更高,因为Claude对错误的推理可能很冗长。
累计节省
节省数据在PRECC数据库中跨会话持久化。随着时间推移,您可以跟踪总体影响:
$ precc savings
Session Token Savings
=====================
Total estimated savings: <span data-stat="session_tokens_saved">8,741</span> tokens
Lifetime savings: <span data-stat="total_tokens_saved">142,389</span> tokens across <span data-stat="total_sessions">47</span> sessions
状态栏
安装后,PRECC 会在 ~/.claude/settings.json 中写入一条 statusLine 条目,使 Claude Code 状态栏显示实时会话指标:
$0.42 spent | 1.2M in/out | 📊 last cmd: −1.2K | PRECC: 7 fixes | 5.8ms avg | this session: 320 saved over 7 cmds (~$0.05) | lifetime: 8.9K saved over 217 cmds (~$2.85)
设置 PRECC_LANG 以你的语言显示标签 — 请参阅本地化章节。
每个分段:
| 分段 | 来源 | 含义 | 会话重启时重置? |
|---|---|---|---|
$0.42 spent | cost.total_cost_usd | Claude Code 报告的累计会话费用 | 是 |
1.2M in/out | total_input_tokens + total_output_tokens | 会话中非缓存的输入 + 输出 tokens | 是 |
📊 last cmd: −1.2K | PRECC 对最近一条 Bash 命令的测量 | 通过重新运行原始命令测得的真实节省 | 否(跨会话保留) |
PRECC: 7 fixes | metrics.log | 本次会话的修正次数 — 仅计数,不含虚假 token 估算 | 是 |
5.8ms avg | PRECC 钩子延迟 p50 | PRECC 处理每次工具调用所花的时间 | 是 |
bash 18% of total | post_observations.log | 会话 token 中来自 Bash 输出的占比 — 解释为何 PRECC 的节省自然只是总成本的一部分(PRECC 仅优化 Bash 输出) | 是 |
this session: 320 saved over 7 cmds (~$0.05) | .lifetime_summary.json − baseline | 每个会话的真实增量。当增量为零时隐藏(会话开始) | 是(基线重新快照) |
lifetime: 8.9K saved over 217 cmds (~$2.85) | .lifetime_summary.json | 自首次安装 PRECC 以来累计节省的 tokens 和重新测量的命令,以及按当前每 token 费率估算的美元价值 | 否 |
lifetime: 分段放在最后,这样如果 Claude Code 的界面在右侧裁剪状态栏,它会最先被截断。
为何费用和 token 数不能相除
显示的 1.2M in/out 不是产生 $0.42 spent 的分母。Claude Code 的 cost.total_cost_usd 是根据 API 的完整 token 分项计算的——基础输入、输出,外加缓存读取和缓存创建。整个会话累计的缓存 token 数未在 statusline 模式中暴露,因此 PRECC 只能显示可见的(非缓存)部分。
在频繁重读文件的长会话中,缓存读取可能是可见 token 数的 10 倍。这就是为何将两者作为比率配对会产生误导——PRECC 改为将其显示为独立分段。
为何 PRECC 不计算费用
费用数字是权威的。PRECC 从 Claude Code 通过 stdin 传给状态命令的 JSON 中逐字读取 cost.total_cost_usd。这就是 Claude Code 对你订阅/用量预算扣费的同一个数字。你可以随时使用内置的 /cost 斜杠命令验证 — 两者应一致。
什么驱动费用
对于 Claude Opus 4.6:
| Token type | Standard (≤200k context) | 1M context tier |
|---|---|---|
| Input | $15 / MTok | $30 / MTok |
| Output | $75 / MTok | $150 / MTok |
| Cache write | $18.75 / MTok | $37.50 / MTok |
| Cache read | $1.50 / MTok | $3 / MTok |
长会话中最大的驱动通常是输出 tokens(每 token 最贵的类型,尤其在 1M 上下文层级)、重复的缓存读取(单次便宜但跨多轮快速累积),以及缓存创建(每次文件读取写入一次,约为基础输入费率的 1.25 倍)。PRECC 通过压缩 Bash 输出来降低可见 token 成本(📊 last cmd: 分段显示每条命令的节省),但无法减少 Claude 已加载文件的缓存读取。
稳定的会话计数
“PRECC: N fixes” 分段统计自持久化的会话开始以来的事件,会话开始在每个会话首次 statusline 刷新时写入 ~/.local/share/precc/sessions/<session_id>.start。这使计数单调 — 即使某次刷新中缺少 cost.total_duration_ms,会话中途也不会减少。
自动刷新的累计快照
lifetime: 分段读取 ~/.local/share/precc/.lifetime_summary.json,该文件在每次 PostToolUse 测量和每次 precc savings 调用时被重写。this session: 分段读取相同的 lifetime 文件,但减去在每个会话首次刷新时持久化的会话基线。无需手动刷新 — 文件会自动更新。
禁用状态栏
如果你更想保留现有的状态栏,请在 ~/.claude/settings.json 中设置你自己的 statusLine 命令。PRECC 的安装程序会检测到自定义值,并在后续更新中保持不变。
若只想抑制每次交互的 📊 PRECC 行(在 additionalContext 中),请在 shell 环境中设置 PRECC_QUIET=1。
Related research
PRECC’s three savings mechanisms each have a counterpart in the recent literature. These are related work — the ideas PRECC’s design draws on. Their reported figures are their measurements, not PRECC’s: PRECC only ever quotes numbers measured on your own machine (see “measured, not estimated”, above).
- Output/trajectory trimming (PRECC’s
diet+ bash-output compression) — Reducing Cost of LLM Agents with Trajectory Reduction (AgentDiet), FSE 2026, arXiv:2509.23586. Removes redundant/expired trajectory content post-hoc; reports −39.9–59.7% input tokens. PRECC applies the same idea pre-execution and deterministically (no extra LLM call). - Skills as programs (PRECC’s mined + builtin rewrite skills) — Harnessing LLM Agents with Skill Programs, arXiv:2605.17734. Frames reusable agent skills as executable program functions — the same analogy behind PRECC’s command-rewrite skills (a pattern → a deterministic rewrite).
- Context compression (PRECC’s
compress+lean-ctxwrapping) — Compress the Context, Keep the Commitments: A Formal Framework for Verifiable LLM Context Compression, arXiv:2605.17304. Recent work on compressing context without losing required information — the property PRECC’s deterministic, cache-stable rewrites aim to preserve.
压缩
precc compress 缩小 CLAUDE.md 和其他上下文文件,以减少 Claude Code 加载时的 token 使用量。这是 Pro 功能。
基本用法
$ precc compress .
[precc] Scanning directory: .
[precc] Found 3 context files:
CLAUDE.md (2,847 tokens -> 1,203 tokens, -57.7%)
ARCHITECTURE.md (4,112 tokens -> 2,044 tokens, -50.3%)
ALTERNATIVES.md (3,891 tokens -> 1,967 tokens, -49.5%)
[precc] Total: 10,850 tokens -> 5,214 tokens (-51.9%)
[precc] Files compressed. Use --revert to restore originals.
试运行
预览将要更改的内容而不修改文件:
$ precc compress . --dry-run
[precc] Dry run -- no files will be modified.
[precc] CLAUDE.md: 2,847 tokens -> 1,203 tokens (-57.7%)
[precc] ARCHITECTURE.md: 4,112 tokens -> 2,044 tokens (-50.3%)
[precc] ALTERNATIVES.md: 3,891 tokens -> 1,967 tokens (-49.5%)
[precc] Total: 10,850 tokens -> 5,214 tokens (-51.9%)
还原
原始文件会自动备份。要恢复它们:
$ precc compress --revert
[precc] Restored 3 files from backups.
压缩了什么
压缩器应用多种转换:
- 删除冗余空白和空行
- 缩短冗长的措辞同时保留含义
- 压缩表格和列表
- 去除注释和装饰性格式
- 保留所有代码块、路径和技术标识符
压缩后的输出仍然是人类可读的——它不是压缩化或混淆的。
针对特定文件
$ precc compress CLAUDE.md
[precc] CLAUDE.md: 2,847 tokens -> 1,203 tokens (-57.7%)
报告
precc report 生成一个分析仪表板,总结 PRECC 活动和 token 节省情况。
生成报告
$ precc report
PRECC Report -- 2026-04-03
==========================
Sessions analyzed: 12
Commands intercepted: 87
Total token savings: 42,389
Top skills by activation:
1. cargo-wrong-dir 34 activations 17,204 tokens saved
2. npm-wrong-dir 18 activations 9,360 tokens saved
3. git-wrong-dir 12 activations 4,944 tokens saved
4. RTK rewrite 15 activations 3,750 tokens saved
5. python-wrong-dir 8 activations 4,131 tokens saved
Savings by pillar:
Pillar 1 (context resolution): 28,639 tokens 67.6%
Pillar 4 (automation skills): 7,000 tokens 16.5%
RTK rewrites: 3,750 tokens 8.8%
Lean-ctx wraps: 3,000 tokens 7.1%
Recent corrections:
2026-04-03 09:12 cargo build -> cd myapp && cargo build
2026-04-03 09:18 npm test -> cd frontend && npm test
2026-04-03 10:05 git status -> cd repo && git status
...
通过电子邮件发送报告
将报告发送到电子邮件地址(需要邮件设置,见 Email):
$ precc report --email
[precc] Report sent to you@example.com
收件人地址从 ~/.config/precc/mail.toml 读取。您也可以使用 precc mail report EMAIL 发送到特定地址。
报告数据
报告从本地 PRECC 数据库 ~/.local/share/precc/history.db 生成。除非您明确通过电子邮件发送报告,否则没有数据离开您的机器。
挖掘
PRECC挖掘Claude Code会话日志以学习失败-修复模式。当它再次看到同样的错误时,会自动应用修复。
导入会话日志
导入单个文件
$ precc ingest ~/.claude/logs/session-2026-04-03.jsonl
[precc] Parsing session-2026-04-03.jsonl...
[precc] Found 142 commands, 8 failure-fix pairs
[precc] Stored 8 patterns in history.db
[precc] 2 new skill candidates identified
导入所有日志
$ precc ingest --all
[precc] Scanning ~/.claude/logs/...
[precc] Found 23 session files (14 new, 9 already ingested)
[precc] Parsing 14 new files...
[precc] Found 47 failure-fix pairs across 14 sessions
[precc] Stored 47 patterns in history.db
[precc] 5 new skill candidates identified
强制重新导入
要重新处理已导入的文件:
$ precc ingest --all --force
[precc] Re-ingesting all 23 session files...
挖掘的工作原理
- PRECC读取会话JSONL日志文件。
- 它识别命令对,其中第一个命令失败,第二个是纠正后的重试。
- 它提取模式(出了什么问题)和修复(Claude做了什么不同的事)。
- 模式存储在
~/.local/share/precc/history.db中。 - 当模式达到置信阈值(多次出现)时,它成为
heuristics.db中的挖掘技能。
示例模式
Failure: pytest tests/test_auth.py
Error: ModuleNotFoundError: No module named 'myapp'
Fix: cd /home/user/myapp && pytest tests/test_auth.py
Pattern: pytest outside project root -> prepend cd
precc-learner 守护进程
precc-learner 守护进程在后台运行,自动监视新的会话日志:
$ precc-learner &
[precc-learner] Watching ~/.claude/logs/ for new sessions...
[precc-learner] Processing session-2026-04-03-1412.jsonl... 3 new patterns
守护进程使用文件系统通知(Linux上的inotify,macOS上的FSEvents),因此在会话结束时立即做出反应。
从模式到技能
挖掘的模式在满足以下条件时升级为技能:
- 跨会话至少出现3次
- 一致的修复模式(每次相同类型的纠正)
- 未检测到误报
您可以通过以下方式查看技能候选:
$ precc skills advise
有关管理技能的详细信息,请参见 Skills。
数据存储
- 失败-修复对:
~/.local/share/precc/history.db - 升级的技能:
~/.local/share/precc/heuristics.db
两者都是WAL模式的SQLite数据库,用于安全的并发访问。
电子邮件
PRECC可以通过电子邮件发送报告和文件。这需要一次性的SMTP设置。
设置
$ precc mail setup
SMTP host: smtp.gmail.com
SMTP port [587]: 587
Username: you@gmail.com
Password: ********
From address [you@gmail.com]: you@gmail.com
[precc] Mail configuration saved to ~/.config/precc/mail.toml
[precc] Sending test email to you@gmail.com...
[precc] Test email sent successfully.
配置文件
配置存储在 ~/.config/precc/mail.toml:
[smtp]
host = "smtp.gmail.com"
port = 587
username = "you@gmail.com"
password = "app-password-here"
from = "you@gmail.com"
tls = true
您可以直接编辑此文件:
$EDITOR ~/.config/precc/mail.toml
对于Gmail,请使用应用密码而不是您的账户密码。
发送报告
$ precc mail report team@example.com
[precc] Generating report...
[precc] Sending to team@example.com...
[precc] Report sent.
发送文件
$ precc mail send colleague@example.com output.log
[precc] Sending output.log to colleague@example.com...
[precc] Sent (14.2 KB).
SSH中继支持
如果您的机器无法直接访问SMTP服务器(例如,在企业防火墙后面),PRECC支持通过SSH隧道中继:
[smtp]
host = "localhost"
port = 2525
[ssh_relay]
host = "relay.example.com"
user = "you"
remote_port = 587
local_port = 2525
PRECC将在发送前自动建立SSH隧道。
GIF录制
precc gif 从bash脚本创建终端会话的动画GIF录制。这是Pro功能。
基本用法
$ precc gif script.sh 30s
[precc] Recording script.sh (max 30s)...
[precc] Running: echo "Hello, world!"
[precc] Running: cargo build --release
[precc] Running: cargo test
[precc] Recording complete.
[precc] Output: script.gif (1.2 MB, 24s)
第一个参数是包含要运行的命令的bash脚本。第二个参数是最大录制时长。
脚本格式
脚本是标准的bash文件:
#!/bin/bash
echo "Building project..."
cargo build --release
echo "Running tests..."
cargo test
echo "Done!"
输入模拟
对于交互式命令,提供输入值作为额外参数:
$ precc gif interactive-demo.sh 60s "yes" "my-project" "3"
每个额外参数在脚本提示输入时作为一行stdin输入。
输出选项
输出文件默认以脚本命名(script.gif)。GIF使用深色终端主题,标准80x24尺寸。
为什么使用GIF而不是asciinema?
内置技能 asciinema-gif 自动将 asciinema rec 重写为 precc gif。GIF文件更具可移植性——它们可以在GitHub README、Slack和电子邮件中内联显示,无需播放器。
GitHub Actions 分析
precc gha 分析失败的GitHub Actions运行并建议修复方案。这是Pro功能。
用法
传入失败的GitHub Actions运行的URL:
$ precc gha https://github.com/myorg/myrepo/actions/runs/12345678
[precc] Fetching run 12345678...
[precc] Run: CI / build (ubuntu-latest)
[precc] Status: failure
[precc] Failed step: Run cargo test
[precc] Log analysis:
Error: test result: FAILED. 2 passed; 1 failed
Failed test: tests::integration::test_database_connection
Cause: thread 'tests::integration::test_database_connection' panicked at
'called Result::unwrap() on an Err value: Connection refused'
[precc] Suggested fix:
The test requires a database connection but the CI environment does not
start a database service. Add a services block to your workflow:
services:
postgres:
image: postgres:15
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: test
功能说明
- 解析GitHub Actions运行URL以提取所有者、仓库和运行ID。
- 通过GitHub API获取运行日志(如果设置了
GITHUB_TOKEN则使用,否则公开访问)。 - 识别失败步骤并提取相关错误行。
- 分析错误并根据常见CI失败模式建议修复方案。
支持的失败模式
- 缺少服务容器(数据库、Redis等)
- 运行器OS或架构不正确
- 缺少环境变量或密钥
- 依赖安装失败
- 测试超时
- 权限错误
- 缓存未命中导致构建缓慢
地理围栏
PRECC包含用于受监管环境的IP地理围栏合规性检查。这是Pro功能。
概述
一些组织要求开发工具仅在批准的地理区域内运行。PRECC的地理围栏功能验证当前机器的IP地址是否在允许的区域列表中。
检查合规性
$ precc geofence check
[precc] Current IP: 203.0.113.42
[precc] Region: US-East (Virginia)
[precc] Status: COMPLIANT
[precc] Policy: us-east-1, us-west-2, eu-west-1
如果机器在允许的区域之外:
$ precc geofence check
[precc] Current IP: 198.51.100.7
[precc] Region: AP-Southeast (Singapore)
[precc] Status: NON-COMPLIANT
[precc] Policy: us-east-1, us-west-2, eu-west-1
[precc] Warning: Current region is not in the allowed list.
刷新地理围栏数据
$ precc geofence refresh
[precc] Fetching updated IP geolocation data...
[precc] Updated. Cache expires in 24h.
查看地理围栏信息
$ precc geofence info
Geofence Configuration
======================
Policy file: ~/.config/precc/geofence.toml
Allowed regions: us-east-1, us-west-2, eu-west-1
Cache age: 2h 14m
Last check: 2026-04-03 09:12:00 UTC
Status: COMPLIANT
清除缓存
$ precc geofence clear
[precc] Geofence cache cleared.
配置
地理围栏策略在 ~/.config/precc/geofence.toml 中定义:
[geofence]
allowed_regions = ["us-east-1", "us-west-2", "eu-west-1"]
check_on_init = true
block_on_violation = false
设置 block_on_violation = true 以阻止PRECC在允许区域外运行。
遥测
PRECC支持可选的匿名遥测以帮助改进工具。除非您明确同意,否则不会收集任何数据。
选择加入
$ precc telemetry consent
[precc] Telemetry enabled. Thank you for helping improve PRECC.
[precc] You can revoke consent at any time with: precc telemetry revoke
选择退出
$ precc telemetry revoke
[precc] Telemetry disabled. No further data will be sent.
检查状态
$ precc telemetry status
Telemetry: disabled
Last sent: never
预览将发送的数据
在选择加入之前,您可以查看将收集的确切数据:
$ precc telemetry preview
Telemetry payload (this session):
{
"version": "0.3.0",
"os": "linux",
"arch": "x86_64",
"skills_activated": 12,
"commands_intercepted": 87,
"pillars_used": [1, 4],
"avg_hook_latency_ms": 2.3,
"session_count": 1
}
收集的数据
- PRECC版本、操作系统和架构
- 汇总计数:拦截的命令、激活的技能、使用的支柱
- 平均钩子延迟
- 会话数
不收集的数据
- 不收集命令文本或参数
- 不收集文件路径或目录名
- 不收集项目名称或仓库URL
- 不收集个人身份信息(PII)
- 不收集IP地址(服务器不记录它们)
环境变量覆盖
无需运行命令即可禁用遥测(适用于CI或共享环境):
export PRECC_NO_TELEMETRY=1
这优先于同意设置。
数据目的地
遥测数据通过HTTPS发送到 https://telemetry.peria.ai/v1/precc。数据仅用于了解使用模式和确定开发优先级。
令牌成本预测
PRECC 内置令牌成本预测预言机,让多步骤计划以令牌而非挂钟时间来制定预算。在每一步之前记录预测,工作完成后记录实际值,数据集会训练内置预测器,并随时间不断改进。
记录一次预测
传入计划步骤的一行描述。PRECC 会对其分类(feat / fix / test / refactor / measurement / doc / chore / unknown),估算令牌数,并打印一个 id,用于稍后闭环。
$ precc predict "Implement read-deltas with mtime check"
id=42 category=feat predicted=5680 tokens (confidence=0.50, model=trained-v1)
Record actual when done: precc predict --record 42 <actual_tokens>
记录实际值
步骤完成后,从会话页脚或遥测中查到实际令牌数,并通过 id 回填。
$ precc predict --record 42 6300
Recorded actual=6300 tokens for prediction id=42.
训练 trained-v1
当至少有 10 条闭合的预测时,在 log10(actual) 对 log10(描述长度) 加上一个 one-hot 类别虚拟变量上拟合 trained-v1 岭回归。拟合是闭式解(在带 ridge λ=1 的正规方程上做 Cholesky 分解),运行只需毫秒级。
$ precc predict --train
Trained trained-v1 on 22 closed predictions (λ=1).
Model file : ~/.local/share/precc/predict_model.json
Confidence : 0.50
Intercept : +1.0016
log_desc : +1.2339
Categories :
unknown +0.4811
doc +0.4474
measurement +0.3422
test +0.1071
refactor +0.0326
feat +0.0071
fix -0.1096
chore -0.3063
训练完成后,每次新的 precc predict 调用会自动使用 trained-v1,直到你移除或替换模型文件。旧预测保留其原始 model_version,便于你随时间比较预测器。
检查预测器精度
precc predict --eval 报告整体和分类别的平均绝对百分比误差(MAPE),仅在已闭合的预测(同时有预测值与实际值的行)上计算。
$ precc predict --eval
Predictions logged : 30
With actuals (closed): 22
Mean predicted : 1483 tokens
Mean actual : 47238 tokens
MAPE (statistical) : 76.4%
By category:
category n predicted actual MAPE
feat 6 4605 5250 26.2%
unknown 4 1597 30526 52.6%
test 4 924 38900 56.4%
...
列出最近的预测
precc predict --list 以倒序时间显示最近的记录。开放行(无实际值)等待闭合。
$ precc predict --list --limit 5
id ts category predicted actual conf description
30 2026-05-09 09:40:51 feat 5348 - 0.50 Run the synthetic-fleet pilot...
29 2026-05-09 08:56:48 test 1050 - 0.60 Train predictor: trained-v1...
28 2026-05-09 07:44:18 test 915 150000 0.60 Implement minimal task-12...
为什么用令牌而不是挂钟时间
时间估算事后无法测量,且无法跨机器或跨会话组合。令牌计数是确定性的、可比较的,并且每个闭合的回路都会扩充带标签的数据集,从而持续改进预测器。预言机的核心意义就是把估算从猜测游戏变成测量。
数据存放在哪里
所有预测数据都保存在你本地机器上,不会上传任何内容。
~/.local/share/precc/
├── metrics.db — predictions table (oracle DB)
└── predict_model.json — trained-v1 coefficients (after `--train`)
本地化
PRECC 的状态行和简短反馈字符串支持 28 种语言渲染。翻译已编译进二进制文件,因此在 hook 阶段选择语言不会产生额外 I/O。
设置语言
将环境变量 PRECC_LANG 设置为支持的语言代码。它优先于其他任何来源。
$ PRECC_LANG=zh precc savings
$ export PRECC_LANG=ja
通过 consent.toml 持久化
在 ~/.config/precc/consent.toml 中添加 [ui] preferred_language = "ja"(或任何受支持的代码),即可在不导出环境变量的情况下跨 shell 保留该选择。
# ~/.config/precc/consent.toml
[ui]
preferred_language = "ja"
解析顺序
PRECC 先检查 PRECC_LANG,再检查 consent.toml 中的 [ui] preferred_language,最后回退到英文。第一个非空信号生效,并在进程生命周期内缓存。
1. PRECC_LANG (environment variable)
2. consent.toml ([ui] preferred_language)
3. "en" (default)
语言覆盖
翻译表共附带 28 列语言。我们无法人工核验的单元格保持为空,在查询时回退到英文,而不是显示伪造文本。如果您能改进某种翻译,欢迎向上游提交。
en es de zh fr pt ja vi nl hu ar fa tr ko
th my mn bo pl ru zt da sv fi it is2 ro cs
为什么依然很快
翻译以编译期 const 数组的形式直接放在 precc-core 二进制中,不在 SQLite 里。Hook 仅做一次内存数组查找,因此相对于 < 5 ms 的 p99 hook 预算,翻译开销可以忽略不计。
思维导图
本页由 mindmap.db 自动生成 — 这是一个 SQLite 快照,记录了所有 PRECC 开发会话和 git 提交。每一行都可追溯到其来源(commit:<sha>、session:<id> 或 doc:<path>)。
概览
- 已分析会话: 22
- 消息: 14023
- 工具调用: 5072
- 提交: 205
- 时间范围: 2026-03-20T07:04:14.787Z → 2026-04-19T11:50:10.153Z
- 工作量(令牌):
- 输入: 27928
- 输出: 2750669
- 缓存写入: 43349705
- 缓存读取: 1936351239
功能
| 范围 | 标题 | 状态 | 提交数 | 令牌 | 首次 | 最近 | 来源 |
|---|---|---|---|---|---|---|---|
bench | feat(bench): SWE-bench Verified/Lite driver scaffolding | stabilizing | 4 | 4344299 | 2026-04-17 | 2026-04-17 | commit:5bdd027d |
benchmark_gate.sh | feat: benchmark_gate.sh + pin tb dataset to 0.1.1 | shipped | 1 | 4344299 | 2026-04-17 | 2026-04-17 | commit:99fa9a74 |
real | feat: real lean-ctx (not stub), wider campaign, doc updates | shipped | 2 | 29821152 | 2026-04-07 | 2026-04-17 | commit:6095720a |
precc_mode=benchmark | feat: PRECC_MODE=benchmark toggle + pairwise benchmark harness | shipped | 1 | 4344299 | 2026-04-17 | 2026-04-17 | commit:50c5a30f |
add | feat: add precc update self-update command | shipped | 14 | 42557107 | 2026-03-09 | 2026-04-17 | commit:e5542fba |
negotiable | feat: negotiable rewrites, skill decay, explain/undo — response to critic | shipped | 1 | 4344299 | 2026-04-17 | 2026-04-17 | commit:6fda67e4 |
statusline | feat: statusline shows actual session token consumption + cost | stabilizing | 3 | 25424915 | 2026-04-08 | 2026-04-13 | commit:4f65556d |
public | feat: public repo commits attributed to Ce-cyber-art | shipped | 1 | 25382119 | 2026-04-10 | 2026-04-10 | commit:0e4840e4 |
short | feat: short install URL https://peria.ai/install.sh | shipped | 1 | 25382119 | 2026-04-09 | 2026-04-09 | commit:615d3d06 |
rewrite | feat: rewrite Pillar 2b (ccc) and Pillar 3 (compress) in Rust for single-binary deployment | shipped | 2 | 38118074 | 2026-03-20 | 2026-04-08 | commit:78621579 |
shorten | feat: shorten statusline segments to fit narrower terminals | shipped | 1 | 25382119 | 2026-04-08 | 2026-04-08 | commit:ef2c88b4 |
drop | feat: drop fake token estimate, append cost estimate to lifetime segment | stabilizing | 2 | 25382119 | 2026-04-08 | 2026-04-08 | commit:2702f3f9 |
update | feat: update pricing to $5/6mo + $10/yr, add webhook server | stabilizing | 9 | 38118074 | 2026-02-25 | 2026-04-08 | commit:2d366031 |
clearer | feat: clearer statusline labels — meas:, drop confusing %, add bash share | shipped | 1 | 25382119 | 2026-04-08 | 2026-04-08 | commit:4cd837b7 |
stable | feat: stable machine_hash for telemetry dedup | stabilizing | 2 | 25382119 | 2026-04-08 | 2026-04-08 | commit:3073f428 |
lifetime | feat: lifetime savings segment in statusline | shipped | 1 | 25382119 | 2026-04-08 | 2026-04-08 | commit:9af422e8 |
precc | feat: precc analyze frequencies — data-driven rule gap discovery | shipped | 3 | 25382119 | 2026-04-07 | 2026-04-08 | commit:d6f24c50 |
per-interaction | feat: per-interaction PRECC savings line in PostToolUse | shipped | 1 | 25382119 | 2026-04-08 | 2026-04-08 | commit:e3bc282e |
webhook | feat: webhook auto-regenerates stats.json on telemetry POST | stabilizing | 2 | 29134186 | 2026-03-31 | 2026-04-08 | commit:912b75f3 |
per-email | feat: per-email aggregation for telemetry | shipped | 1 | 25382119 | 2026-04-08 | 2026-04-08 | commit:14c95e7d |
v0.3.3 | feat: v0.3.3 — companion tools default-on, install-script clarity | shipped | 1 | 25382119 | 2026-04-07 | 2026-04-07 | commit:48fca046 |
measurement | feat: measurement campaign script — real per-mode measurements | shipped | 1 | 25382119 | 2026-04-07 | 2026-04-07 | commit:36760587 |
quote-aware | feat: quote-aware chain split + sysadmin tool whitelist (54.2% → 55.5%) | shipped | 1 | 25382119 | 2026-04-07 | 2026-04-07 | commit:f6580598 |
; | feat: ; chain support + ssh inner-command parsing for measurement | shipped | 1 | 25382119 | 2026-04-07 | 2026-04-07 | commit:10093218 |
expand | feat: expand is_safe_to_rerun coverage + measurement timeout/cache | shipped | 1 | 25382119 | 2026-04-07 | 2026-04-07 | commit:c5a7ea79 |
multi-mode | feat: multi-mode adaptive compression with failure learning | shipped | 1 | 25382119 | 2026-04-07 | 2026-04-07 | commit:81475afc |
measured | feat: measured savings in telemetry, detailed live stats, update nudge | shipped | 1 | 25382119 | 2026-04-06 | 2026-04-06 | commit:06907091 |
scientific | feat: scientific token savings measurement, telemetry dedup, 28-language docs | shipped | 1 | 25382119 | 2026-04-06 | 2026-04-06 | commit:78a20ef2 |
v0.3.2 | feat: v0.3.2 — hook safety, adaptive compression, on-demand metrics import | shipped | 1 | 25382119 | 2026-04-05 | 2026-04-05 | commit:a0c0c882 |
self-hosted | feat: self-hosted telemetry endpoint at peria.ai, install UX improvements | shipped | 1 | 2565703 | 2026-04-04 | 2026-04-04 | commit:8212a18e |
auto-update | feat: auto-update consent prompt on init and manual update | shipped | 1 | 1924302 | 2026-04-02 | 2026-04-02 | commit:818be6dd |
use | perf: use pre-built binaries for lean-ctx and nushell installation | stabilizing | 4 | 10170252 | 2026-03-09 | 2026-03-31 | commit:8c612e55 |
authorize | feat: authorize peria.ai server for license key generation | shipped | 2 | 1186364 | 2026-03-31 | 2026-03-31 | commit:53dfe832 |
license | feat: license keys, SMTP mail-agent, updated business plan and demos | stabilizing | 2 | 10170252 | 2026-03-09 | 2026-03-31 | commit:b07c9dfb |
lean-ctx | feat: lean-ctx integration for deep output compression | shipped | 1 | 1186364 | 2026-03-31 | 2026-03-31 | commit:07361e62 |
integrate | feat: integrate three-pillar savings from precc-cc (cocoindex-code, token-saver, ClawHub) | shipped | 2 | 10170252 | 2026-03-20 | 2026-03-31 | commit:af4205f1 |
windows | feat: Windows build via CI, deploy triggers workflow | stabilizing | 2 | 2533692 | 2026-03-29 | 2026-03-29 | commit:7404761b |
monthly | feat: monthly usage report via email for Pro users | shipped | 1 | 2533692 | 2026-03-28 | 2026-03-28 | commit:77ad78bc |
nushell | feat: nushell what-if analysis, skill clustering, comment blocker, bash unwrap (v0.2.6) | shipped | 1 | 2337941 | 2026-03-27 | 2026-03-27 | commit:803df684 |
geofence | feat: geofence compliance guard, 3rd-party skill Claude interaction tracking (v0.2.5) | shipped | 1 | 2337941 | 2026-03-26 | 2026-03-26 | commit:0c9fc765 |
stripe | feat: Stripe payment integration, context pressure, GHA analysis | shipped | 2 | 2457088 | 2026-03-21 | 2026-03-22 | commit:8eb16f78 |
context | feat: context pressure warning, GHA analysis, statusline context % | shipped | 1 | 2166141 | 2026-03-20 | 2026-03-20 | commit:894621ba |
statusline, | feat: statusline, squash deploy, ClaWHub metadata, SHA256 checksums | shipped | 1 | 2166141 | 2026-03-20 | 2026-03-20 | commit:7ab15883 |
gumroad | feat: Gumroad license verification via API (v0.2.2) | shipped | 1 | 0 | 2026-03-13 | 2026-03-13 | commit:75c5e480 |
per-user | feat: per-user email-based license keys with Gumroad webhook (v0.2.2) | shipped | 1 | 0 | 2026-03-13 | 2026-03-13 | commit:6d056958 |
posttooluse | feat: PostToolUse observability + comprehensive test coverage (v0.2.1) | shipped | 1 | 0 | 2026-03-12 | 2026-03-12 | commit:6e33b7e4 |
multi-tool | feat: multi-tool hook dispatch, subagent propagation & Read/Grep filters (v0.2.0) | shipped | 1 | 0 | 2026-03-12 | 2026-03-12 | commit:1bf5a108 |
skill | feat: skill advisor, sharing credits, telemetry & Rust actionbook (v0.1.9) | shipped | 1 | 0 | 2026-03-12 | 2026-03-12 | commit:d41d310e |
fire | feat: fire anonymous update-check ping on precc update (opt-out via PRECC_NO_TELEMETRY=1) | shipped | 1 | 0 | 2026-03-10 | 2026-03-10 | commit:7acce69d |
enforce | feat: enforce license tier gates (Free/Pro) on ingest, mined skills, gif, mail, savings | shipped | 1 | 0 | 2026-03-10 | 2026-03-10 | commit:a7bd23e3 |
translate | feat: translate git commands to jj (Jujutsu) in colocated repos | shipped | 1 | 0 | 2026-03-09 | 2026-03-09 | commit:d8a29e48 |
rtk | feat(rtk): sync rewrite rules with upstream RTK v0.27.2 | shipped | 1 | 0 | 2026-03-09 | 2026-03-09 | commit:ad7dca0e |
apply | feat: apply skill portfolio per command for maximum token savings | shipped | 1 | 0 | 2026-03-09 | 2026-03-09 | commit:b2490073 |
pitch | feat(pitch): add bilingual EN/ZH PowerPoint pitch deck | shipped | 2 | 0 | 2026-02-27 | 2026-02-28 | commit:8876c4b7 |
hook | perf(hook): skip heuristics.db open via plain-text prefix cache | shipped | 1 | 0 | 2026-02-27 | 2026-02-27 | commit:89537483 |
init | feat(init): embed builtin skills in binary via include_str! | shipped | 1 | 0 | 2026-02-26 | 2026-02-26 | commit:3a837b13 |
cli | feat(cli): add precc skills export command | shipped | 2 | 0 | 2026-02-26 | 2026-02-26 | commit:59beea8d |
gdb | feat(gdb): re-enable Pillar 2 GDB hook suggestion | shipped | 1 | 0 | 2026-02-26 | 2026-02-26 | commit:a8428025 |
skills | feat(skills): add git wrong-dir skill and context mapping | stabilizing | 2 | 0 | 2026-02-25 | 2026-02-25 | commit:352474e1 |
metrics | feat(metrics): record hook latency, rtk_rewrite, cd_prepend via append-log | shipped | 1 | 0 | 2026-02-25 | 2026-02-25 | commit:9bf31d12 |
demo | feat(demo): add investor demo suite | shipped | 1 | 0 | 2026-02-25 | 2026-02-25 | commit:c818a0ac |
security | feat(security): SQLCipher encryption, binary hardening, multi-platform CI | shipped | 1 | 0 | 2026-02-25 | 2026-02-25 | commit:efd3dfc8 |
ingest | feat(ingest): add –force flag to re-mine already-recorded sessions | shipped | 1 | 0 | 2026-02-22 | 2026-02-22 | commit:85cc8f6f |
依赖关系(precc-core 模块)
advisor→db,promote,skillsdiet→lean_ctxmetrics→dbmining→skillsmode_selector→db,modemulti_probe→diet,lean_ctx,mode,nushell,post_observe,rtknushell→lean_ctx,mining,rtkpromote→db,skillsrtk→lean_ctxsharing→db,license,skillsskill_advisor→mining,nushellskills→dbtelemetry→db,license,mining
计划与任务
计划(请求设计/架构的提示)
- [proposed] indeed the measurement needs to be based on precc-cc’s established KPI’s. If the two ideas are so close, perhaps you can draft a plan to integrate them (algorithmatically) step-by-step, then start to use Rust (consistent with Precc) to impl… —
session:905ff169(2026-04-18) - [proposed] 西班牙语网站上有人评价:中文翻譯(繁體): —
session:781fe484(2026-04-16) - [proposed] That’s a really solid framing — using pre-tool-call hooks as quality gates instead of just optimization is a big shift in mindset. You’re essentially moving from “make the model cheaper” to “make the system more correct,” whic… —
session:ebd81938(2026-04-05) - [proposed] Plan the integration of both tools, make sure we don’t take their credit and maintain a clear interface so that once it evolves, we can get smaller changes to integrate with their future changes —
session:43541885(2026-03-31) - [proposed] for the benchmark, we need to prepare a table to record the comparison for existing historical scenarios, as a “what-if” analysis because there is no way to measure the results for future usages. For this requirement, plan out a step-by-ste… —
session:5761d7ca(2026-03-27) - [proposed] while bash could be improved using RTK, would its replacement with nushell a better choice for Claude Code? If so, plan an option for replacing bash with nushell to gain better accuracy and hence potentially more token savings by some small… —
session:5761d7ca(2026-03-27)
任务(TaskCreate / TodoWrite 条目)
- completed: 89
- in_progress: 3
- deleted: 2
最近 30 项任务:
- [completed] Re-ingest and review residual pending — Run precc mindmap build after the fix, then classify the actually-pending tasks (done-but-unclosed vs genuinely-unfinished). —
session:0925455d(2026-04-19) - [completed] Fold TaskCreate/TaskUpdate + dedupe TodoWrite — Replay TaskCreate/TaskUpdate events per (session_id, taskId) to derive final status. For TodoWrite, keep only the last call per session. —
session:0925455d(2026-04-19) - [completed] Run ingest and produce MINDMAP.md — Execute ingest on local sessions + git, then render output to docs/MINDMAP.md. —
session:0925455d(2026-04-19) - [completed] Wire precc mindmap CLI subcommand — Add ingest/render subcommands to precc-cli. —
session:0925455d(2026-04-19) - [completed] Write mindmap render module — Query DB and render nested markdown mindmap with KPIs, features, plans, blockers. —
session:0925455d(2026-04-19) - [completed] Write mindmap ingest module — Parse JSONL sessions + git log, extract messages/tokens/commands/decisions into SQLite. —
session:0925455d(2026-04-19) - [completed] Design SQLite mindmap schema — Tables: sessions, messages, commands, features, plans, tasks, kpis, decisions, dependencies. Every row traces to source (session_id+uuid or commit sha). —
session:0925455d(2026-04-19) - [in_progress] Step 4: HeaderSlicePass + kernel corpus — Shallow-clone Linux kernel, adapt filter for kernel conventions (Fixes: tag, selftests/ and kunit test-surface detection, .c/.h classification). Measure how many recent fix commits ship with a test an… —
session:905ff169(2026-04-19) - [completed] Step 6: concurrency extraction — Add Pipeline::run_parallel_applies that parallelizes applies() via std::thread::scope when pass count ≥ threshold. Falls back to serial below threshold (thread-spawn overhead > savings). Benchmark s… —
session:905ff169(2026-04-19) - [completed] [parallel] AST-aware #[test] extractor — Use syn (Rust) or tree-sitter-rust (Python) to detect added #[test] fns in a commit diff and emit a test-only patch. Gates fail→pass verification on this repo. Not blocking; parallel work for the Ru… —
session:905ff169(2026-04-19) - [completed] Step 7: precc skvm report tooling — Wire had_solid_hit into metrics log. Add
precc skvm reportthat surfaces pass activation counts, cache hit rate, hook-latency percentiles. Read from metrics.db + skvm_solid_cache. Closes the observa… —session:905ff169(2026-04-19) - [completed] Wire SolidificationPass into live hook — Add stage_solidification_lookup (front, short-circuits on hit) and stage_solidification_record (end) to Pipeline. Gate behind PRECC_SOLIDIFY. Add had_solid_hit flag. Open cache via db::open_metrics fo… —
session:905ff169(2026-04-19) - [completed] Step 3: solidification cache — skvm::solid module: Cache (SQLite-backed) with lookup/record, Key with normalization, SolidificationPass at pipeline front. Gated by PRECC_SOLIDIFY=1. Tests with in-memory DB. No wiring into live hook… —
session:905ff169(2026-04-19) - [completed] Wire CdPrependPass into hook’s stage_context — Replace the direct context::resolve/apply calls in precc-hook::Pipeline::stage_context with CdPrependPass via HookIR. Verify no hook tests regress; full cargo test green. —
session:905ff169(2026-04-19) - [completed] Step 2: migrate cd_prepend through Pass trait — Re-express the existing cd-prepend stage as a Pass impl that reuses the current context resolution. Diff-test: on a fixture corpus, the new pass must produce byte-identical output to the legacy path. … —
session:905ff169(2026-04-19) - [completed] Step 5 preview: CrateSlicePass sketch — Implement CrateSlicePass in precc-core::skvm::passes::crate_slice. Detects
cargo <build\|test\|check\|clippy>without -p, reads cachedcargo metadata, narrows to -p when unambiguous. Wire a minimal K… —session:905ff169(2026-04-19) - [completed] Step 1: Pass trait + HookIR — precc-core::skvm::{pass, ir}. Pass trait with name/capability/applies/run. HookIR holds command, cwd, and mutable output. Capability enum: Detect|Rewrite|Slice|Verify. No behavior change; no passes re… —
session:905ff169(2026-04-19) - [completed] Step 0: baseline harness — Add precc-core::skvm::baseline module +
precc report --skvm-baselinesubcommand. Snapshots K1 (hook latency p50/p99), K3 (token savings total), activation counts from metrics.db into a named baselin… —session:905ff169(2026-04-19) - [completed] Build K3-only replay corpus — For each of the 82 fix-surface commits, derive ground-truth set of changed crates and emit realistic cargo commands. CrateSlicePass evaluation will read this corpus and measure narrowing precision/rec… —
session:905ff169(2026-04-18) - [deleted] Run verifier over 33 candidates — Execute verifier, collect verdicts. Apply size gate to verified set. Emit precc_self_corpus.jsonl. —
session:905ff169(2026-04-18) - [deleted] Write fail-at-parent verifier — Per candidate: git worktree at parent, apply only test-file diff, cargo test (expect added tests FAIL), reset + apply full commit, cargo test (expect PASS). Per-worktree CARGO_TARGET_DIR to avoid tras… —
session:905ff169(2026-04-18) - [completed] Classify test surface of 33 candidates — Split candidates into pure_test_path (tests/ only) vs mixed_file_test (production + #[test] in same file). Reports count by class. Cheap, no cargo. —
session:905ff169(2026-04-18) - [completed] Run first Terminal-bench batch (5 tasks) — Execute scripts/benchmark.sh –tasks 5 using OAuth token from subscription as ANTHROPIC_API_KEY. Verify arm A (vanilla) works, then arm B (PRECC), then compare.json. —
session:781fe484(2026-04-17) - [completed] Add precc explain and precc undo — explain –since 1h: lists recent rewrites with diff + skill + confidence (reads stash + rewrite_log). undo <id>: re-disables the skill that produced rewrite id. —
session:781fe484(2026-04-16) - [completed] Confidence decay on retry-after-rewrite — post_observe: if same command class is retried within 60s after a PRECC rewrite, decrement skill confidence by 0.05 (or count as false-correction event). Below SUGGEST_THRESHOLD (0.3) skill auto-disab… —
session:781fe484(2026-04-16) - [completed] Add precc skills disable/enable per-project — CLI commands to disable a skill in the current project (writes to .precc/disabled-skills file at project root). Hook reads this list and skips matching skills. —
session:781fe484(2026-04-16) - [completed] Make every rewrite visible via additionalContext — In precc-hook, whenever the pipeline produces a non-trivial rewrite (cd-prepend, skill, RTK, lean-ctx, nushell, diet), append a one-line summary “PRECC rewrote: <orig> -> <new> [reason]” to additional… —
session:781fe484(2026-04-16) - [completed] Soften overstated claims in intro — Replace “Claude never sees the error. No tokens wasted.” with measured language matching README. Update strings_intro.sql and re-translate the new key for all 28 langs. —
session:781fe484(2026-04-16) - [completed] Fix per-language html lang and dir — build-book.sh must rewrite book.toml language= and text-direction= per language so generated pages have correct lang/dir attributes. RTL for ar, fa. —
session:781fe484(2026-04-16) - [completed] Rebuild book and verify — Run scripts/build-book.sh to regenerate introduction.md per language, verify first lines now show translations —
session:781fe484(2026-04-16)
阻塞项(用户报告的失败/卡住信号)
- look at all the historical session logs and executed commands to summarize a mark down document like Mindmap showing (1) the features, status, decisions, dependencies, and effort (tokens releated to its development); (2) the plans, tasks, s… —
session:0925455d(2026-04-19) - check if it is working? why precc savings –all doesn’t work? —
session:ebd81938(2026-04-13) - i tried that url it doesn’t work? —
session:ebd81938(2026-04-08) - why I can’t see the “last: “ messages? —
session:ebd81938(2026-04-08) - not yet. I would wait to get more data from telemetry to update the website. But now you need to investigate on those “unmeasured” cases, why we cannot measure them? —
session:ebd81938(2026-04-07) - regarding the live usage statistics https://precc.cc/en/#live-usage-statistics, we need to report the percentages based on the duration of releases, i.e., how much saving was made by which release (otherwise it is easy to mislead readers to… —
session:ebd81938(2026-04-06) - https://precc.cc cannot find the server —
session:ebd81938(2026-04-05) - can see key_id mk_1TDiUmFxhHEidPnDw5esdOMa, but cannot reveal or see the sk_live_… —
session:d65ad15f(2026-04-01) - PS C:\Users\y00577373> iwr -useb https://raw.githubusercontent.com/peria-ai/precc-cc/main/scripts/install.ps1 | iex —
session:10175339(2026-03-30) - why can’t you create peria-ai or peri-a-i organizations —
session:10175339(2026-03-28) - the hello_world_do example has the following errors: NPU run failed. —
session:3b5e2947(2026-03-22)
决策与理由
- feat(bench): clean-subset metrics (exclude timeouts & infra failures) — When one arm times out or the agent fails to install, the resulting tokens/pass numbers aren’t measuring PRECC — they’re measuring tb’s source:
commit:5bdd027d(commit 2026-04-17) - fix(bench): drop –include-hook-events (causes 401 Invalid API key) — Adding
--include-hook-eventsto the tb agent command caused Claude Code to return api_error_status=401 on first turn, even though the source:commit:025995d9(commit 2026-04-17) - feat: PRECC_MODE=benchmark toggle + pairwise benchmark harness — Problem (from reviewer): the “trivial vs semantic” error-shaping claim is rhetoric without a measurable boundary. A rewriter that saves tokens source:
commit:50c5a30f(commit 2026-04-17) - docs: update savings.md.tpl + README to match new statusline labels — - Σ → meas: throughout - New ‘bash X% of total’ segment row in segment table source:
commit:2d366031(commit 2026-04-08) - feat: clearer statusline labels — meas:, drop confusing %, add bash share — Three statusline UX changes from user feedback: 1. Lifetime segment renamed from ‘Σ 8.9K (22% over 217)’ to source:
commit:4cd837b7(commit 2026-04-08) - docs: explain statusline cost vs token semantics in book + README — Adds a ‘Status Bar’ section to docs/book/templates/savings.md.tpl and README.md explaining: source:
commit:6028b64c(commit 2026-04-08) - feat: v0.3.3 — companion tools default-on, install-script clarity — The single biggest change: install.sh now installs companion tools (lean-ctx, RTK, nushell, cocoindex-code) BY DEFAULT instead of source:
commit:48fca046(commit 2026-04-07) - feat: quote-aware chain split + sysadmin tool whitelist (54.2% → 55.5%) — Three improvements that increase measurable Bash invocation coverage: 1. Quote-aware top-level chain split source:
commit:f6580598(commit 2026-04-07) - fix: command_class env stripping, skill validation, ssh/journalctl/kubectl diet rules — 1. command_class strips env prefixes and noise: - RUST_BACKTRACE=1 cargo test → “cargo test” source:
commit:f4220343(commit 2026-04-07) - feat: multi-mode adaptive compression with failure learning — New modules: - mode.rs: CompressionMode enum (basic/diet/nushell/lean-ctx/rtk/adaptive-expand) source:
commit:81475afc(commit 2026-04-07) - test: comprehensive tests for ccc and compress modules (319 → 386 tests) — ccc.rs: +20 tests covering edge cases for is_eligible (flags, whitespace, empty input), extract_pattern (no path, multiple flags, boundary length), source:
commit:448430e2(commit 2026-03-20) - feat(gdb): re-enable Pillar 2 GDB hook suggestion — - Add open_history_readonly() to db.rs (same pattern as heuristics) - Add count_recent_failures() to gdb.rs: queries failure_fix_pairs for source:
commit:a8428025(commit 2026-02-26) - fix(mining): correct summary counters and orphaned events on –force re-mine — Three bugs fixed: 1. mine_session returned Skipped for sessions with no Bash events even source:
commit:3ef089d8(commit 2026-02-22) - 1. Compiled Rust Binary vs Shell Script — Decision: Replace the
rtk-rewrite.shshell script hook with a compiled Rust binary (precc-hook). Alternatives considered: source:doc:ALTERNATIVES.md - 2. SQLite vs Key-Value Store — Decision: Use SQLite for both
history.dbandheuristics.db. Alternatives considered: source:doc:ALTERNATIVES.md - 3. Workspace of 4 Crates vs Monolith — Decision: Structure the project as a Cargo workspace with 4 crates:
precc-core,precc-hook,precc-cli,precc-learner. Alternatives considered: source:doc:ALTERNATIVES.md - 4. GDB Hook Integration vs Standalone CLI — Decision: Implement GDB debugging as a CLI command (
precc debug) rather than as an automatic hook rewrite. Alternatives considered: source:doc:ALTERNATIVES.md - 5. Background Daemon vs On-Demand Mining — Decision: Support both modes —
precc-learnerdaemon for continuous mining,precc ingestfor on-demand. Alternatives considered: source:doc:ALTERNATIVES.md - 6. Confidence Thresholds — Decision: Three-tier confidence system: auto-apply (≥ 0.7), suggest (0.3-0.7), hidden (< 0.3). Alternatives considered: source:
doc:ALTERNATIVES.md - 7. RTK Subsumption Strategy — Decision: Port RTK’s rewriting logic into
precc-coreas the final pipeline stage, rather than running both hooks in sequence. Alternatives considered: source:doc:ALTERNATIVES.md - 8. Skill Storage Format — Decision: TOML files for built-in skills, SQLite rows for mined/user skills. Alternatives considered: source:
doc:ALTERNATIVES.md - 9. Session Log Format — Decision: Read Claude Code’s native JSONL format directly rather than converting to a custom format. Rationale: Claude Code already writes detailed session logs in JSONL format at
~/.claude/projects/*/. Creating a custom format would mean: source:doc:ALTERNATIVES.md
关键指标随时间变化
| 指标 | 单位 | 首值 | 最新值 | Δ | 样本数 | 最近来源 |
|---|---|---|---|---|---|---|
at | x | 0.1 | 1.25 | +1.15 | 2 | commit:4f65556d |
build | ms | 3 | 480 | +477 | 2 | commit:f84bab49 |
hook | ms | 5 | 3 | -2 | 2 | commit:f81e4543 |
precc | tokens | 423 | 87 | -336 | 2 | commit:e3bc282e |
saved | ms | 4.8 | 6.3 | +1.5 | 2 | commit:ec17f16c |
各会话工作量(按令牌数前 10)
| 会话 | 首次 → 最近 | 消息数 | 输入 | 输出 | 缓存写入 | 缓存读取 |
|---|---|---|---|---|---|---|
ebd81938 | 2026-04-04 → 2026-04-13 | 4517 | 4547 | 686622 | 24690950 | 1020430414 |
781fe484 | 2026-04-16 → 2026-04-17 | 1434 | 1341 | 603596 | 3739362 | 259708120 |
10175339 | 2026-03-28 → 2026-03-30 | 1318 | 1176 | 102469 | 2430047 | 110606429 |
5761d7ca | 2026-03-26 → 2026-03-28 | 1180 | 4363 | 137056 | 2196522 | 116605673 |
550c7bab | 2026-03-20 → 2026-03-22 | 1064 | 1466 | 104943 | 2059732 | 92991217 |
905ff169 | 2026-04-18 → 2026-04-19 | 650 | 1698 | 496929 | 1572668 | 63432376 |
d65ad15f | 2026-03-31 → 2026-04-04 | 752 | 558 | 78099 | 1845645 | 58334554 |
3b5e2947 | 2026-03-22 → 2026-03-23 | 1162 | 896 | 128068 | 1526203 | 102403205 |
0925455d | 2026-04-19 → 2026-04-19 | 440 | 830 | 262128 | 1226054 | 32943523 |
43541885 | 2026-03-31 → 2026-03-31 | 566 | 7353 | 82683 | 1096328 | 41667559 |
在 Cursor 中使用 PRECC
PRECC 最初是作为 Claude Code 的 PreToolUse 钩子构建的,但其底层技能库——cargo-wrong-dir、git-wrong-dir、npm-wrong-dir、jj-translate 等——与编辑器无关。通过一小段 shell 代码片段,你可以将 Cursor 集成终端中输入的每个命令都路由到 precc-hook,让那些为 Claude Code 节省 token 的相同重写规则同样在 Cursor 上生效。
Requires
precc≥ 0.3.45. Earlier versions don’t plant the integration scripts under<data_dir>/integrations/cursor/. Runprecc updateto upgrade if you have an older release.
覆盖范围
此集成会捕获你在 Cursor 终端中输入的命令。在 zsh 上,它会在你按下回车之前自动重写命令行;在 bash 上,它只能发出警告(DEBUG trap 是在命令定型之后才触发的)。Cursor 的智能体以 bash -c 子进程生成的命令不会加载你的交互式 shell 初始化文件,因此钩子无法看到它们;要弥合这一缺口需要一个 PATH 垫片,目前该目录尚未提供。Cursor 的非 shell 工具调用(文件编辑、代码搜索)同样不在覆盖范围内。
安装
zsh(自动重写)
source ~/.local/share/precc/integrations/cursor/precc-preexec.zsh
运行一次 precc init —— 它会将脚本安装到上述路径(使用 precc 存储中的 <data_dir>,因此 CLAUDE_CONFIG_DIR 等配置隔离会被遵守)。然后将 source 行添加到 ~/.zshrc。precc-hook 和 jq 必须在 PATH 中;如果任一缺失,脚本会安全地不执行任何操作。
bash(仅警告)
source ~/.local/share/precc/integrations/cursor/precc-preexec.bash
运行一次 precc init —— 它会将脚本安装到上述路径。然后将 source 行添加到 ~/.bashrc。DEBUG 陷阱会将建议的改写输出到 stderr,但不会自动应用;你可以手动复制该建议。
验证
在 Cursor 的终端中,执行 cd /tmp(或任意 Rust 项目之外的目录),输入一个 Rust 构建命令然后按下回车。在 zsh 上,缓冲区应原地变为 PRECC 重写后的形式(通常是 cd PATH && … 风格的前置)。在 bash 上,你应该会在 stderr 上看到一行 [precc] suggested rewrite: …。
注意事项
- 会引入
precc-hook的每次按键延迟。钩子的目标是 p50 < 5 ms,但在冷缓存下 p99 会更高;请参阅本书中关于钩子延迟的说明。 - 此路径不上报遥测。钩子会以它检测到的任何
agent_class上报,但那不会是claude-code——你在 Cursor 上节省的部分不会出现在公开统计页面上。 - 重写原因会通过
zle -M闪现一次按键时长。安静而非模态。 - 要覆盖智能体场景,下一步计划是引入
PATH垫片(在~/.precc/bin/cargo、~/.precc/bin/git、…… 处放置包装器)。
命令参考
所有PRECC命令的完整参考。
precc init
初始化PRECC并向Claude Code注册钩子。
precc init
Options:
(none)
Effects:
- Registers PreToolUse:Bash hook with Claude Code
- Creates ~/.local/share/precc/ data directory
- Initializes heuristics.db with built-in skills
- Prompts for telemetry consent
precc ingest
挖掘会话日志中的失败-修复模式。
precc ingest [FILE] [--all] [--force]
Arguments:
FILE Path to a session log file (.jsonl)
Options:
--all Ingest all session logs from ~/.claude/logs/
--force Re-process files that were already ingested
Examples:
precc ingest session.jsonl
precc ingest --all
precc ingest --all --force
precc skills
管理自动化技能。
precc skills list
precc skills list
List all active skills (built-in and mined).
precc skills show
precc skills show NAME
Show detailed information about a specific skill.
Arguments:
NAME Skill name (e.g., cargo-wrong-dir)
precc skills export
precc skills export NAME
Export a skill definition as TOML.
Arguments:
NAME Skill name
precc skills edit
precc skills edit NAME
Open a skill definition in $EDITOR.
Arguments:
NAME Skill name
precc skills advise
precc skills advise
Analyze recent sessions and suggest new skills based on repeated patterns.
precc skills cluster
precc skills cluster
Group similar mined skills to identify redundant or overlapping patterns.
precc report
生成分析报告。
precc report [--email]
Options:
--email Send the report via email (requires mail setup)
precc savings
显示token节省。
precc savings [--all]
Options:
--all Show detailed per-command breakdown (Pro)
precc compress
压缩上下文文件以减少token使用。
precc compress [DIR] [--dry-run] [--revert]
Arguments:
DIR Directory or file to compress (default: current directory)
Options:
--dry-run Preview changes without modifying files
--revert Restore files from backup
precc license
管理您的PRECC许可证。
precc license activate
precc license activate KEY --email EMAIL
Arguments:
KEY License key (XXXX-XXXX-XXXX-XXXX)
Options:
--email EMAIL Email address associated with the license
precc license status
precc license status
Display current license status, plan, and expiration.
precc license deactivate
precc license deactivate
Deactivate the license on this machine.
precc license fingerprint
precc license fingerprint
Display the device fingerprint for this machine.
precc mail
电子邮件功能。
precc mail setup
precc mail setup
Interactive SMTP configuration. Saves to ~/.config/precc/mail.toml.
precc mail report
precc mail report EMAIL
Send a PRECC analytics report to the specified email address.
Arguments:
EMAIL Recipient email address
precc mail send
precc mail send EMAIL FILE
Send a file as an email attachment.
Arguments:
EMAIL Recipient email address
FILE Path to the file to send
precc update
将PRECC更新到最新版本。
precc update [--force] [--version VERSION] [--auto]
Options:
--force Force update even if already on latest
--version VERSION Update to a specific version
--auto Enable automatic updates
precc telemetry
管理匿名遥测。
precc telemetry consent
precc telemetry consent
Opt in to anonymous telemetry.
precc telemetry revoke
precc telemetry revoke
Opt out of telemetry. No further data will be sent.
precc telemetry status
precc telemetry status
Show current telemetry consent status.
precc telemetry preview
precc telemetry preview
Display the telemetry payload that would be sent (without sending it).
precc geofence
IP地理围栏合规(Pro)。
precc geofence check
precc geofence check
Check if the current machine is in an allowed region.
precc geofence refresh
precc geofence refresh
Refresh the IP geolocation cache.
precc geofence clear
precc geofence clear
Clear the geofence cache.
precc geofence info
precc geofence info
Display geofence configuration and current status.
precc gif
从bash脚本录制动画GIF(Pro)。
precc gif SCRIPT LENGTH [INPUTS...]
Arguments:
SCRIPT Path to a bash script
LENGTH Maximum recording duration (e.g., 30s, 2m)
INPUTS... Optional input lines for interactive prompts
Examples:
precc gif demo.sh 30s
precc gif interactive.sh 60s "yes" "my-project"
precc gha
分析失败的GitHub Actions运行(Pro)。
precc gha URL
Arguments:
URL GitHub Actions run URL
Example:
precc gha https://github.com/org/repo/actions/runs/12345678
precc cache-hint
显示当前项目的缓存提示信息。
precc cache-hint
precc trial
开始Pro试用。
precc trial EMAIL
Arguments:
EMAIL Email address for the trial
precc nushell
启动带有PRECC集成的Nushell会话。
precc nushell
precc doctor
Self-diagnose a broken or silent install.
precc doctor
Self-diagnose the install: settings.json hook registration, hook binary
path + permissions, and when the hook last fired. Run this first when
`precc savings` reports 0 tokens saved on a fresh install.
Options:
(none)
precc debug
Launch a GDB debugging session for a binary.
precc debug [BINARY] [ARGS...]
GDB-based debugging helper (Pillar 2).
Arguments:
BINARY Binary to debug
ARGS... Arguments to pass to the binary
precc explain
See what PRECC recently rewrote, and why.
precc explain [--since 1h] [--limit 20]
Show recent PRECC rewrites with their diff and the reasons each fired —
the audit trail for what PRECC changed.
Options:
--since SINCE Time window, e.g. "30m", "1h", "24h" (default: 1h)
--limit LIMIT Cap at N most-recent rewrites (default: 20)
precc undo
Undo a specific rewrite by its id.
precc undo ID
Revert a rewrite by id: re-disables the skill(s) that produced it.
Arguments:
ID Rewrite id from `precc explain` (16-hex-char hash)
precc recall
Search your cross-session knowledge mindmap.
precc recall QUERY [--kind KIND] [--limit 20]
Search the cross-session knowledge mindmap for past decisions, plans,
commits, blockers, and commands. Case-insensitive substring, newest first.
Arguments:
QUERY Query string
Options:
--kind KIND Restrict to: decision, plan, task, feature, blocker,
commit, command
--limit LIMIT Cap on hits returned (default: 20)
precc audit
Measure the token cost of your context surfaces.
precc audit <claude-md | claudeignore | positioning>
Measure the token cost of context surfaces. No opinions — just numbers.
Subcommands:
claude-md Bytes, estimated tokens, and per-section sizes of
CLAUDE.md (project + ~/.claude).
claudeignore Per-path bytes/tokens a .claudeignore could exclude from
Grep/Glob/Read (node_modules/, dist/, target/, …).
--write appends missing entries.
positioning Which positioning angles are backed by measured numbers.
precc analyze
Find command classes PRECC does not yet cover.
precc analyze frequencies
Count Bash command-class frequencies from session logs and report the
classes PRECC does not yet cover (rule-gap discovery).
常见问题
PRECC安全吗?
是的。PRECC使用Claude Code官方的PreToolUse钩子机制——Anthropic专门为此目的设计的扩展点。该钩子:
- 完全离线运行(热路径中无网络调用)
- 在5毫秒内完成
- 是fail-open的:如果出现任何问题,原始命令将不受修改地运行
- 只修改命令,从不自己执行它们
- 将数据存储在本地SQLite数据库中
PRECC能与其他AI编码工具一起使用吗?
PRECC专为Claude Code设计。它依赖于Claude Code提供的PreToolUse钩子协议。它不适用于Cursor、Copilot、Windsurf或其他AI编码工具。
遥测发送什么数据?
遥测仅在选择加入后启用。启用后发送:
- PRECC版本、操作系统和架构
- 汇总计数(拦截的命令、激活的技能)
- 平均钩子延迟
它不发送命令文本、文件路径、项目名称或任何个人身份信息。您可以在选择加入前使用 precc telemetry preview 预览确切的数据。详见遥测。
如何卸载PRECC?
PRECC is fully reversible — remove it in three steps:
-
移除钩子注册:
# Delete the hook entry from Claude Code's settings # (precc init added it; removing it disables PRECC) -
删除二进制文件:
rm ~/.local/bin/precc ~/.local/bin/precc-hook ~/.local/bin/precc-learner -
删除数据(可选):
rm -rf ~/.local/share/precc/ rm -rf ~/.config/precc/
我的许可证过期了。会发生什么?
PRECC恢复到社区版。所有核心功能继续正常工作:
- 内置技能保持活跃
- 钩子管道正常运行
precc savings显示摘要视图precc ingest和会话挖掘正常工作
Pro功能在续订前不可用:
precc savings --all(详细分类)precc compressprecc gifprecc ghaprecc geofence- 电子邮件报告
钩子似乎没有运行。如何调试?
Run precc doctor first — it automates every check below. To diagnose by hand:
-
检查钩子是否已注册:
precc init -
手动测试钩子:
echo '{"tool_input":{"command":"cargo build"}}' | precc-hook -
检查二进制文件是否在PATH中:
which precc-hook -
检查
~/.claude/settings.json中的Claude Code钩子配置。
PRECC会减慢Claude Code吗?
不会。钩子在5毫秒内完成(p99)。与Claude推理和生成回复所花费的时间相比,这是不可察觉的。
我可以在CI/CD中使用PRECC吗?
PRECC是为交互式Claude Code会话设计的。在CI/CD中,没有Claude Code实例可以挂钩。但是,precc gha 可以从任何环境分析失败的GitHub Actions运行。
挖掘的技能与内置技能有何不同?
内置技能随PRECC提供,涵盖常见的错误目录模式。挖掘的技能从您的特定会话日志中学习——它们捕获您工作流程中独特的模式。两者都存储在SQLite中,并由钩子管道以相同方式评估。
我可以与团队共享技能吗?
可以。使用 precc skills export NAME 将任何技能导出为TOML并共享文件。团队成员可以将其放在 skills/ 目录中或导入到他们的启发式数据库中。
Why do I see zero tokens saved?
If precc savings reports 0 tokens despite an active Claude Code session burning input/output tokens, the hook is not firing. Three causes account for almost every reported instance:
-
You are on v0.3.42 or v0.3.43. These releases shipped a data-path regression where the hook wrote metrics to a directory that the CLI then read from a different directory — both ran, but the savings number stayed at 0. Fixed in v0.3.44 (data paths routed through
db::data_dir()). Upgrade with:precc update -
Your
settings.jsonis missing the hook entry. Runprecc doctor(available in v0.3.53+). It checks each precondition of the hot path — settings file, hook entry, binary on$PATH, heuristics DB, recent invocations — and reports the first one that fails:precc doctorIf doctor is not available because you are on an older release, run
precc initto (re)register the hook. -
Your session has not yet hit a skill trigger. PRECC only intercepts Bash commands matching one of the active skills. If your session has been pure file editing or pure web fetching against domains not covered by
webfetch-opencli, you have not yet given the hook anything to compress or rewrite. This is normal. Runprecc skills listto see what triggers exist.
If after upgrading and running precc doctor you still see zero savings, file an issue at https://github.com/peri-a-i/precc-cc/issues with the output of precc doctor.
My MCP server (e.g. lean-ctx) is pegging CPU. How do I kill it safely without taking Claude Code down with it?
PRECC does not ship or supervise MCP servers — but this is a recurring trap because some MCP binaries (notably lean-ctx) are also invoked as per-Bash-tool-call wrappers by the Claude Code harness, not just as long-running servers. A naive pkill <name> then matches many short-lived wrappers in addition to the server.
Identify the runaway PID, do not kill by name:
pgrep -f "^lean-ctx$" \
| xargs -I{} ps -o pid,%cpu,etime,args -p {} \
| sort -k2 -nr | head -3
The top row is the long-running server (large etime, high %cpu). Send SIGTERM to only that PID:
kill -TERM <pid>
Avoid these forms, all of which can also kill Claude Code or break in-flight tool calls:
pkill lean-ctx— matches transientlean-ctx -c <cmd>wrappers spawned per Bash tool call.pkill -9 -f lean-ctx— same broad match, plus ungraceful exit leaves the MCP stdio half-open.pkill -g <pgid>/kill -- -<pgid>— kills the whole process group, which includesclaudeitself when the MCP server shares a session with it.
If after a clean SIGTERM the server does not exit within a few seconds, escalate with kill -KILL <pid> on the same single PID (still not by name). Claude Code will lose those MCP tools until you restart it; it should not exit on its own.
This advice is independent of PRECC — but PRECC users frequently run lean-ctx, so it is worth documenting here.
What is OpenCLI and do I need it?
OpenCLI is a third-party Node.js tool that turns ~148 websites into structured-output CLI commands (opencli hackernews top, opencli reddit search <q>, opencli arxiv search <q>, …). PRECC ships two built-in skills that work with it:
webfetch-opencli-hint— fires oncurl/wget/http/fetchagainst any of 11 OpenCLI-supported domains andsuggest_fix-es the equivalentopencli <site> …command. Suggestion only; never modifies the command.webfetch-opencli-hackernews— auto-rewritescurl|wget news.ycombinator.comtoopencli hackernews topwith an inlinecommand -v openclifallback to the original command if OpenCLI isn’t installed.
You don’t need OpenCLI for PRECC to work. The hint skill costs nothing; the auto-rewrite skill is safe to ship default-on because of the fallback.
If you want OpenCLI’s WebFetch token savings, install it with:
precc init --opencli
That runs npm install -g @jackwener/opencli (Node.js 20+ required). For cookie-reuse on logged-in pages, also install OpenCLI’s Chrome extension separately — see the project README. The extension requests broad permissions (debugger, <all_urls>, cookies); review them before installing.
precc doctor reports OpenCLI’s presence on $PATH as an informational line:
i opencli: installed (webfetch-opencli skills will auto-rewrite)
or
i opencli: not installed (run `precc init --opencli` if you want WebFetch token savings)
Never marks doctor as failing — the integration is fully opt-in.