节省
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
Status Bar
After installation, PRECC wires a statusLine entry into ~/.claude/settings.json so the Claude Code status bar shows live session metrics:
$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)
Each segment:
| Segment | Source | Meaning | Resets on session restart? |
|---|---|---|---|
$0.42 spent | Claude Code’s cost.total_cost_usd | Cumulative session cost reported by Claude Code | Yes |
1.2M in/out | Claude Code’s total_input_tokens + total_output_tokens | Non-cached input + output tokens across the session | Yes |
📊 last cmd: −1.2K | PRECC measurement of the most recent Bash command | Real ground-truth saving from re-running the original | No (persists across sessions) |
PRECC: 7 fixes | PRECC session aggregate from metrics.log | Number of corrections this session — fix count only, no fake token estimate | Yes |
5.8ms avg | PRECC hook latency p50 | Time PRECC spent processing each tool call | Yes |
bash 18% of total | PRECC post_observations.log filtered by session window | Share of session tokens that came from Bash output — clarifies why PRECC’s savings are naturally a fraction of total cost (PRECC only optimizes Bash output) | Yes |
this session: 320 saved over 7 cmds (~$0.05) | ~/.local/share/precc/.lifetime_summary.json minus the per-session baseline at ~/.local/share/precc/sessions/<session_id>.savings_baseline | Real per-session delta. Baseline is captured the first time PRECC sees this session_id; subsequent refreshes compute current_lifetime − baseline so the value reflects savings accrued in this session only. Hidden when delta is zero (start of session) | Yes (baseline re-snapshots) |
lifetime: 8.9K saved over 217 cmds (~$2.85) | ~/.local/share/precc/.lifetime_summary.json + current session’s cost.total_cost_usd / total_used_tokens rate | Cumulative tokens saved and re-measured commands since PRECC was first installed, plus an estimated USD value computed from the current session’s per-token rate. Cost estimate is conservative — it uses (input+output) as the denominator while the cost includes cache tokens, so the per-token rate is overstated and the resulting savings figure is lower than actual | No |
The lifetime: segment is placed last so it’s the first to be truncated if Claude Code’s UI clips the bar at the right edge.
Why cost and token count don’t divide
The displayed 1.2M in/out is not the denominator that produced $0.42 spent. Claude Code’s cost.total_cost_usd is computed from the API’s full token breakdown — base input, output, plus cache reads and cache creations. The session-wide cumulative cache token counts are not exposed in the statusline schema, so PRECC can only show the visible (non-cache) portion.
On long sessions with heavy file rereads, cache reads can be 10× the visible token count. That’s why pairing the two as a ratio would mislead — PRECC shows them as independent segments instead.
Why PRECC doesn’t compute the cost
The cost number is authoritative. PRECC reads cost.total_cost_usd verbatim from the JSON Claude Code pipes into the status command on stdin. That’s the same number Claude Code charges against your subscription/usage budget. You can verify it any time with the built-in /cost slash command — both should agree.
What drives the cost
For 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 |
The biggest drivers on long sessions are usually:
- Output tokens — most expensive per-token type, especially on the 1M context tier
- Repeated cache reads — cheap individually but accumulate fast across many turns
- Cache creations — written once per file read, ~1.25× the base input rate
PRECC reduces the visible-token cost by compressing Bash output (the 📊 last cmd: segment shows the per-command saving), but it cannot reduce cache reads of files Claude has already loaded.
Stable session counts
The “PRECC: N fixes” segment counts events since the persisted session start, written to ~/.local/share/precc/sessions/<session_id>.start on the first statusline refresh of each session. This makes the count monotonic — it cannot drop mid-session even if cost.total_duration_ms is missing on a particular refresh (which would otherwise collapse the window to “since now” and silently drop nearly all events).
Auto-refreshed lifetime snapshot
The lifetime: segment reads ~/.local/share/precc/.lifetime_summary.json, which is rewritten:
- On every PostToolUse measurement (so it stays current as commands accumulate)
- On every
precc savingsinvocation
The this session: segment reads the same lifetime file but subtracts a per-session baseline persisted to ~/.local/share/precc/sessions/<session_id>.savings_baseline on the first refresh of each session.
No need to manually refresh anything — the files update themselves.
Suppressing the status bar
If you’d rather keep your existing status bar, set your own statusLine command in ~/.claude/settings.json. PRECC’s installer will detect the custom value and leave it alone on subsequent updates.
To suppress only the per-interaction 📊 PRECC line (in additionalContext), set PRECC_QUIET=1 in your shell environment.