π° TokenCounter /v (from kijai)
How many tokens is your prompt, really? Count them against your actual CLIP
- clip
- COUNT
- COUNT_AS_STRING
Prompts have a budget, and past it the model just drops your words. Most people only discover that when a long prompt stops responding to itself. TokenCounter tells you, before you generate, exactly how many tokens your prompt takes against the CLIP model you're actually using - and it does it with the real tokenizer, so the number isn't a guess.
It's a vendored node from JNodes (the KJNodes family) that MaraScott bundled under its own namespace - same code, same behavior. It's an output node, so the count shows up in the UI after each run.
How it works
You give it text and a clip (wire in the CLIP you're conditioning with). It cleans the text first - stripping prompt weight syntax like (word:1.2) and :0.8, removing parentheses and embedding: prefixes - so you're counting the words the model will actually consume, not the syntax around them. Then it runs the CLIP tokenizer on the cleaned text and counts tokens, excluding the padding/end token.
The output COUNT_AS_STRING is the useful one: it reports N / MAX against the model's sectioned limit - like 45 / 75 for a single SD1.5-style section, or 120 / 150 for two sections. That "how full is my budget" framing is what actually matters.
Inputs: text (STRING), clip (CLIP). Outputs: COUNT (INT - the raw token count), COUNT_AS_STRING (STRING - the N / MAX display).
Using it
Drop it on any prompt you care about, wire the CLIP in, and run once. If you're over 75 for SD1.5-style models, words are getting cut - trim or reorder so the important stuff lands early. For SDXL/Flux you have more headroom but the same logic applies. It's also a great teaching tool: instead of guessing why a long negative prompt does nothing, you can watch the count climb past the limit and know the tail was silently dropped.
Installing it
Ships in the MaraScott pack: ComfyUI Manager β search "MaraScott" β Install β restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MaraScott/ComfyUI_MaraScott_Nodes
Then restart. Note the pack pins transformers==4.37.2 in requirements, which can collide with other packs wanting newer versions - that's the one real install gotcha here.
Common issues
The count is only as meaningful as the CLIP you wired in - counting against an SD1.5 CLIP when you're prompting SDXL gives you the wrong budget, so wire the actual CLIP you use. The text cleaning also means heavily weighted prompts report lower than a naive count; (word:1.2) becomes just word, which is correct for what the model consumes but can surprise you if you were comparing against a character count. And like any vendored node, it won't update on its own - you get the version bundled when you installed the pack.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | β | |
| clip | CLIP | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| COUNT | INT | β |
| COUNT_AS_STRING | STRING | β |