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.
- 🔢 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
Clone the repo and install dependencies:
git clone https://github.com/yourname/tc.git
cd tc
npm installTo make the command globally available:
npm linkYou can now use tc anywhere in your terminal.
You need an Anthropic API key.
Create a .env file in the project root:
ANTHROPIC_API_KEY=your_api_key_hereOr export it:
export ANTHROPIC_API_KEY=your_api_key_heretc --file prompt.mdcat prompt.md | tctc --file prompt.md --model haiku
tc --model opus < input.txt| 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
Only the number of tokens is printed to stdout:
$ tc --file input.md
847Errors and help messages go to stderr:
❌ Unknown model alias: snafu
Available: sonnet, haiku, opus, sonnet35, haiku35, sonnet35v2Run with ts-node:
npx ts-node tc.ts --file input.mdBuild:
npm run build
node dist/tc.js -f input.mdISC © BroJor
Built for developers who want to work closely with large language models and need precise token control.
Inspired by wc, but LLM-native.