token-cost
Measure before optimizing — estimate token counts locally with stated heuristics, price them at your model's rates, and quantify before/after saving…
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Token Cost Skill
Every token optimization should start and end with the same question: how many, at what price, how often? — and most skip all three. This skill is the measurement layer: local token estimates (two stated heuristics, averaged, no tokenizer dependencies), cost math at your model's prices (supplied, never baked in — prices change faster than repos), and the before/after comparison that turns "this feels smaller" into "saves 4,200 tokens, $1.26 per hundred calls." The honest core: a 40% saving on something sent once is a rounding error; 8% on something sent every call is real money — the --calls flag is the whole insight.
What This Skill Produces
- The estimate — chars/4 and words×4/3, both shown, averaged, with the ±15% honesty label
- The cost math — per call and across the stated call volume, at supplied prices
- The comparison — before vs. after any optimization: tokens saved, percent, dollars at volume
- The verdict frame — worth-it / not-worth-it, decided by volume × savings vs. the optimization's own complexity
Required Inputs
Ask for these if not provided:
- The content — file or text to measure; for comparisons, both versions
- The prices — the model's $/M input (and output if relevant) — from the user's provider page, today's, because baked-in prices are stale prices
- The volume — how many calls this content rides along on (a system prompt rides every call; a one-shot report rides one) — the multiplier that decides everything
Programmatic Helper
python3 scripts/token_cost.py --file context.md --price-in 3 --calls 200
python3 scripts/token_cost.py --file original.json --compare crushed.json --price-in 3 --calls 200
Deterministic, stdlib-only. Two heuristics (≈4 chars/token, ≈0.75 words/token) averaged and labeled as estimates — real tokenizers vary by model and content type, and the script says so on every run rather than cosplaying as one.
Framework: The Measurement Rules
- Volume is the multiplier that matters: cost = tokens × price × calls — and calls is the term intuition drops. System prompts, standing context, and per-turn tool schemas ride every call; optimizing them compounds. One-shot content barely matters however big it is. Every measurement states its volume assumption.
- Measure both sides of an optimization: the crushed version's savings minus what the optimization itself costs (a crush header, an index that must also be loaded, engineering time) — comparisons that only count the win are marketing.
- Estimates are estimates, loudly: the ±15% label is permanent; decisions that need exact counts (billing disputes, hard context limits) need the provider's tokenizer, and the skill says so instead of faking precision. For is-this-worth-it decisions, ±15% is plenty.
- Price the journey's stages separately: input tokens (usually cheap, high volume), output tokens (usually 3–5× the price — why output discipline like [token-diet](../token-diet/SKILL.md) pays disproportionately), and cached-input rates where the provider offers them (stable prefixes can cost ~10% of fresh input — measurement should know which bucket content falls in).
- The worth-it verdict is a sentence, not a spreadsheet: "saves $0.31 per hundred calls; the crush step is one pipe — worth it" or "saves 60 tokens once; skip." Every measurement ends in one, because the point of measuring was deciding.
Output Format
Token Cost: [content] — at $[X]/M × [N] calls
[Script output: both heuristics, the estimate, the cost lines]
[Comparison mode: the before/after with savings at volume]
The verdict: [worth-it / not-worth-it, in one sentence with the reasoning]
Estimates ±15%; prices supplied by you, dated today; exact counts need the provider's tokenizer.
Quality Checks
- [ ] Both heuristics shown, average labeled as an estimate
- [ ] Prices came from the user, never from memory
- [ ] The call-volume assumption is explicit in every cost figure
- [ ] Comparisons subtract the optimization's own cost
- [ ] The measurement ends in a worth-it sentence
Anti-Patterns
- [ ] Do not recite model prices from memory — they change; ask for today's
- [ ] Do not present heuristic counts as tokenizer truth — the ±15% label is load-bearing
- [ ] Do not optimize unmeasured — "feels smaller" has shipped many complexity-positive savings
- [ ] Do not ignore volume — the same 500 tokens is negligible once and structural at every-call
- [ ] Do not end without the verdict — a measurement that doesn't decide anything measured nothing
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
plugins/pm-tokens/skills/token-cost/SKILL.md同一个仓库里的其他技能
同名技能的其他版本
有 3 个不同仓库或目录里都有叫 token-cost 的技能。它们内容并不相同,别混用:
- mohitagw15856/pm-claude-skills — Measure before optimizing — estimate token counts locally with stated heuristics, price th
- mohitagw15856/pm-claude-skills — Measure before optimizing — estimate token counts locally with stated heuristics, price th