Token optimization
First inspect the current tool inventory. Use a named token-optimizer MCP tool
only when that exact schema is visible; an installed plugin or MCP config is not
proof that its server registered successfully. If the tool is absent, keep the
native operation available, bound its output, and do not retry an unavailable
schema.
When registered, these tools cache, diff, and bound context. The native hook
refuses a built-in call only after positive registration evidence and injects
applicable graph findings; the active model still makes every MCP tool call.
When to use which tool
smart_read instead of a plain file read when a file is large
(roughly >400 lines / >25 KB) or you have read it before this session. It
caches file content and, on re-reads, returns only a diff of what changed
— often a handful of tokens instead of the whole file. Pass path; optionally
enableCache, diffMode, maxSize, includeMetadata.
smart_glob instead of a content grep for finding files in a big or
unfamiliar tree. It returns paths only (no content) with filtering,
sorting, and pagination — a fraction of the tokens of listing with content.
Pass pattern (e.g. src/**/*.ts) and optionally cwd, extensions,
limit.
smart_edit instead of a raw edit for large files: it applies the
edit and returns a compact unified diff rather than echoing the whole
file. (For very small files a plain edit is fine — smart_edit's diff overhead
is only worth it once the file is sizeable.)
optimize_session / get_session_stats when the context window is
filling up or after a burst of file operations. optimize_session
batch-compresses prior file operations and stores them out-of-context;
get_session_stats reports tokens saved so far.
get_optimization_report when the user asks how much they've saved
(or to show it proactively). Returns total tokens saved, overall savings %,
approximate cost saved, and a full breakdown by action, by hook phase, and
by MCP server, plus a pre-rendered formatted text summary you can display
as-is.
count_tokens to measure how expensive a chunk of text is before you
decide how to handle it.
Live graph
- When
wiki_write is visible, call it when you establish a durable,
non-obvious conclusion:
a failed approach and why, a decision and its rejected alternative, or a
command that finally worked. Anchor it to a real file or path#symbol, and
include its concrete evidence, applicability, calibrated confidenceLabel,
scope, and invalidators.
- Perform this semantic harvest yourself while you still hold the reasoning.
Do not delegate it to another model, and do not invent a finding merely to
populate the graph.
- If
wiki_write is absent, do not claim semantic harvesting succeeded.
- Applicable findings are injected automatically when their file or command is
touched. Use
wiki_read for an explicit lookup.
Storing bulky content out of context
optimize_text — compress a large text blob under a key and keep it in
the external cache instead of your context; retrieve it later by key. Reports
tokensSaved. Good for logs, large outputs, or reference material you don't
need inline right now.
compress_text — Brotli+base64 compression. Byte reduction only:
the base64 output usually has more LLM tokens than the input, so use it
for at-rest storage/caching, not for putting back into context. The tool
returns increasesTokens + a warning when that's the case.
Rules of thumb
- Reading a big file or one you've seen before →
smart_read.
- Searching a large/unknown tree →
smart_glob (paths first, read only what
you need).
- Editing a large file →
smart_edit.
- Context getting tight →
optimize_session, then continue.
- Need to stash bulky output →
optimize_text (by key), not compress_text
into context.
- Small files/one-off reads → the built-in tools are fine; don't add overhead.
1---2name: token-optimization3description: Use the token-optimizer MCP tools to reduce context/token usage when reading, searching, or editing files, or when the context window is filling up. Trigger when reading large files, re-reading files already seen, searching a big/unknown tree, making edits to large files, or when you need to store bulky output out-of-context.4metadata:5 source: https://skillmd.com/skills/hashgraph-online/token-optimization6---78# Token optimization910First inspect the current tool inventory. Use a named token-optimizer MCP tool11only when that exact schema is visible; an installed plugin or MCP config is not12proof that its server registered successfully. If the tool is absent, keep the13native operation available, bound its output, and do not retry an unavailable14schema.1516When registered, these tools cache, diff, and bound context. The native hook17refuses a built-in call only after positive registration evidence and injects18applicable graph findings; the active model still makes every MCP tool call.1920## When to use which tool2122- **`smart_read`** instead of a plain file read when a file is **large**23 (roughly >400 lines / >25 KB) or you have **read it before this session**. It24 caches file content and, on re-reads, returns only a **diff** of what changed25 — often a handful of tokens instead of the whole file. Pass `path`; optionally26 `enableCache`, `diffMode`, `maxSize`, `includeMetadata`.2728- **`smart_glob`** instead of a content grep for finding files in a **big or29 unfamiliar tree**. It returns **paths only** (no content) with filtering,30 sorting, and pagination — a fraction of the tokens of listing with content.31 Pass `pattern` (e.g. `src/**/*.ts`) and optionally `cwd`, `extensions`,32 `limit`.3334- **`smart_edit`** instead of a raw edit for **large files**: it applies the35 edit and returns a compact unified **diff** rather than echoing the whole36 file. (For very small files a plain edit is fine — smart_edit's diff overhead37 is only worth it once the file is sizeable.)3839- **`optimize_session`** / **`get_session_stats`** when the **context window is40 filling up** or after a burst of file operations. `optimize_session`41 batch-compresses prior file operations and stores them out-of-context;42 `get_session_stats` reports tokens saved so far.4344- **`get_optimization_report`** when the user asks **how much they've saved**45 (or to show it proactively). Returns total tokens saved, overall savings %,46 approximate cost saved, and a full breakdown **by action, by hook phase, and47 by MCP server**, plus a pre-rendered `formatted` text summary you can display48 as-is.4950- **`count_tokens`** to measure how expensive a chunk of text is before you51 decide how to handle it.5253## Live graph5455- When **`wiki_write`** is visible, call it when you establish a durable,56 non-obvious conclusion:57 a failed approach and why, a decision and its rejected alternative, or a58 command that finally worked. Anchor it to a real file or `path#symbol`, and59 include its concrete evidence, applicability, calibrated `confidenceLabel`,60 scope, and invalidators.61- Perform this semantic harvest yourself while you still hold the reasoning.62 Do not delegate it to another model, and do not invent a finding merely to63 populate the graph.64- If `wiki_write` is absent, do not claim semantic harvesting succeeded.65- Applicable findings are injected automatically when their file or command is66 touched. Use **`wiki_read`** for an explicit lookup.6768## Storing bulky content out of context6970- **`optimize_text`** — compress a large text blob under a `key` and keep it in71 the external cache instead of your context; retrieve it later by key. Reports72 `tokensSaved`. Good for logs, large outputs, or reference material you don't73 need inline right now.7475- **`compress_text`** — Brotli+base64 compression. **Byte** reduction only:76 the base64 output usually has **more** LLM tokens than the input, so use it77 for **at-rest storage/caching, not for putting back into context.** The tool78 returns `increasesTokens` + a warning when that's the case.7980## Rules of thumb81821. Reading a big file or one you've seen before → `smart_read`.832. Searching a large/unknown tree → `smart_glob` (paths first, read only what84 you need).853. Editing a large file → `smart_edit`.864. Context getting tight → `optimize_session`, then continue.875. Need to stash bulky output → `optimize_text` (by key), not `compress_text`88 into context.896. Small files/one-off reads → the built-in tools are fine; don't add overhead.