* Tokenizer utility for token counting. This module provides functions to estimate tokens in text content by dividing character length by 4. Usage: - Main process: Import and use directly
// Source: https://github.com/matt1398/claude-devtools | License: MIT | Copyright 2026 claude-devtools contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Tokenizer utility for token counting.
*
* This module provides functions to estimate tokens in text content by
* dividing character length by 4.
*
* Usage:
* - Main process: Import and use directly
* - Renderer: Token counts should be pre-computed in main process and passed via IPC
*/
/**
* Count tokens in a string by dividing length by 4.
* Uses character count estimation instead of exact tokenizer.
*
* @param text - The text to tokenize
* @returns Number of tokens (estimated)
*/
export function countTokens(text: string | undefined | null): number {
if (!text || text.length === 0) {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key