Cutting Claude Code token usage, the parts that actually matter
说明与用途
通过限制始终加载的内容、禁用未使用的 MCP 服务器、清除历史记录以及使用 PreToolUse 钩子阻止不必要的文件读取,优化 Claude Code 的令牌使用。
问题
Claude Code sessions resend all context, causing high token usage for files and commands that are rarely needed.
结果
Token usage is reduced by preventing large, unnecessary reads and outputs while maintaining essential functionality.
工作流
- Run /context to view current context size
- Keep CLAUDE.md under 200 lines and move workflow‑specific instructions to skills
- Disable unused MCP servers with /mcp
- Use /clear between unrelated tasks or /compact to keep only needed parts
- Implement a PreToolUse hook to deny full reads of lockfiles, minified files, source maps, node_modules, .venv, .next, coverage, binaries, and allow targeted reads with offset/limit or grep
- Use quiet reporters and single‑test commands to reduce Bash output
- Place exact commands in CLAUDE.md for reliable execution
证据
Every message you send in a Claude Code session re-sends what's already in context: the system prompt, your CLAUDE.md, MCP server instructions, and every file and command output from earlier in the session.
A PreToolUse hook runs before every tool call and can deny it with a reason the model reads.
I published this as token-diet-lite: one stdlib Python file, MIT.
- 记录日期: 2026-10-25T21:11:10.412Z