Skip to content

brojor/quantok

Repository files navigation

tc – Token Counter CLI for Claude

tc is a lightweight CLI tool that counts tokens in your input using Anthropic Claude models. Inspired by the classic Unix tool wc, but for LLM prompts.


✨ Features

  • 🔢 Counts tokens using Claude 3 models
  • 📂 Supports both file input and stdin
  • 🧱 Outputs only the token number (stdout)
  • 📤 Prints errors to stderr
  • 🎯 Supports multiple models via short aliases
  • 🧑‍💻 Written in TypeScript

🚀 Installation

Clone the repo and install dependencies:

git clone https://github.com/yourname/tc.git
cd tc
npm install

To make the command globally available:

npm link

You can now use tc anywhere in your terminal.


🔐 Setup

You need an Anthropic API key. Create a .env file in the project root:

ANTHROPIC_API_KEY=your_api_key_here

Or export it:

export ANTHROPIC_API_KEY=your_api_key_here

🧪 Usage

From a file

tc --file prompt.md

From stdin

cat prompt.md | tc

Specify model

tc --file prompt.md --model haiku
tc --model opus < input.txt

🧠 Supported Model Aliases

Alias Claude Model ID
sonnet claude-3-7-sonnet-20250219
haiku claude-3-haiku@20240307
opus claude-3-opus@20240229
haiku35 claude-3-5-haiku@20241022
sonnet35 claude-3-5-sonnet@20240620
sonnet35v2 claude-3-5-sonnet-v2@20241022

Default model: sonnet


📤 Output

Only the number of tokens is printed to stdout:

$ tc --file input.md
847

Errors and help messages go to stderr:

❌ Unknown model alias: snafu
   Available: sonnet, haiku, opus, sonnet35, haiku35, sonnet35v2

📦 Development

Run with ts-node:

npx ts-node tc.ts --file input.md

Build:

npm run build
node dist/tc.js -f input.md

🛠 License

ISC © BroJor


💡 Inspiration

Built for developers who want to work closely with large language models and need precise token control. Inspired by wc, but LLM-native.

About

CLI tool for fast token counting using Anthropic Claude models. Inspired by Unix wc, perfect for developers working with LLM prompts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors