New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@kunal_dutt/token-lens

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kunal_dutt/token-lens

Count and cut the tokens your prompts, chats and agents use, adapted to the model and task. MCP server and self-hosted gateway. Collects no data.

latest
npmnpm
Version
0.2.39
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Token Lens

Count and cut the tokens your prompts, chats and agents use, adapted to the model and the task, without switching your model or changing the answer. Every saving is shown in tokens and dollars, priced for the model you use.

Works with any LLM: GPT, Claude, Gemini and Gemma, DeepSeek, Mistral, Grok, Llama, Qwen, Kimi, GLM, Cohere Command, Perplexity Sonar, Phi, and your own or local models. For people (in their AI app), companies (gateway or library, per team) and companies serving their own customers (savings and limits per customer).

Collects no data. No accounts, analytics or telemetry. It makes no network requests of its own, except an exact token count from Anthropic or Google when you set your own ANTHROPIC_API_KEY or GEMINI_API_KEY for it. See PRIVACY.md.

Add it to your AI app

No Node, no install: add https://cardoptimizer-bice.vercel.app/api/mcp as a connector in ChatGPT, claude.ai, Le Chat or any app that takes MCP connectors, then ask "Open Token Lens" in a chat. It works in the app and the website alike, and updates itself.

It runs on your own computer with Node 20 or newer. @latest means each start picks up the newest version, so there's nothing to update.

AppHow
Claude Codeclaude mcp add token-lens -- npx -y @kunal_dutt/token-lens@latest
Claude DesktopAdd the JSON below to claude_desktop_config.json (keeps itself up to date), or for a one-click install without Node, download token-lens.mcpb and open it.
Codex CLIcodex mcp add token-lens -- npx -y @kunal_dutt/token-lens@latest
Gemini CLIAdd the JSON below to ~/.gemini/settings.json.
Cursor, VS Code, Windsurf, Zed, Cline, LM Studio, any MCP appAdd a stdio server with the JSON below.
ChatGPT, claude.ai, Le Chat and mobile appsNeed a connector URL: use the public one, https://cardoptimizer-bice.vercel.app/api/mcp, or run your own (below).
{
  "mcpServers": {
    "token-lens": { "command": "npx", "args": ["-y", "@kunal_dutt/token-lens@latest"] }
  }
}

Needs Node.js 20 or newer for the npx setups. If Claude Desktop shows "Server disconnected", Node is missing or too old: install the LTS version from https://nodejs.org (on a Mac, its .pkg installer, which apps can find; a Node installed only through nvm usually isn't visible to desktop apps), then quit the app fully and reopen it.

Then ask, for example: "optimize this prompt with Token Lens", "how full is this chat?" or "optimize this agent's system prompt and tools".

Live tips in the Claude app on a Mac, with no command. When the Claude desktop app starts Token Lens, it also watches the message box and open chat of the AI app in front (Claude, or ChatGPT's Mac app), through macOS Accessibility. macOS gives that permission to whatever started Token Lens, which is often "node", and turning node on would give every Node program that control, so Token Lens never asks for it. Instead it offers Token Lens Helper, a small native Mac app set up only when you click Set up Token Lens Helper at http://localhost:4797 (or tell Claude yes when it offers): you turn it on once in System Settings > Privacy & Security > Accessibility. It reads only the message box and chat of Claude or ChatGPT, whichever is in front, runs Token Lens's own optimizer inside itself, and shows tips as notifications and in its menu bar window. It takes no input from other programs and the text never leaves it, so the permission can't be borrowed. Once a day it asks the npm registry for a newer Token Lens, checked against the registry's sha512 and never older than one it used. The panel shows your drafts only when Token Lens opens it (ask Claude to "open the Token Lens panel"). When you pause typing and a shorter prompt says the same thing, or a chat gets long enough that every message re-reads a lot, a macOS notification says so, in tokens and dollars. The shorter draft waits, ready to copy, at http://localhost:4797. It never types into Claude, keeps and sends nothing, and stops when Claude quits. Ask Claude "turn off Token Lens live tips" to stop it (the live_tips tool), or set TOKEN_LENS_LIVE=0. Other apps that run the same package aren't affected.

Tools: optimize_prompt, optimize_agent, audit_agent_rules, compact_data, compare_prompts, estimate_cost, savings_report, count_tokens, check_conversation, list_model_profiles, and live_tips on a Mac. Each takes the model's name, so it adapts to whichever model you use.

Run your own connector

npx -y @kunal_dutt/token-lens@latest --http 8787     # serves http://localhost:8787/mcp

Put it behind HTTPS (any reverse proxy or tunnel) and add https://<host>/mcp as a custom connector in ChatGPT or claude.ai. It stores nothing.

Cost check for agent builders

Every pull request that changes an agent's prompts or tool definitions gets a comment with the token and dollar change per call (and per month), priced for the model the agent runs on, plus what could be trimmed with the same output.

  • GitHub: copy agent-cost-check.yml to .github/workflows/, then set --model and your agent file paths.
  • Any other CI or locally: npx -y @kunal_dutt/token-lens@latest check-agent --model claude-opus-5-5 --base origin/main 'agents/**' prints the same report as Markdown (--out file.md to save it, --fail-above 500 to fail when a change adds more than 500 tokens per call).

Agent files are .json specs (system, tools, examples, messages, prompt; OpenAI- and Anthropic-style tool lists work as-is) or any text file, read as a system prompt. It runs inside your CI and sends nothing anywhere.

Gateway for companies

A self-hosted proxy that speaks the OpenAI and Anthropic APIs and optimizes every call your apps, workflows and agents make, with any model, including your own. Most providers need only their usual key variable (GEMINI_API_KEY, MISTRAL_API_KEY, DEEPSEEK_API_KEY, OLLAMA_BASE_URL…). Businesses serving their own customers get savings, spend and daily or monthly limits per customer and plan. It talks only to the model endpoints you configure. See GATEWAY.md.

docker run -p 8080:8080 -e OPENAI_API_KEY ghcr.io/duttkunal101-lab/token-lens-gateway:latest
# or
OPENAI_API_KEY=... npx -y @kunal_dutt/token-lens@latest gateway

Browser extension

For ChatGPT, Claude, Gemini, DeepSeek, Le Chat and Grok on the web: search "Token Lens" in the Chrome Web Store, Microsoft Edge Add-ons or Firefox Add-ons.

MIT licensed.

Keywords

mcp

FAQs

Package last updated on 18 Oct 2026

Related posts