context_mastery
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Mastery & Token Optimization Protocol
上下文精通与Token优化协议
1. The "Grep-First" Rule (Token Saver)
1. “Grep优先”规则(Token节省方案)
- Problem: on a 2000-line file consumes ~500-1000 tokens instantly.
read_file - Solution: Always use or
grepfirst to inspect specific functions or imports.read_file_range - Banned: or
caton entire directories or massive files (e.g.,read_file, giant logs) unless absolutely necessary.package-lock.json
- 问题:对2000行文件执行会立即消耗约500-1000个Token。
read_file - 解决方案:始终优先使用或
grep来检查特定函数或导入内容。read_file_range - 禁止操作:除非绝对必要,否则不要对整个目录或超大文件(如、大型日志文件)执行
package-lock.json或cat。read_file
2. Incremental Summarization
2. 增量摘要
- Trigger: When the conversation exceeds ~20 turns or you feel the context window filling.
- Action:
- Summarize what has been achieved in the last 10 turns.
- Write it to or
scratchpad.md.active_task.md - Explicitly state "I am clearing internal context of validated steps" (if tool allows) or just rely on the scratchpad for future lookup.
- 触发条件:当对话超过约20轮,或你感觉到上下文窗口即将被占满时。
- 操作步骤:
- 总结最近10轮对话中已完成的工作。
- 将总结内容写入或
scratchpad.md。active_task.md - 明确声明“我正在清除已验证步骤的内部上下文”(如果工具支持的话),或者后续直接依赖草稿文件进行查阅。
3. Focused Context Loading
3. 聚焦式上下文加载
- Don't: "Read all files in to understand the project." (Too expensive).
src/ - Do:
- Read /
CLAUDE.md.README.md - Read directory listing .
ls -R - Selectively read only the interfaces () or entry points (
types.ts) related to the current task.index.ts
- Read
- 避免操作:“读取目录下的所有文件以了解项目”(成本过高)。
src/ - 推荐操作:
- 读取/
CLAUDE.md。README.md - 读取目录列表。
ls -R - 仅选择性地读取与当前任务相关的接口文件(如)或入口文件(如
types.ts)。index.ts
- 读取
4. Context Efficiency Checklist
4. 上下文效率检查表
- Did I use instead of reading the whole file?
grep - Did I check if I already have this info in ?
MEMORY.md - Is my next prompt efficient? (Avoid repeating massive code blocks back to the user).
- 我是否使用替代了读取整个文件?
grep - 我是否检查过中已有相关信息?
MEMORY.md - 我的下一个提示词是否高效?(避免向用户重复大段代码块)