token-usage-meter

Monitors xAI Grok session token usage and prompt-cache hit rates with cost estimates.

Updated Jun 17, 2026
One-click install
npx skills add https://github.com/ndestates/ndestates-website --skill token-usage-meter-ndestates
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: token-usage-meter
Source: https://github.com/ndestates/ndestates-website/tree/main/.copilot/skills/token-usage-meter
Command: npx skills add https://github.com/ndestates/ndestates-website --skill token-usage-meter-ndestates

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Tracking token consumption and prompt-cache efficiency across Grok Build sessions is manual and error-prone, making it hard to detect context bloat, cache misses, and rising API costs before they degrade performance. ## Core Features & Use Cases - Session Context Monitoring: Syncs totalTokens from Grok updates.jsonl logs into reports/tokens/ and warns when context exceeds 100k tokens or a single turn grows by 15k tokens. - Prompt-Cache Analysis: Parses xAI API usage JSON to compute cache hit rates and flags POOR status when cached_tokens is zero on substantial prompts. - Cost Estimation: Applies per-model pricing from references/pricing.json to estimate session and per-turn spend, including cache savings versus no-cache baselines. - Use Case: During a long coding session, the agent appends a one-line Token meter footer to each response showing context size, turn delta, and estimated cost, and warns you to summarize the thread when context approaches 128k tokens. ## Quick Start Ask the agent to run the token monitor sync and show the current session's token usage, cache status, and estimated cost.

Frequently Asked Questions about token-usage-meter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I monitor token usage in Grok Build sessions?▼

Run token_monitor.py with the --sync flag to parse the session's updates.jsonl file and log per-turn token counts to reports/tokens/. Use --footer to print a one-line summary showing context size, turn delta, and estimated cost.

How to check xAI API prompt cache hit rate?▼

Pipe the API response's usage JSON into analyze_token_usage.py, which reads cached_tokens from prompt_tokens_details and computes the hit rate as cached tokens divided by prompt tokens. Rates of 80% or higher are rated EXCELLENT, while zero cached tokens on prompts over 50 tokens is flagged POOR.

What token thresholds trigger context warnings?▼

Context at or above 100,000 tokens triggers a WARNING recommending cache-first lean replies, and 128,000 tokens triggers CRITICAL status suggesting thread summarization. A single-turn delta of 15,000 tokens or more also triggers a warning about large file reads.

Does the token monitor estimate API costs?▼

Yes, it estimates costs using per-model pricing from references/pricing.json, billing uncached input, cached input, and output tokens at their respective rates. Session mode assumes a 75% cache hit on prior context after the first turn, while API mode uses exact usage JSON for precise billing.

Why does the cache analysis report a POOR status?▼

A POOR status means cached_tokens was zero on a prompt larger than 50 tokens, indicating the prompt cache was not utilized. This typically happens when prompts change between calls or the cache window expired; see references/xai-prompt-caching.md for cache mechanics.