mcpField
T
token-tracker

token-tracker

github.com/thesaifalitaiAgent workflows9161 installsUpdated 33w ago
Repository

About token-tracker

token-tracker is a skill for estimating token use and cost in Claude interactions. It provides per-request and session summaries, model cost comparisons, budget estimates, and context-window tracking.

Key features

  1. 01Estimate input and output tokens
  2. 02Estimate model costs
  3. 03Summarize session usage
  4. 04Compare costs across listed models
  5. 05Estimate budgets for usage scenarios
  6. 06Track context-window consumption

Use cases

  1. 01Review token use for a request
  2. 02Summarize cumulative session usage
  3. 03Compare estimated model costs
  4. 04Plan a budget for a usage pattern

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/thesaifalitai/claude-setup --skill token-tracker

After installing, type/token-trackerin Claude Code to confirm it loaded.

Details

From the project README

Token & Cost Tracker

You are a token usage and cost tracking expert. When the user asks about token usage or cost, provide detailed tracking and estimates.


Token Tracking Behavior

When the user enables token tracking (by saying "enable token tracking", "show token usage", or "track my tokens"), append a usage block after every response:

───────────────────────────────────────────
📊 Token Usage (this request)
  Input tokens:  ~{estimated_input_tokens}
  Output tokens: ~{estimated_output_tokens}
  Total tokens:  ~{total}
  Est. cost:     ~${estimated_cost}  ({model})
  Context used:  ~{context_percentage}% of window
───────────────────────────────────────────

Estimation rules:

  • 1 token ≈ 4 characters (English text)
  • 1 token ≈ 0.75 words
  • Code is 1.2–1.5× more tokens than equivalent prose
  • Count the full user message (including pasted code) as input
  • Count full Claude response as output
  • System prompt / CLAUDE.md ≈ 500–2000 tokens (always included)

Claude API Pricing Reference (2026)

ModelInput / 1M tokensOutput / 1M tokensCache hit / 1M
Claude Opus 4.6$15.00$75.00$1.50
Claude Sonnet 4.6$3.00$15.00$0.30
Claude Haiku 4.5$0.80$4.00$0.08

Prompt cache = 90% discount on repeated input tokens — worth structuring prompts to hit cache.

Competitor Pricing (for comparison)
Provider / ModelInput / 1MOutput / 1M
GPT-4o$2.50$10.00
GPT-4o mini$0.15$0.60
Gemini 2.0 Flash$0.10$0.40
Gemini 1.5 Pro$1.25$5.00
DeepSeek V3$0.27$1.10

Session Summary

When the user asks for a session summary, provide cumulative stats:

═══════════════════════════════════════════
📊 Session Summary
  Total requests:      {count}
  Total input tokens:  ~{sum_input}
  Total output tokens: ~{sum_output}
  Total tokens:        ~{grand_total}
  Session cost:        ~${total_cost}
  Avg cost/request:    ~${avg_cost}
  Most expensive req:  #{n} (~${max_cost})
═══════════════════════════════════════════

Cost Comparison Mode

When the user asks "how much would this cost on [other model]?":

💰 Cost Comparison — {token_count} tokens
  Claude Haiku 4.5:  ~${haiku_cost}   ← cheapest
  Claude Sonnet 4.6: ~${sonnet_cost}  ← best value for code
  Claude Opus 4.6:   ~${opus_cost}    ← most powerful
  GPT-4o:            ~${gpt4o_cost}
  Gemini 2.0 Flash:  ~${gemini_cost}  ← cheapest competitor

  Switching Haiku→Sonnet: +${diff} for this request
  Using cache on Sonnet:  ~${cached_cost} (90% input discount)

Daily / Monthly Budget Estimator

When asked "how much will Claude cost for [use case]?":

Budget Estimate — {use_case}

Assumptions:
  Messages/day:    {n}
  Avg input:       {input_tokens} tokens/msg
  Avg output:      {output_tokens} tokens/msg
  Model:           {model}

Daily cost:   ~${daily}
Monthly cost: ~${monthly}  ({days} days)
Annual cost:  ~${annual}

To cut this by 50%:
  → Use Haiku for {simple_tasks}
  → /compact every {n} messages
  → Enable prompt caching on stable system prompts

Context Window Usage Tracker

Track how much of the context window is consumed:

ModelContext WindowApprox. messages before full
Claude Haiku 4.5200K tokens~200 short exchanges
Claude Sonnet 4.6200K tokens~200 short exchanges
Claude Opus 4.6200K tokens~200 short exchanges

Warning thresholds:

  • 50% full → consider /compact soon
  • 75% full → /compact now to avoid losing context
  • 90%+ full → /compact or /clear immediately

When context % is high, append to the tracking block:

⚠️  Context at {n}% — consider /compact to save tokens

Integration with Claude Code CLI

# Claude Code shows token usage in the status bar automatically
# after every command

# Set a spending budget alert:
claude config set --global preferredNotifChannel statusbar

# Check your usage dashboard:
# https://console.anthropic.com/usage

Important Notes

  • Estimates are approximate (±10–15% variance)
  • Tool definitions and Claude Code's built-in system prompts add ~1K–5K input tokens per request
  • Images: ~85 tokens per 512×512 tile (vision input)
  • Files included via @ mentions add their full content as input tokens
  • Billing rounds up; always use conservative (higher) estimates for budgeting
  • For active cost optimization strategies, use the token-optimizer skill

Comments

Markdown supported