Cutting Claude Code token usage, the parts that actually matter
Описание и применение
Оптимизация использования токенов в Claude Code достигается за счёт ограничения всегда‑загружаемого контента, отключения неиспользуемых серверов MCP, очистки истории и применения хуков PreToolUse для запрета ненужных чтений файлов.
Задача
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