Token Lens

v0.2.37
io.github.duttkunal101-lab/token-lens Checked 3 days ago Published 1 month ago

Count and cut tokens in prompts, chats and agents for any model.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

plan_coach Get the most out of your Claude plan

How much of the user's Claude plan (Free, Pro, Max, Team) is used and left, how many more messages fit this session in the open chat versus a new one, what is draining it, and what to do before it runs out or resets unused. Never switches the model or changes answers. Use when the user asks about usage, limits, their plan or subscription, or how to make it last.

ParameterTypeDescription
chat_tokensintegerYour best estimate of this chat's size in tokens.
planstringThe user's plan, if they said; saved for next time.
session_pct_usednumberSession usage % from Claude's Settings > Usage, if the user gave it.
session_resets_in_minutesnumber
week_pct_usednumber

optimize_prompt Optimize a prompt for fewer tokens

Rewrite a prompt to use fewer tokens for a given model, keeping its meaning. Detects the task (coding, debugging, writing, editing, summarizing, translation, research, analysis, brainstorming, chat), leaves code, quotes and pasted source text untouched, trims logs when debugging, and drops step-by-step instructions for reasoning models. Never suggests switching models. Returns the best prompt to paste (same answer, fewer tokens, with what it kept), the savings in tokens and dollars, and model- and task-specific tips. Use when the user asks to shorten, tighten or save tokens on a prompt.

ParameterTypeDescription
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
prompt *stringThe prompt to optimize, exactly as the user wrote it.
conversation_tokensintegerTokens already in the conversation, if known.
levelstringlight: wording only; balanced: + politeness and filler; aggressive: + hedges. Default auto.
pricingobjectUSD per 1M tokens, only if not the list price.

count_tokens Count tokens

Count the tokens in a text for a given model. Exact for OpenAI models (o200k tokenizer); for Claude and Gemini exact when the server runs with your own ANTHROPIC_API_KEY or GEMINI_API_KEY (it then asks the provider's free token-count endpoint), otherwise a per-family estimate. Use when the user asks how many tokens something is, or before pasting a large document.

ParameterTypeDescription
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
text *string
pricingobjectUSD per 1M tokens, only if not the list price.

check_conversation Check conversation token budget

Estimate how full the context window is for a conversation and whether to hand off to a new chat. Pass the conversation text or a token count. When the chat is long, also offers an optional handoff request that produces a compact brief to continue in a fresh chat; this can change later answers, because the new chat only knows what the brief keeps, so present it as optional and never as same-output. Use when the user asks about chat length, usage limits, or the model forgetting earlier context.

ParameterTypeDescription
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
conversationstringThe conversation so far, as text.
conversation_tokensintegerOr: its size in tokens.
latest_requeststringThe user's latest message, to tailor the handoff to the task.
pricingobjectUSD per 1M tokens, only if not the list price.

optimize_agent Find token hotspots and optimize an agent or conversation

Break down where tokens go in an agent or chat (system prompt, tool definitions, examples, conversation history, next prompt), find what is large or growing, and fix it. Safe fixes that keep the meaning (tighter wording with every number, negation and constraint kept; duplicate history removed) are applied and returned as an optimized spec. Returns the optimized system prompt, tool definitions and next prompt ready to paste. Every applied change is verified (facts and constraints kept, every instruction word kept, tool interface and conversation unchanged, same model) and the checks are return…

ParameterTypeDescription
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
calls_per_monthintegerHow many calls this agent makes per month, if known, to show the monthly saving.
examplesarrayFew-shot examples.
messagesarrayConversation history, oldest first.
pricingobjectUSD per 1M tokens, only if not the list price.
promptstringThe next user message.
systemstringSystem prompt / instructions.
toolsarrayTool definitions (parameters = JSON schema).

audit_agent_rules Trim coding-agent rule files

Audit the instruction files a coding agent re-sends on every turn (CLAUDE.md, AGENTS.md, .cursorrules, .github/copilot-instructions.md, GEMINI.md and the like) and return trimmed versions ready to paste. Removes exact repeats within and across the files and tightens wording only where every number, negation, constraint and instruction word is kept, so the agent gets the same instructions. Lines that mention files missing from the repo are listed, never removed. Reports the tokens and dollars saved per turn and per 1,000 turns. Use when the user shares agent rule files or asks why a coding agen…

ParameterTypeDescription
files *arrayEach rule file: its path and full text.
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
pricingobjectUSD per 1M tokens, only if not the list price.
repo_pathsarrayOptional: the repo's file paths, to flag rules that mention files that no longer exist.

list_model_profiles List model profiles

List the model families Token Lens adapts to, with their context windows, whether counts are exact, and the price used for cost figures.

compact_data Shrink pasted data without changing it

Shrink pasted JSON, API responses or logs with the data unchanged (removes only whitespace outside strings; proven by parsing). Returns paste-ready text and savings. Use when the user pastes large data.

ParameterTypeDescription
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
text *stringText with the pasted data, as written.

compare_prompts Check a shortened prompt against the original

Check a prompt the user shortened against the original: savings, and any number, negation, constraint or instruction word lost. Use when asked if a shorter prompt is safe to send.

ParameterTypeDescription
edited *string
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
original *string

estimate_cost Forecast monthly cost and same-answer savings

Monthly cost of an app or agent on its model (input, output, long-context rates) and what same-answer prompt caching and half-price batch save. Use for budgets and cutting an LLM bill.

ParameterTypeDescription
calls_per_day *number
input_tokens *integerPer call.
model *stringModel in use, e.g. "gpt-5", "claude-sonnet-4-5"; your own if unsure.
output_tokens *integerPer call, incl. reasoning.
can_wait_sharenumberShare of calls that can wait 24h.
pricingobjectUSD per 1M tokens, only if not the list price.
repeated_prefix_tokensintegerUnchanging start of each call: system, tools, examples.

savings_report Show total tokens and money saved

Tokens and money Token Lens has saved: today, 7 and 30 days, total, by action and model.