ComfyUI Node

Token Counter

Stop guessing how many CLIP tokens your prompt eats

By LaVie024·Created about a year ago·Updated 8 months ago· 8
Token Counter
  • clip
  • tkn_count_str
  • tkn_count_int
text

CLIP-based models chunk your prompt into 77-token blocks, and the way your prompt breaks across that boundary decides what gets baked into your image. TokenCounter tells you exactly how many tokens your text takes - as a string and as an int - so you can stop writing prompts blind and start engineering around the limit. It's a straight re-implementation of pamparamm's old CLIP Token Counter from ComfyUI-ppm, with the text input changed from a built-in textbox to a forced wire, plus an int output for programmatic use. The README's note is important: it only works for SD1.5 and SDXL CLIP outputs.

Why you'd reach for it

The 77-token limit is a wall you keep hitting in anime prompting. You've got a NoobAI or Illustrious prompt with artist tags, character tags, and a quality block, and you feel like it's too long but you can't see the boundary. TokenCounter makes the limit visible: wire your text in, read the count, trim until you're comfortable. Because it needs a CLIP input, it reads through the actual tokenizer you're using - not an approximation.

How it works

The implementation mirrors the old ppm logic: it splits the text on BREAK into blocks (the same block separator CLIP uses), tokenizes each block through your CLIP model, strips out special tokens, and counts what remains. BREAK therefore shows up as separate counts - tokenize per block, not one lump sum - which is genuinely useful if you're deliberately structuring a prompt around the 77-token chunks. The output is the count of the first block as a string, and the same number as an int for feeding into math or metadata nodes.

One honest limitation from the source: it reaches into the CLIP model's clip_l tokenizer and special-token table, which is why the README warns it's SD1.5/SDXL-scoped. Feed it an LLM-encoded model's CLIP and the internals it expects aren't there.

The inputs and outputs

  • clip (CLIP) - the CLIP model whose tokenizer you want to measure against. Same CLIP you're conditioning with.
  • text (STRING, forced input) - the prompt to count. Wire it from your prompt node rather than typing.
  • tkn_count_str (STRING) - the count as text, handy for display or metadata.
  • tkn_count_int (INT) - the count as a number, handy for logic.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/LaVie024/comfyui-lopi999-nodes

Restart ComfyUI, or search "comfyui-lopi999-nodes" in ComfyUI Manager. No model downloads - it uses the CLIP you already have loaded.

Common issues

The big one is scope: SD1.5 and SDXL CLIP only. On anything LLM-encoded (Flux, Anima, the 2026 generation), the node can't measure your prompt meaningfully - those models don't have a 77-token CLIP boundary at all, so the count would be misleading. Also, because the input is forced, you can't type a prompt directly into the node for a quick check - you need a string source wired in, even a plain text node. And remember the count is per-BREAK-block on the first block, not the whole prompt's total; if you're checking a long prompt, keep the block structure in mind.

Categorylopi999/utils

Inputs (2)

NameTypeDefaultDescription
clipCLIP
textSTRING

Outputs (2)

NameTypeDescription
tkn_count_strSTRING
tkn_count_intINT