Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

tiktokenman

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiktokenman

File-based token counter CLI powered by tiktoken

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
6
20%
Maintainers
1
Weekly downloads
 
Created
Source

tiktokenman

File-based token counter CLI powered by tiktoken.

Count tokens in any file before sending to an LLM API — know the cost before you pay.

Install

npm i -g tiktokenman

Or run directly:

npx tiktokenman count ./file.txt

Usage

Single file

$ tiktokenman count ./README.md
README.md    342 tokens (gpt-4o)

Multiple files / glob patterns

$ tiktokenman count "src/**/*.ts"
 src/cli.ts              83 tokens
 src/commands/count.ts  559 tokens
 src/index.ts           176 tokens
────────────────────────────────────
 Total                  818 tokens (gpt-4o)

Specify model

$ tiktokenman count ./file.txt --model gpt-4o-mini

Supported models: gpt-4o (default), gpt-4o-mini, gpt-4, gpt-3.5-turbo

JSON output

$ tiktokenman count "src/**/*.ts" --json
{
  "model": "gpt-4o",
  "files": [
    { "file": "src/cli.ts", "tokens": 83 },
    { "file": "src/commands/count.ts", "tokens": 559 },
    { "file": "src/index.ts", "tokens": 176 }
  ],
  "total": 818
}

Options

OptionAliasDescriptionDefault
--model-mTokenizer modelgpt-4o
--jsonOutput as JSONfalse
--help-hShow help
--version-vShow version

Programmatic API

import { countTokens, countFileTokens } from "tiktokenman";

// Count tokens from text
const tokens = countTokens("Hello, world!", "gpt-4o");
console.log(tokens); // 4

// Count tokens from a file
const result = countFileTokens("./README.md");
console.log(result); // { file: "./README.md", tokens: 342, model: "gpt-4o" }

License

MIT

FAQs

Package last updated on 10 Apr 2026

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