Token Counter
See how close your prompt is to CLIP's 77-token wall
- clip
- COUNT
- COUNT_AS_STRING
CLIP - the text encoder in classic Stable Diffusion - has a hard token limit of 77 tokens (for the ViT-L/14 variant SD 1.5 and SDXL use). Go past it and your prompt gets truncated or split into chunks, which quietly changes what the model sees. JNodes_TokenCounter tells you the number before you get burned by it. Feed it your prompt and a CLIP, and it counts the tokens the real tokenizer produces.
It's one of the features Jared Therriault highlighted when he first posted JNodes back in 2024, and it's genuinely useful for anyone who writes long prompts and wonders whether the back half is even being read. The answer, past 77 tokens on SD 1.5/SDXL, is often "no."
How it works
Tokens aren't words. CLIP breaks your text into sub-word pieces, so "photorealistic" might be two or three tokens and a rare word might be several. This node runs your text through the tokenizer of the clip you hand it and reports the count. Because it uses the actual loaded encoder - not a generic estimate - the number reflects your model's tokenizer, including its special start/end tokens. It's an output node, so it displays the result; wire the outputs onward if you want to act on the number.
The inputs and outputs
text(STRING) - the prompt you want measured. Wire your positive (or negative) prompt in here.clip(CLIP) - the loaded CLIP from your checkpoint or CLIP loader. This is what makes the count accurate to your model rather than a guess.COUNT(INT) andCOUNT_AS_STRING(STRING) outputs - the same number in two forms. Use theINTfor logic (gate a node when you're over budget) and the string for display, filenames, or metadata.
How to install it
Via ComfyUI Manager: Install Custom Nodes, search "JNodes", install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/JaredTherriault/ComfyUI-JNodes
pip install -r ComfyUI-JNodes/requirements.txt
then restart ComfyUI. No model downloads - it uses whatever CLIP is already loaded in your graph.
Common issues & troubleshooting
You need to wire in a CLIP - it won't count without one. The clip input is required precisely because the count is tokenizer-specific. Grab the CLIP output from your checkpoint loader (or a dedicated CLIP loader) and plug it in.
On newer models the 77-token limit is gone - but the counter still helps. Flux, Qwen-Image, Z-Image and other LLM-encoder models don't truncate at 77; their encoders take thousands of tokens. So the count won't map to a hard wall there. But long prompts still hurt: community testing on these models found the model starts to drift past roughly 75-100 effective tokens, and 400-word prompts actively work against you. Read the counter on those models as a "am I rambling?" gauge, not a truncation alarm. Three to five strong concepts, subject first, beats a wall of text.
The number includes special tokens. Tokenizers add start/end markers, so a very short prompt won't read as zero and the count may be a touch higher than you'd guess by eye. That's expected - it's counting what actually goes into the encoder.
A high count doesn't mean "delete words until it fits." On SD 1.5/SDXL, if you're over 77 you have real choices: trim to the essentials, or accept the chunking (ComfyUI handles multi-chunk prompts, but the emphasis and interactions across chunks get muddier). The counter's job is to make the trade-off visible, not to make it for you.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| clip | CLIP | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| COUNT | INT | — |
| COUNT_AS_STRING | STRING | — |