👁 TokenLens AI
Intelligent token middleware for AI developers — see every token, control every request, pay only for what matters.

TokenLens AI is a VS Code extension that sits between you and any LLM. It automatically classifies your task, strips irrelevant context, routes to the right model, and shows you exactly what's happening with your tokens in real time.
The Problem
AI coding tools send your entire codebase to the LLM blindly.
- A simple bug fix sends 50,000 tokens when 5,000 would do
- You're paying 10x more than necessary
- You have zero visibility into what's being sent
The Solution
TokenLens AI acts as a middleware layer that:
- Classifies your task (bug fix, review, documentation, etc.)
- Optimizes context — removes irrelevant files, compresses low-priority ones
- Routes to the cheapest model that can handle the task
- Shows you real-time token usage, cost, and savings
Your Prompt + Codebase (50,000 tokens)
│
▼
TokenLens AI
┌────────────────────┐
│ 1. Classify task │ → "bugfix"
│ 2. Strip context │ → remove 47 unrelated files
│ 3. Compress files │ → summarize 3 large files
│ 4. Route model │ → Claude Sonnet (not Opus)
└────────────────────┘
│
▼
Optimized Request (6,200 tokens) → 88% saved
Features
- Token Dashboard — real-time view of tokens used, cost, and savings per request
- Auto Task Classifier — detects bugfix, review, architecture, docs, refactor, test, and more
- Context Optimizer — removes irrelevant files, compresses low-priority content
- Smart Model Router — auto-routes to Haiku, Sonnet, Opus, GPT-4o, or local Ollama
- Prompt Caching — leverages Anthropic/OpenAI cache APIs for stable context
- PII Detection — warns before sending sensitive data to cloud LLMs
- Stack Templates — pre-configured context profiles for popular frameworks
- MCP Server Templates — ready-made integrations for GitHub, Jira, Adobe Commerce, and more
Quick Start
1. Install
Search TokenLens AI in VS Code Extensions or:
code --install-extension tokenlens-ai.tokenlens-ai
// VS Code Settings (settings.json)
{
"tokenlens.anthropicApiKey": "sk-ant-...",
"tokenlens.openaiApiKey": "sk-...",
"tokenlens.defaultProvider": "anthropic"
}
Or set environment variables:
export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...
3. Select Your Stack
Open Command Palette (Cmd/Ctrl+Shift+P) → TokenLens AI: Select Stack Template
4. Send Your First Request
Select code in editor → Command Palette → TokenLens AI: Send Optimized Request
Model Routing
TokenLens AI automatically picks the right model for each task:
| Task |
Default Model |
Why |
| Code completion |
Claude Haiku |
Fast, cheap, sufficient |
| Bug fix |
Claude Sonnet |
Balanced quality/cost |
| Architecture |
Claude Opus |
Complex reasoning needed |
| Documentation |
GPT-4o-mini |
Great writer, very cheap |
| Code review |
Claude Sonnet |
Balanced |
| Test generation |
Claude Haiku |
Pattern-based, cheap |
Override any rule in Settings → tokenlens.router.*
Stack Templates
Pre-configured context profiles that know what matters for your framework:
| Template |
Includes |
Excludes |
Compresses |
| Next.js |
types, lib, next.config |
.next, node_modules |
components, public |
| FastAPI |
models, schemas, core |
pycache, .venv |
routers, tests |
| Django |
models, serializers, config |
migrations, pycache |
views, tests |
MCP Server Templates
Connect your tools in one click:
| Service |
Category |
Features |
| 🐙 GitHub |
DevOps |
PRs, issues, actions, code search |
| 📋 Jira |
Project Management |
Issues, sprints, epics |
| 🛒 Adobe Commerce |
E-commerce |
Products, orders, inventory, CMS |
| 🐘 PostgreSQL |
Database |
Schema, queries, migrations |
| 💬 Slack |
Communication |
Channels, threads, search |
| ⚡ Linear |
Project Management |
Issues, cycles, roadmap |
| 🐶 Datadog |
Observability |
Metrics, logs, traces, alerts |
| ⚡ Supabase |
Database + Auth |
Schema, RLS, Edge Functions |
Token Dashboard
The dashboard shows you exactly what happened with your last request:
👁 TokenLens AI
Session Usage
├── Total Tokens: 42,800
├── Tokens Saved: 180,200 (81%)
├── Total Cost: $0.0184
└── Requests: 12
Last Request
├── Task Type: bugfix
├── Model Used: claude-sonnet-4-6
├── Raw Context: 38,400 tokens
├── After Optimize: 6,200 tokens (84% saved)
├── Cost: $0.0032
└── Duration: 1,240ms
Trimmed Files (12)
── node_modules/...
── .next/...
── prisma/migrations/...
Configuration
Full config via VS Code Settings or .tokenlens/config.json in your project:
{
"providers": {
"default": "anthropic",
"anthropic": { "apiKey": "${ANTHROPIC_API_KEY}" },
"openai": { "apiKey": "${OPENAI_API_KEY}" },
"ollama": { "baseUrl": "http://localhost:11434" }
},
"budget": {
"dailyTokenLimit": 500000,
"alertAt": 0.8
},
"context": {
"maxTokensPerRequest": 20000,
"alwaysExclude": [".env", "node_modules", "*.lock"]
},
"stack": "nextjs",
"mcp": {
"github": { "enabled": true },
"jira": { "enabled": false }
}
}
Contributing
We welcome contributions! The most wanted:
- New MCP templates (Shopify, Salesforce, HubSpot, AWS...)
- New stack templates (Go, Rust, Flutter, Laravel...)
- Token optimization improvements
- Bug reports and feature requests
See CONTRIBUTING.md for details.
Roadmap
- [ ] LLM call inspector (DevTools for AI)
- [ ] Inline eval runner
- [ ] Multi-model benchmark per codebase
- [ ] Background agents
- [ ] Team token budget management
- [ ] AI pipeline builder
- [ ] VS Code fork (full editor)
License
MIT — see LICENSE
Built with ❤️ for AI developers. Star ⭐ if you find it useful!