Nodes/ComfyCollectorNodes/Token Counter (CCN)
ComfyUI Node

Token Counter (CCN)

Stop guessing whether your prompt fits

By valkymaera·Created 4 months ago·Updated 10 days ago· 1
Token Counter (CCN)
  • clip
  • token_count
  • info
text
debugfalse

Every ComfyUI model has a token budget, and most of us only discover it by watching output quality quietly rot as the prompt grows. Token Counter (CCN) is the fix: wire your prompt in, optionally connect the same CLIP model you're actually encoding with, and it tells you how many tokens you're using - right on the node. No more counting commas, no more "is this under 77?"

The CLIP connection is the whole trick. ComfyUI's tokenizer isn't one size fits all, and this node knows it: it reports per-encoder counts. An SDXL-style CLIP gives you a ~77-token window (which is why BREAK used to matter so much - the old chunk-boundary tool, as prompt-engineering.md documents); a T5 encoder like the ones behind Flux and Wan allows roughly 512. If your model has two encoders, you get a line for each, plus the max - because the encoder that runs out first is the one that matters. That's the kind of detail a generic char-counting "token counter" gets wrong, and it's why this one is worth having.

How it works

With a CLIP connected, the node runs the model's real tokenizer (clip.tokenize) across every encoder, strips structural tokens (BOS/EOS/padding) from the count, and reports used / capacity (percent). It even warns when a chunk is near or at full - the small "⚠ chunk full" flag that means your prompt is about to be silently truncated or shoved into a second chunk. Without a CLIP connected it degrades to a rough ~4-characters-per-token estimate and says so, which is better than nothing and clearly labeled as an estimate.

The token_count output is the max across encoders (the binding constraint). The info output is the human-readable breakdown - encoder name, tokens, chunk count, percentage - shown on the node and available to wire anywhere.

The inputs and outputs that matter

  • text - the prompt you're checking.
  • clip - optional, but plug it in. It's the difference between a real count and a guess.
  • debug - optional; logs per-encoder tokenizer details to the console.

Outputs: token_count (INT) and info (STRING).

How to install it

Standard ComfyCollectorNodes install: ComfyUI Manager → search ComfyCollectorNodes → Install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/valkymaera/ComfyCollectorNodes.git

Restart ComfyUI. No extra Python dependencies.

Common issues

Two honest caveats. First, this counts the tokenizer's output, not the model's attention - on modern LLM-encoded models the practical ceiling can land lower than the tokenizer's max (the community's "attention cap" around 75–100 effective tokens), so use the count as a budget, not permission to fill to 512. Second, if your model's tokenizer exposes special tokens in an unusual way, the node may fall back to an approximate count - the debug toggle and the info output will tell you which one you got, so glance at them before trusting a number.

CategoryComfyCollectorNodes/Utils

Inputs (3)

NameTypeDefaultDescription
textSTRING
clipoptCLIP
debugoptBOOLEANfalse

Outputs (2)

NameTypeDescription
token_countINT
infoSTRING