Skip to content

ctok - Claude Token Estimator, Cost Calculator & Prompt Refiner

The focus layer for Claude Code. Stop context rot: size the prompt, pick the right model and effort, trim the dead weight, and see your quota impact - before you send.

Stop context rot - keep Claude Code focused

ctok is a free, open-source toolkit for everyone who builds with Claude. Long coding sessions drift, the wrong model burns money, and you hit your quota mid-task. ctok runs before you send, wrapping a simple Plan → Execute → Verify loop around every prompt:

  • Plan - count tokens for Claude Haiku 4.5, Sonnet 4.6, and Opus 4.7, price the prompt at current Anthropic list rates, and get a model + effort recommendation.
  • Execute - refine the prompt with a 7-pass pipeline that strips filler, catches repeats, and adds structure so every message stays lean.
  • Verify - see exactly what percentage of your 5-hour window the prompt will burn before you spend it.

It runs everywhere a developer already works: a CLI on the terminal, an MCP server inside Claude Code / Cursor / Zed, and a web playground in the browser. The CLI and MCP server are on npm; the browser extension and desktop app build straight from a clone - no app store or account required.

What ctok does

Estimate tokens

Heuristic BPE-aware estimation across prompt, code, files, and project context. Shows input/output ranges with confidence level.

Recommend model & effort

Picks Haiku / Sonnet / Opus based on task complexity. Suggests effort level (low → xhigh) with written reasoning.

Refine prompts

7-pass pipeline strips filler words, replaces vague verbs, deduplicates blocks, and scores specificity 0-100.

Works everywhere

CLI · Web playground · MCP server · Desktop app · Browser extension. Same engine, every surface.

Quick start - run from a clone

No store, no account. Clone and you have the whole toolkit working locally:

Terminal window
git clone https://github.com/ctok-cli/ctok.git
cd ctok
# macOS / Linux
./scripts/setup.sh
# Windows (PowerShell)
./scripts/setup.ps1
# any OS, after `corepack enable`
pnpm setup

Prefer npm? The CLI is published there too:

Terminal window
npm install -g @ctok/cli

30-second demo

Terminal window
$ ctok check "Refactor the auth middleware to use the new session store"
Input tokens ~367 (range 365-369, high confidence)
Output tokens ~400 (range 400-551)
Estimated cost $0.035 at Opus 4.7
Recommendation opus-4-7 · high effort
Why Deep / architectural work. Opus 4.7 has the strongest
reasoning and is worth the premium when correctness matters.
$ ctok refine "please can you kindly help me to handle the auth thing somehow"
Score 12 45 (+33) · saved 4 tokens
Refined: Handle the auth flow.