docs/token-optimization.md
Practical settings and habits to reduce token consumption, extend session quality, and get more work done within daily limits.
See also:
rules/common/performance.mdfor model selection strategy,skills/strategic-compact/for automated compaction suggestions.
These are recommended defaults for most users. Power users can tune values further based on their workload — for example, setting MAX_THINKING_TOKENS lower for simple tasks or higher for complex architectural work.
Add to your ~/.claude/settings.json:
{
"model": "sonnet",
"env": {
"MAX_THINKING_TOKENS": "10000",
"CLAUDE_CODE_SUBAGENT_MODEL": "haiku"
}
}
| Setting | Default | Recommended | Effect |
|---|---|---|---|
model | opus | sonnet | Sonnet handles ~80% of coding tasks well. Switch to Opus with /model opus for complex reasoning. ~60% cost reduction. |
MAX_THINKING_TOKENS | 31,999 | 10,000 | Extended thinking reserves up to 31,999 output tokens per request for internal reasoning. Reducing this cuts hidden cost by ~70%. Set to 0 to disable for trivial tasks. |
CLAUDE_CODE_SUBAGENT_MODEL | (inherits main) | haiku | Subagents (Task tool) run on this model. Haiku is ~80% cheaper and sufficient for exploration, file reading, and test running. |
Some recent Claude Code builds have community reports that CLAUDE_AUTOCOMPACT_PCT_OVERRIDE can only lower the compaction threshold, which means values below the default may compact earlier instead of later. If that happens in your setup, remove the override and rely on manual /compact plus ECC's strategic-compact guidance. See Troubleshooting.
Use the right model for the task:
| Model | Best for | Cost |
|---|---|---|
| Haiku | Subagent exploration, file reading, simple lookups | Lowest |
| Sonnet | Day-to-day coding, reviews, test writing, implementation | Medium |
| Opus | Complex architecture, multi-step reasoning, debugging subtle issues | Highest |
Switch models mid-session:
/model sonnet # default for most work
/model opus # complex reasoning
/model haiku # quick lookups
| Command | When to use |
|---|---|
/clear | Between unrelated tasks. Stale context wastes tokens on every subsequent message. |
/compact | At logical task breakpoints (after planning, after debugging, before switching focus). |
/cost | Check token spending for the current session. |
The strategic-compact skill (in skills/strategic-compact/) suggests /compact at logical intervals rather than relying on auto-compaction, which can trigger mid-task. See the skill's README for hook setup instructions.
When to compact:
When NOT to compact:
Use subagents (Task tool) for exploration instead of reading many files in your main session. The subagent reads 20 files but only returns a summary — your main context stays clean.
Each enabled MCP server adds tool definitions to your context window. The README warns: keep under 10 enabled per project.
Tips:
/mcp to see active servers and their context costgh instead of GitHub MCP, aws instead of AWS MCP)disabledMcpServers in project config to disable servers per-projectmemory MCP server is configured by default but not used by any skill, agent, or hook — consider disabling itAgent Teams (experimental) spawns multiple independent context windows. Each teammate consumes tokens separately.
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in settingsThe configure-ecc install wizard could offer to set these environment variables during setup, with explanations of the cost tradeoffs. This would help new users optimize from day one rather than discovering these settings after hitting limits.
# Daily workflow
/model sonnet # Start here
/model opus # Only for complex reasoning
/clear # Between unrelated tasks
/compact # At logical breakpoints
/cost # Check spending
# Environment variables (add to ~/.claude/settings.json "env" block)
MAX_THINKING_TOKENS=10000
CLAUDE_CODE_SUBAGENT_MODEL=haiku
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1