CloTokO — LLM Token Counter & Prompt Cost OptimizerCloTokO measures your prompt and cuts what you should not pay for — live, as you type, and 100% offline: no network calls, no telemetry, no dependencies. In Copilot Chat:
|
| Command | What it does |
|---|---|
@clotoko <prompt> |
Analyse it. Nothing is sent to a model. |
@clotoko /optimize <prompt> |
Shrink it, then send the shorter version. |
@clotoko /send <prompt> |
Send as written, after showing the cost. |
Prefer chat only, with no editor decorations? Set clotoko.surface to "chat".
The analysis, not just a word count
Trimming filler is the small half of the problem. CloTokO also reports the things that actually decide what a prompt costs and whether it works:
- Where the money really goes. On a typical call the answer is 90%+ of the bill, so deleting words from the prompt moves almost nothing. It says so, with your numbers.
- Retry risk. Vague scope, no output format and no length limit make a second attempt likely — and a retry doubles the call. It quotes the phrases responsible.
- Contradictions, e.g. asking for a brief answer and an exhaustive one at once.
- Too many asks in a single call, which reliably produces partial answers.
- Prompt-cache ordering — providers discount cached input by 50-90%, but only match a prefix, so variable content near the top forfeits the discount.
- Energy and carbon, scaled by model tier, with a comparison you can picture.
Set
clotoko.gridIntensityfor your region (default 400 g CO2e/kWh).
It will not silently damage your prompt
Every rewrite is checked before you are offered it. Numbers and product names are
load-bearing: if 3 scenarios, ESUs or PostgreSQL would be lost, the rewrite is
discarded and CloTokO tells you why rather than reporting a saving that never existed.
What it does while you work
You write a prompt. CloTokO continuously shows what it costs and what to cut.
User: Please could you kindly, in order to help me, review this. 142 tok · $0.0021 · −38% possible
| Surface | When it updates |
|---|---|
| Inline hint at the end of each prompt's first line — tokens, cost, savings %, budget breach | as you type (300 ms) |
| Status bar — tokens, cost, saving % for the prompt under your cursor | every keystroke and cursor move |
| Active prompt highlight — a left border marking the prompt you're inside | on cursor move |
| Live Inspector panel — KPIs, budget bar, fixable list, top levers, optimized preview | as you type |
| Problems panel squiggles + 💡 quick fixes | as you type |
| CodeLens above every prompt | on edit |
| Hover — per-line and per-word token counts | on hover |
It tells you which model to use
CloTokO classifies the task (11 categories: reasoning, architecture, code-gen, analysis, QA, summarisation, rewriting, translation, extraction, classification, creative), estimates the capability it actually demands, then scores every model on capability fit, context headroom and price. It recommends the cheapest model that clears the bar — and shows its reasoning.
Task looks like classification / tagging ("sentiment").
That needs roughly 31/100 capability - raised by strict requirements.
Cheapest model clearing that bar: gpt-5-nano (50/100, $3.67/mo).
You are currently paying 190.9x more than necessary.
Habitual boilerplate is stripped before classifying. "Think step by step", "take a deep breath" and "you are a world-class expert" are instructions to the model, not evidence the work is hard — counting them would recommend a frontier model for sentiment tagging.
It writes you a better prompt
Beyond deleting waste, CloTokO reconstructs the prompt in a compact canonical shape:
| Role | one line, grandiose adjectives dropped |
| Task | imperative, deduplicated |
| Rules | constraints as bullets, negation preserved |
| Output | explicit format + length cap + "no preamble" |
| Payload | code and JSON preserved byte-for-byte |
It never returns a longer prompt — on an already-lean prompt it says so and leaves it alone. Your data is never paraphrased; only instruction prose is rewritten.
Press Ctrl+Alt+W to apply, or preview the diff first. It always confirms before replacing.
It knows where your prompt starts and ends
CloTokO never costs "the whole file". It finds the prompt block under your cursor:
- Chat transcripts — splits on
System:/User:/Assistant:markers, so each turn is priced separately. - Markdown — falls back to
---rules, then headings. - Python / JS / TS — finds prompt string literals inside your code and scores them, so a
file path or a
const SECRET = "ABC..."is never mistaken for a prompt.
Optimize then rewrites only that prompt — it will not touch your system prompt or the
surrounding code, and in Python/JS it edits the string contents without disturbing the quotes.
Why prompts cost more than they should
| Cause | Typical share of avoidable spend |
|---|---|
| Unbounded output length | 30–60% |
| Resending a static prefix without caching | 20–50% |
| Stuffing whole documents instead of retrieving | 40–90% of input |
| Conversation history replayed every turn (O(n²)) | 40–70% on long threads |
| Near-duplicate queries with no cache | 20–40% of all traffic |
| Politeness, filler, pretty-printed JSON, blank lines | 5–25% of input |
CloTokO measures all six on the prompt in front of you and fixes what it can automatically.
Waste rules
~25 rules with one-click fixes, in three safety tiers:
| Tier | Touches | Examples |
|---|---|---|
safe |
provably lossless | trailing whitespace, blank-line runs, repeated spaces, invisible/zero-width chars, ASCII rules, padded markdown tables, pasted line-number gutters, over-escaped \n |
balanced |
wording, meaning preserved | 100+ verbose→concise phrases, politeness padding, filler/intensifiers, ALL-CAPS (costs ~2× tokens), excessive !!!, pretty JSON → minified, URL tracking params, "I will tip you $200" filler, license headers |
aggressive |
structural | duplicated lines, near-duplicate paragraphs (shingle similarity), base64/binary blobs, bulk GUID dumps, comment-heavy pasted code |
Strategy recommendations
Ranked by impact, each with the concrete action and expected saving:
- Output caps — output costs 4–8× input on every major model
- Prompt caching — reorder so the static prefix is byte-identical; shows the exact per-call saving for your model
- Batch API — 50% off anything non-interactive
- Model right-sizing — scores task complexity, names the cheaper model and the cascade pattern
- RAG instead of stuffing — 80–95% input reduction
- History windowing — flattens O(n²) chat cost to O(n)
- Few-shot trimming — accuracy saturates at 2–4 examples
- Semantic caching, streaming + stop sequences, structured output to kill retries
- Token density warnings — id/hash-heavy content, non-Latin script (2–3× cost)
- Context-window overflow risk
Token budgets
Set CloTokO.tokenBudget (or run CloTokO: Set Token Budget). Any prompt over it gets an
orange inline marker, a status-bar flame, a CodeLens, and a Problems entry telling you the
monthly cost of the overshoot.
Commands
| Command | Keybinding |
|---|---|
| Open Live Prompt Inspector | Ctrl+Alt+I |
| Apply Rewritten Prompt | Ctrl+Alt+W |
| Preview Rewritten Prompt (diff) | Ctrl+Alt+O |
| Analyze This Prompt | Ctrl+Alt+T |
| Open Cost & Savings Report | Ctrl+Alt+R |
| Recommend Best Model for This Prompt | — |
| Optimize This Prompt (safe fixes) | — |
| Compare Cost Across Models | — |
| Count Tokens · Set Billing Model · Set Token Budget | — |
| Insert Optimized Prompt Skeleton | — |
| Reset Cumulative Savings · Toggle Live Hints | — |
Settings
| Setting | Default | Purpose |
|---|---|---|
CloTokO.model |
gpt-4o-mini |
model used for all estimates |
CloTokO.outputTokenEstimate |
600 |
assumed completion length |
CloTokO.queriesPerDay |
50 |
drives monthly/annual projections |
| CloTokO.tokenBudget | � | warn above N tokens per prompt (0 = off) |
| CloTokO.outputCap | 150 words | limit the rewriter adds when your prompt has none |
CloTokO.aggressiveness |
balanced |
safe | balanced | aggressive |
CloTokO.inlineHints |
true |
end-of-line live cost hints |
CloTokO.highlightActivePrompt |
true |
border around the prompt you're editing |
CloTokO.liveCounter |
true |
status-bar counter |
CloTokO.diagnostics / CloTokO.codeLens |
true |
squiggles / lenses |
CloTokO.enabledLanguages |
md, txt, json, yaml, py, js, ts, … | where it runs |
CloTokO.minSavingsToReport |
2 |
hide trivial findings |
CloTokO.currencySymbol / usdConversionRate |
$ / 1 |
set ₹ and 88 for INR |
CloTokO.customPrices |
{} |
override list prices (PTU / negotiated rates) |
Accuracy
Token counts come from an offline model of the GPT pre-tokenizer plus BPE merge heuristics and
a frequent-word table, calibrated per encoding (o200k, cl100k, Claude, Gemini, Llama). On
English prose, markdown, JSON and code it lands within about ±5% of tiktoken — with no 2 MB
vocabulary download and no network.
Prices are planning defaults (see PRICES_AS_OF in src/models.js). Override them in
CloTokO.customPrices.
Privacy
No network access, no telemetry, no dependencies. Your prompts never leave the machine. The
only persisted state is a local savings counter in VS Code's globalState.
Install
Copy the folder to %USERPROFILE%\.vscode\extensions\ and reload VS Code, or install the
included CloTokO-1.1.0.vsix. No build step — plain CommonJS JavaScript.
Bonus: terminal CLI
$env:ELECTRON_RUN_AS_NODE=1
& "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" tools\cli.js demo\wasteful-prompt.md gpt-4o
# flags: --write (emit file.optimized.md) --template (print the prompt skeleton)
Try it
Open demo\chat-transcript.md — each turn is priced separately. Put your cursor in a turn and
press Ctrl+Alt+I, then edit and watch it update. demo\prompts.py shows detection inside
Python string literals.
Tests
$env:ELECTRON_RUN_AS_NODE=1
& "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" test\run-tests.js
& "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" test\activate-test.js
135 assertions: 99 unit (tokenizer, pricing, every rule, prompt scoping, offset mapping,
optimizer, model advisor, prompt rewriter, caching, regression guards) and 36 activation tests
that load extension.js against a stubbed VS Code API and verify the live decorations, cursor
scoping, budget warnings and every command.
One test asserts no source file imports http, net, child_process or calls fetch — the
offline guarantee is enforced, not just claimed.
License
MIT