Socket
Book a DemoInstallSign in
Socket

count-tokens

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

count-tokens

A simple CLI tool to count tokens in files or clipboard content using tiktoken

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

count-tokens

npm version License: MIT

A simple CLI tool to count tokens in files or clipboard content using OpenAI's tiktoken library.

🔗 GitHub Repository

Installation

npm install -g count-tokens

or with bun:

bun add -g count-tokens

Usage

count-tokens [file] [options]

Options

  • -m, --model <model> - OpenAI model to use for encoding (default: "gpt-4")
  • -e, --encoding <encoding> - Specific encoding to use (overrides model)
  • -d, --details - Show detailed token information including character count and cost estimates
  • -c, --chunks <size> - Split output into chunks of specified token size
  • --clipboard - Count tokens from clipboard content instead of a file
  • -h, --help - Display help
  • -V, --version - Display version

Examples

Count tokens in a file using the default GPT-4 encoding:

count-tokens myfile.txt

Count tokens using GPT-3.5 Turbo encoding:

count-tokens myfile.txt --model gpt-3.5-turbo

Show detailed information including cost estimates:

count-tokens myfile.txt --details

Show chunk breakdown for 4096 token chunks:

count-tokens myfile.txt --chunks 4096

Use a specific encoding directly:

count-tokens myfile.txt --encoding cl100k_base

Clipboard Examples

Count tokens from clipboard content:

count-tokens --clipboard

Count clipboard tokens with GPT-3.5 Turbo encoding:

count-tokens --clipboard --model gpt-3.5-turbo

Show detailed information for clipboard content:

count-tokens --clipboard --details

Copy text and immediately count tokens (macOS):

echo "Your text here" | pbcopy && count-tokens --clipboard

Copy text and immediately count tokens (Linux):

echo "Your text here" | xclip -selection clipboard && count-tokens --clipboard

Supported Models

  • gpt-4, gpt-4-32k
  • gpt-3.5-turbo
  • gpt-4o, gpt-4o-mini
  • text-davinci-003
  • text-embedding-ada-002
  • And many more OpenAI models

Supported Encodings

  • gpt2
  • cl100k_base
  • o200k_base
  • p50k_base
  • p50k_edit
  • r50k_base

Development

bun install
bun run index.ts <file>

License

MIT

Keywords

tiktoken

FAQs

Package last updated on 21 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts