How to Optimize Token Usage in ECC: 7 Proven Strategies for Efficient AI Coding

Optimize token usage in ECC by lazy-loading skills via trigger tables, manually compacting context at logical boundaries, replacing heavy tools like grep with mgrep, and leveraging the built-in token-optimizer MCP and cost-tracking skill.

Everything Claude Code (ECC) is an open-source framework for AI-assisted software development where token consumption directly impacts cost and context window availability. Optimizing token usage in ECC requires a multi-layered approach spanning runtime configuration, skill design, and tool selection to keep prompt sizes minimal while maintaining productivity. The repository provides concrete guidance in files like skills/strategic-compact/SKILL.md and the-longform-guide.md that you can implement immediately.

Load Only What You Need with Trigger-Table Lazy Loading

Lazy-loading defers the loading of full skill definitions until a relevant keyword appears in the conversation. Each skill typically adds 1–5 KB of tokens to every session, so deferring this cost until necessary provides immediate savings.

According to skills/strategic-compact/SKILL.md, the trigger-table approach works by mapping keywords to skills. For example, the system loads the tdd-workflow skill only when the user mentions "test", "coverage", or "tdd" rather than loading it at session start.


# Example snippet from a custom skill definition

trigger: "security|auth|xss"
skill: security-review
load_when: "User mentions security"

The skill remains unloaded (zero token cost) until the trigger condition fires, keeping the baseline context window lean.

Replace MCPs with Thin Skills

Certain Model Context Protocol (MCP) servers, such as those for GitHub or Supabase, inject large "system prompt" blobs into every turn. As noted in the-longform-guide.md, you can often replace an MCP call with a thin skill or command that invokes the CLI directly, shaving hundreds of tokens per interaction. This MCP replacement pattern is particularly effective for frequently used integrations where a simple shell command suffices.

Compact Context at Logical Boundaries

Manual /compact commands clear the session's transient context while preserving files, Git state, and persisted memory. The Strategic Compact skill in skills/strategic-compact/SKILL.md provides a compaction decision guide recommending you run this command after research phases, after reaching milestones, or before major context shifts.


# After a planner run that writes plan.md

/compact Focus on implementation now – keep plan.md

This command clears the chat history while preserving plan.md on disk, preventing the plan’s prose from inflating future prompts and stopping "context rot" that otherwise drives up token counts.

Replace Heavy-Weight Tools with Token-Friendly Alternatives

Switching from standard shell tools to ECC-optimized alternatives yields significant savings. The mgrep utility drops the token cost of file-search commands by roughly 50% compared to standard grep, as benchmarked in the-longform-guide.md.


# Before (≈ 30 tokens per call)

bash "grep -rn \"TODO\" src/**/*.ts" \
  description "Search for TODO comments"

# After (≈ 15 tokens per call)

bash "mgrep \"TODO\" src/**/*.ts" \
  description "Search for TODO comments with token-friendly mgrep"

Additionally, avoid redundant cat or head calls. Use the dedicated Read, Grep, and Glob tools provided by the harness instead of ad-hoc shell commands, as each extra shell line expands the prompt with unnecessary syntax.

Use the Token-Budget Advisor Skill

When you need a concise answer, the token-budget-advisor skill inserts a short-answer tier (e.g., "Essential (25%)") and trims the response length accordingly. Defined in skills/token-budget-advisor/SKILL.md, this skill can be invoked automatically from any command or manually via the !budget trigger.


# User asks for a short answer

!budget essential

The skill then replies with a concise, 25%-token answer, automatically respecting the budget and preventing verbose explanations when brevity is required.

Leverage the token-optimizer MCP

The token-optimizer MCP performs content deduplication across the entire session, offering greater than 95% token reduction for repetitive text such as repeated rule blocks. As documented in the "Context Optimization Tools" section of skills/strategic-compact/SKILL.md, this optimizer strips duplicated sections before sending them to the model.


# .claude/mcp-configs/mcp-servers.yaml

servers:
  - name: token-optimizer
    url: https://token-optimizer.mcp.example.com
    tools: [Read, Write, Edit, Bash]

All subsequent tool calls pass through the optimizer, which removes redundancy while preserving semantic meaning.

Structure Projects for Modularity

Keeping core files under a few hundred lines reduces the baseline token load for each edit session. The the-longform-guide.md notes that a modular codebase saves both tokens and mental overhead, as smaller files require less context to understand and modify. This architectural choice compounds your savings when combined with the lazy-loading strategies above.

Monitor Token Usage Continually

The cost-tracking skill logs every tool call with its estimated token count, allowing you to spot hot-spots early and refactor offending workflows. Defined in skills/cost-tracking/SKILL.md, this continuous monitoring creates feedback loops where you can identify which agents or tools consume the most tokens and adjust accordingly.

Summary

  • Lazy-load skills using trigger tables in skills/strategic-compact/SKILL.md to defer token costs until keywords appear.
  • Run /compact at logical boundaries to clear transient chat history while preserving important files.
  • Replace grep with mgrep and avoid shell wrappers to cut file-search token costs by 50%.
  • Invoke !budget or the token-budget-advisor skill to enforce answer-length tiers automatically.
  • Enable the token-optimizer MCP for 95%+ deduplication of repetitive context.
  • Maintain modular file structures to minimize baseline context per session.
  • Use the cost-tracking skill to monitor per-tool token consumption and identify optimization opportunities.

Frequently Asked Questions

What is the fastest way to reduce token usage in a new ECC session?

Enable trigger-table lazy loading for your custom skills. By adding trigger conditions to your skill definitions in skills/strategic-compact/SKILL.md, you ensure that heavy system prompts only load when specific keywords appear, keeping the initial context window minimal from the first message.

When should I use manual /compact instead of automatic compaction?

Use manual /compact after completing discrete phases of work, such as finishing research or reaching a milestone, as recommended in the Compaction Decision Guide. Automatic compaction may trigger too early or too late; manual control ensures you preserve critical context like plan.md while clearing the conversational history that no longer serves the current task.

How much token savings does mgrep provide compared to standard grep?

According to benchmarks in the-longform-guide.md, mgrep reduces token costs by approximately 50% compared to standard grep commands. This is achieved through both shorter command syntax and more compact result formatting, making it the preferred tool for file-search operations within ECC.

Can I track which specific tools consume the most tokens in ECC?

Yes. The cost-tracking skill defined in skills/cost-tracking/SKILL.md provides per-tool token accounting. It logs every tool call with its estimated token count, allowing you to analyze usage patterns and identify hot-spots where replacing a tool or refactoring a workflow could yield significant savings.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →