Token optimization (Gemini CLI)
July 20, 2026 · View on GitHub
This extension adds the token-optimizer MCP server. Its tools cut context/token
usage 60–90% via caching, diffing, and compression. Prefer them:
smart_readinstead of reading a file directly when the file is large (>~400 lines / >25 KB) or already read this session — re-reads return a diff.smart_globinstead of a content grep on a big/unknown tree — returns paths only; read only what you need.smart_editon large files — returns a compact diff, not the whole file.optimize_sessionwhen context fills up;get_session_statsfor savings.get_optimization_reportto show the user total tokens saved with a full breakdown by action/hook/server (returns a ready-to-displayformattedsummary).optimize_textto stash bulky text out-of-context under a key.compress_textis at-rest byte compression only — its base64 output usually costs more tokens, so never put it back into context.count_tokensto measure a chunk first.
Small files / one-off reads: built-in reading is fine — don't add overhead.