Files
knowledge-base/6 - Zettelkasten/20260308213200 Everything Claude Code Token 优化.md
Yaojia Wang ad79665527 Sync
2026-03-14 20:23:32 +01:00

48 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
created: "2026-03-08 21:32"
type: zettel
tags: [claude-code, token-optimization, cost]
source: "https://github.com/affaan-m/everything-claude-code"
---
# Everything Claude Code Token 优化
## 节省 60%+ 成本的四个策略
### 1. 模型路由
90% 任务用 SonnetHaiku 做搜索/文档Opus 只用于架构和安全。用 `/model-route` 自动路由。
### 2. MCP 精简
- 保持 < 10 MCP 启用
- CLI + skill 替代 MCP wrapper gh CLI 替代 GitHub MCP
- 每个 MCP 消耗上下文窗口多到一定程度 200k 70k
### 3. 工具替换
mgrep 替代 grep/ripgrep 50 任务 benchmark 中减少约 2x token 使用
### 4. 代码模块化
文件保持 200-400 最大 800)。模块化代码库让 agent 不需要读取大文件减少上下文消耗且首次成功率更高
## 配置
```json
{
"model": "sonnet",
"env": {
"MAX_THINKING_TOKENS": "10000",
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
}
}
```
## Skill 的渐进式加载
Skill 启动时只读描述 100 tokens只在相关时才加载完整内容这比把所有内容放在 CLAUDE.md 系统提示中高效得多
---
## Related
- [[Everything Claude Code 最佳实践]]
- [[Everything Claude Code Agent 编排模式]]