List Counter (Inspire)
A running index as ComfyUI walks a list
- signal
- INT
Small node, oddly handy. When ComfyUI processes a list, it runs the connected nodes once per item - that's how you loop over, say, a folder of images. The problem is that inside that loop, nothing tells you which iteration you're on. List Counter fixes that: every time an item passes through it, it ticks a counter up by one and outputs the current number. Item one gets 0, item two gets 1, and so on.
That index is the glue for a bunch of batch-automation patterns. Number your output filenames so they don't overwrite each other. Pick the Nth entry out of a parallel list. Gate different behavior on odd vs even iterations. Anytime you're processing a list and need to know your position in it, this is the node.
How it works
ComfyUI's list execution re-runs a node for each element of the list feeding it. List Counter holds a small piece of state that survives across those per-item runs, incrementing on each one. It's the same mechanism that lets Inspire's other iteration tools work - the node "remembers" between executions within a single run. The value it emits is the running count, offset by whatever starting number you set.
The inputs and outputs that matter
Just two inputs, one output:
signal(type*) - the wire that drives the counting. You connect the list you're iterating (any type - it's a wildcard) so that each list item flowing through triggers one increment. The node doesn't care what the signal is; it only cares that it fired.base_value(default 0) - the number the count starts from. Leave it at 0 for zero-based indexing, set it to 1 if you'd rather count from one, or set it to wherever you want the sequence to begin.
The single output is INT - the current count. Feed it into a filename formatter, a list-index node, a math node, wherever you need the position.
How to install it
ComfyUI Manager: search ComfyUI Inspire Pack, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Inspire-Pack
then restart. It's from Dr.Lt.Data, the ComfyUI-Manager and Impact Pack author.
Common issues & troubleshooting
The counter doesn't increment - it's stuck at base_value. This node only counts when it's actually inside list processing. If the signal input isn't a list (it's a single value), the node runs exactly once and you get one number. Make sure the thing driving signal is genuinely a list output, e.g. from Load Image List From Dir or a node marked as outputting a list.
It doesn't reset between runs the way I expected. The count is tied to a single execution over a single list. If you're chaining runs or reusing the graph and seeing an offset you didn't want, that's usually a caching/state artifact - reset by re-queuing fresh, and use base_value to set your intended starting point explicitly rather than assuming it starts at zero.
Off-by-one in filenames. Remember it starts at base_value and the default is 0, so the first item is numbered 0, not 1. If you want human-friendly 1-based numbering, set base_value to 1.
I want the index but I'm not in a list loop. Then this isn't your node - it's specifically for per-item list execution. For a plain counter across queue runs you'd want a different utility.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| signal | * | — | |
| base_value | INT | 00–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |