Nodes/ComfyAngel/Loop Start 🪽
ComfyUI Node

Loop Start 🪽

Iterate a batch in ComfyUI without touching Auto Queue

By ThepExcel·Created 8 months ago·Updated about a month ago· 14
Loop Start 🪽
  • items
  • flow
  • item

The thing everyone eventually wants in ComfyUI is "take these 20 prompts and run the same workflow on each one." The classic answer is Auto Queue - re-queue the graph, let a seed-incrementing node walk through a list - and it works, but it's slow and it scatters results across multiple runs. Loop Start 🪽 is the other way: it turns a batch into a single graph that runs every item in one pass, and it's the front door of ComfyAngel's loop system.

What it does

You feed it items - an IMAGE batch, a list of strings, a list from the folder loader, almost anything iterable - and it hands back two outputs:

  • flow - the control wire. It must connect to a Loop End; that's the loop's spine.
  • item - the current element of the batch for this iteration. Iteration 0 gives you the first string/image, iteration 1 the second, and so on.

Everything between Loop Start and Loop End runs once per item. Wire item into a prompt, a KSampler, an overlay, whatever, and the whole middle of your graph re-executes for each element. The classic example from the README: feed it ["cat on chair", "cat on sofa", "dog on chair", "dog on sofa"] and each iteration gives you one prompt to process.

How it actually works

Here's the honest mechanism, because it explains the gotchas. Loop Start doesn't literally "loop" - ComfyUI's execution engine doesn't do cycles. Instead, Loop End (the node you'll read next) builds a new graph at runtime using ComfyUI's dynamic graph machinery (comfy_execution), re-creates everything inside the loop with the next index, and recurses until an internal comparison says the index hit the total. Loop Start's flow output is really a packed state - current index plus accumulated values - which the Loop End unpacks to keep the recursion moving. That's why the nodes need a reasonably modern ComfyUI build; on an old one you'll get a RuntimeError about the comfy_execution module, not a pretty message.

The items input is declared as a list (INPUT_IS_LIST), and an empty batch raises a clear error: "Cannot loop over empty items." The one subtlety beginners hit is feeding it a single batched tensor - a (20, H, W, C) image tensor - and expecting per-image items. That works: the node pulls item as a one-image tensor slice per iteration.

Installing it

ComfyAngel is one pack, this is one node in it:

cd ComfyUI/custom_nodes
git clone https://github.com/ThepExcel/ComfyAngel.git

Restart ComfyUI, or search "ComfyAngel" in ComfyUI Manager. Just Pillow as a dependency, no model downloads.

Where people get burned

Three things, in rough order of frequency. First, forgetting the Image Bridge - without a preview/save node inside the loop you'll see nothing until it's done, which makes a 20-item run feel broken. Second, memory: every iteration accumulates results in RAM, so huge batches will balloon; for truly enormous jobs the README suggests Split Image Batch + Auto Queue instead. Third, mismatched shapes in the middle of the loop - see the Accumulate article for why your collected results can silently become a list instead of a batch. Loop Start is the easy part; the discipline is all in what you put between it and the End.

CategoryComfyAngel/Loop

Inputs (1)

NameTypeDefaultDescription
items*Batch/list to iterate over

Outputs (2)

NameTypeDescription
flowFLOW_CONTROL
item*