Grok Build
Data and hooks
Section titled “Data and hooks”The adapter reads Grok session usage/signals and maintains a local in-flight tally for crash recovery. Complete host costUsdTicks values are converted at 10 billion ticks per USD. Incomplete or partial costs are marked unknown, not free; Token Optimizer does not invent a savings headline from them. contextWindowTokens is authoritative when present, with a 256K fallback.
The installer owns <grok-home>/hooks/token-optimizer.json and a copied payload under <grok-home>/token-optimizer/plugin/; it does not replace another plugin’s hook file.
| Event | Adapter action |
|---|---|
| SessionStart | Initialize token tally and sweep stale locks; passive stdout ignored |
| UserPromptSubmit | Session bookkeeping |
| PreToolUse (Bash) | Eligible command rewrite through the shared compressor |
| PostToolUse | Token tally and context-growth nudge |
| Stop | Throttled rollup and dashboard refresh |
Compression remains contract-tested, not live-verified. The adapter does not replace native compaction. SessionStart and allowing UserPromptSubmit stdout are ignored under its contract, so this bridge does not promise a continuity restore at those seams. Nudges can use a tool-call proxy (30 and 80 calls); they are not exact occupancy readings.
Run and verify
Section titled “Run and verify”Follow Grok Build install. Every Python command uses the Grok runtime:
TOKEN_OPTIMIZER_RUNTIME=grok python3 skills/token-optimizer/scripts/measure.py grok-doctor --probeTOKEN_OPTIMIZER_RUNTIME=grok python3 skills/token-optimizer/scripts/measure.py grok-summaryTOKEN_OPTIMIZER_RUNTIME=grok python3 skills/token-optimizer/scripts/measure.py dashboard --serveThe shared dashboard serves at http://localhost:24848/token-optimizer. The home defaults to ~/.grok; TOKEN_OPTIMIZER_GROK_HOME overrides only Token Optimizer’s view, ahead of host GROK_HOME. See Configuration and the CLI reference.
The shared engine reserves port 24848, but the foreign-runtime guard blocks setup-daemon for Grok. Use the foreground dashboard command above; do not confuse a port assignment with a working persistent install command.
