token-efficiency
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseToken Efficiency
Token 效率
Reduce output token waste and prevent iteration cycles that consume context.
减少输出token浪费,避免消耗上下文的迭代循环。
Trigger
触发场景
Use when:
- Sessions feel expensive or slow
- Output is verbose with filler text
- Claude is re-reading files or iterating unnecessarily
- Setting up a new project for token-efficient work
在以下情况使用:
- 会话成本过高或响应缓慢
- 输出冗长且包含冗余文本
- Claude重复读取文件或进行不必要的迭代
- 为高效token使用搭建新项目
Anti-Sycophancy Rules
反谄媚规则
These patterns waste 30-60% of output tokens:
| Pattern | Example | Fix |
|---|---|---|
| Sycophantic opener | "Sure! Great question!" | Delete. Lead with answer. |
| Prompt restatement | "You're asking about X..." | Delete. Answer directly. |
| Closing fluff | "Let me know if you need anything!" | Delete. Stop after the answer. |
| Unsolicited suggestions | "You might also want to..." | Delete unless asked. |
| AI disclaimers | "As an AI model..." | Delete entirely. |
| Verbose preambles | "I'll help you with that..." | Delete. Start with the action. |
这些模式会浪费30-60%的输出token:
| 模式 | 示例 | 修复方案 |
|---|---|---|
| 谄媚式开场白 | "好的!这个问题很棒!" | 删除,直接给出答案。 |
| 重述提示 | "您问的是关于X的问题..." | 删除,直接作答。 |
| 冗余结束语 | "如果您有其他需求请告诉我!" | 删除,给出答案后立即停止。 |
| 主动建议 | "您可能还想..." | 除非被询问,否则删除。 |
| AI免责声明 | "作为AI模型..." | 完全删除。 |
| 冗长前置语 | "我会帮您处理这个问题..." | 删除,直接开始行动。 |
Tool-Call Budgets
工具调用预算
Set explicit budgets by task complexity:
| Task Type | Tool-Call Budget | Wrap-Up At |
|---|---|---|
| Quick fix / lookup | 20 calls | 15 |
| Bug fix | 30 calls | 25 |
| Feature (small) | 50 calls | 40 |
| Feature (large) | 80 calls | 65 |
| Refactor | 50 calls | 40 |
| Exploration / research | 30 calls | 25 |
At the wrap-up threshold: commit progress, assess remaining work, decide whether to continue or start fresh.
根据任务复杂度设置明确的预算:
| 任务类型 | 工具调用预算 | 收尾阈值 |
|---|---|---|
| 快速修复/查询 | 20次调用 | 15次 |
| Bug修复 | 30次调用 | 25次 |
| 小型功能开发 | 50次调用 | 40次 |
| 大型功能开发 | 80次调用 | 65次 |
| 重构 | 50次调用 | 40次 |
| 探索/调研 | 30次调用 | 25次 |
达到收尾阈值时:提交当前进度,评估剩余工作,决定是否继续或重新开始。
One-Pass Coding Discipline
一次性编码准则
For simple-to-medium tasks:
- Read all relevant files including tests first
- Understand what tests assert before coding
- Write complete solution in one pass — not incrementally
- Run tests once — if pass, STOP immediately
- If fail: read the error, fix once, retest
- Never iterate more than twice on the same failure — rethink approach
- Never refactor, improve, or polish passing code
适用于简单到中等难度的任务:
- 先阅读所有相关文件,包括测试文件
- 在编码前理解测试断言的内容
- 一次性写出完整解决方案——不要逐步编写
- 只运行一次测试——如果通过,立即停止
- 如果失败:读取错误信息,修复一次后重新测试
- 针对同一失败的迭代次数不要超过两次——重新思考解决方案
- 不要对已通过测试的代码进行重构、优化或润色
Task Profiles
任务配置文件
Switch profiles based on what you're doing:
根据当前工作切换配置文件:
Coding Profile
编码配置文件
- Return code first, explanation after (only if non-obvious)
- Simplest working solution, no over-engineering
- Read file before modifying — always
- No docstrings on unchanged code
- No error handling for impossible scenarios
- State bug, show fix, stop
- 先返回代码,再给出解释(仅当代码逻辑不明显时)
- 采用最简单的可行方案,避免过度设计
- 修改文件前务必先阅读
- 不对未修改的代码添加文档字符串
- 不为不可能的场景添加错误处理
- 说明问题,展示修复方案,然后停止
Agent/Pipeline Profile
Agent/流水线配置文件
- Structured output only: JSON, bullets, tables
- No prose unless targeting a human reader
- Every output must be parseable without post-processing
- Execute task, do not narrate actions
- Never invent file paths, API endpoints, or function names
- If unknown: return null or "UNKNOWN", never guess
- 仅输出结构化内容:JSON、项目符号、表格
- 除非面向人类读者,否则不使用散文式表述
- 所有输出必须无需后处理即可解析
- 执行任务,不要叙述操作过程
- 切勿编造文件路径、API端点或函数名称
- 如果未知:返回null或"UNKNOWN",切勿猜测
Analysis Profile
分析配置文件
- Lead with finding, context and methodology after
- Tables and bullets over prose
- Numbers must include units
- Never fabricate data points
- Summary first (3 bullets max), caveats last
- 先给出结论,再提供背景和方法
- 优先使用表格和项目符号,而非散文
- 数字必须包含单位
- 切勿编造数据点
- 先给出摘要(最多3个项目符号),最后说明注意事项
Read-Before-Write Enforcement
写前必读强制规则
Hard rules:
- Never write a file you haven't read in this session
- Never re-read a file already read unless it was modified
- Read tests before coding — understand what passes before writing
- Read error output carefully before attempting a fix
硬性规则:
- 切勿编写本次会话中未读取过的文件
- 除非文件已被修改,否则切勿重新读取已读过的文件
- 编码前先阅读测试文件——在编写前先明确通过标准
- 尝试修复前仔细阅读错误输出
ASCII-Only Output
仅ASCII输出
Use ASCII characters only in all output:
- not
--(em dash)— - not
""(smart quotes)" - not
''(curly apostrophes)' - No emoji unless explicitly requested
- No Unicode decorators or special characters
This ensures clean copy-paste for code and compatibility with downstream systems.
所有输出仅使用ASCII字符:
- 使用而非
--(长破折号)— - 使用而非智能引号
"" - 使用而非卷曲撇号
'' - 除非明确要求,否则不使用表情符号
- 不使用Unicode装饰符或特殊字符
这确保代码可干净复制粘贴,并与下游系统兼容。
Measuring Impact
效果衡量
Track these metrics to measure token savings:
- Output length: average words per response (target: 30-50% reduction)
- Tool calls per task: should stay within budget tier
- Re-read count: should be near zero
- Write-without-read count: should be zero
- Iteration cycles: tests should pass in 1-2 attempts, not 5+
跟踪以下指标以衡量token节省情况:
- 输出长度:平均每个响应的单词数(目标:减少30-50%)
- 每项任务的工具调用次数:应保持在对应预算等级内
- 重复读取次数:应接近零
- 未读即写次数:应为零
- 迭代周期:测试应在1-2次尝试内通过,而非5次以上
Attribution
致谢
Token efficiency patterns adapted from drona23/claude-token-efficient (MIT).
Token效率模式改编自drona23/claude-token-efficient(MIT协议)。