Nodes/ComfyUI-ArchiGraph/Iterate Items πŸ¦β€πŸ”₯
ComfyUI Node

Iterate Items πŸ¦β€πŸ”₯

The ComfyUI loop that re-runs the whole graph for you

By vincentfsΒ·Created 2 years agoΒ·Updated 9 months agoΒ· 3
Iterate Items πŸ¦β€πŸ”₯
  • items
  • item
  • index
β—„iteration_ontrueβ–Ί

ComfyUI doesn't have loops. It's a directed acyclic graph, and that's mostly fine - until you want to run the same pipeline once per prompt, once per image in a folder, once per item in a list. That's what this node is: feed it a list, and it hands you one item at a time while the workflow re-runs itself until the list is exhausted.

How it works - and it's a bit rude

The node keeps an internal index, returns items[index], then hacks the prompt queue to re-enqueue the entire running workflow with a fresh prompt id. ComfyUI just runs your graph again, the node advances its index, and so on until you've walked the whole list. It's not a for-loop node in the sense of a single execution - it's "repeat this whole graph N times, give me one item per pass." That's the entire secret of these iterate nodes, and it's worth knowing before you use one, because it means everything downstream of it (and anything else in the graph, including Save Image) executes once per item.

Outputs are item (any type - whatever's in your list) and index (INT, 0-based). The iteration_on toggle defaults to true, and its whole job is to force the node to re-run even if the input list hasn't changed - the node's change-detection returns NaN so ComfyUI never caches it. Turn it off if you only want a single pass.

Where it shines

  • Batch prompt generation: feed it a list of prompt strings, iterate, and let a text node plus KSampler run each one.
  • Folder/batch processing: pair it with a list of file paths from something like the pack's Filename List node.
  • Rendering a series of images where each one needs a different item injected into the pipeline.

The index output is genuinely useful - use it to name output files (AG_0003.png) so each pass doesn't overwrite the last.

Realistic complaints

Because each pass re-runs the entire graph, a slow pipeline means the node "costs" a full generation per item. That's expected, but people get surprised when their expensive sampler runs 10 times for a 10-item list. Also, since it re-queues the current prompt rather than a trimmed version, any output nodes elsewhere in your graph fire on every pass - keep iteration passes isolated, or accept the repeated saves.

There's also a statefulness trap: the index lives on the node instance in memory. If you change the list length mid-run or hit refresh, the counter can sit at the wrong position. When things look off, rerun the whole queue from a clean state.

Install

In ComfyUI Manager, search ComfyUI-ArchiGraph, or:

cd ComfyUI/custom_nodes
git clone https://github.com/vincentfs/ComfyUI-ArchiGraph

Restart ComfyUI and run the pack's install script once so its dependencies land. No models involved.

Verdict

It's the honest way to do per-item batch work in a graph that doesn't want to loop, and it's the same trick every "iterate" custom node in this space uses. Just don't put it in a graph with heavy outputs and expect anything subtle - it will happily run that graph N times.

CategoryπŸ¦β€πŸ”₯ ArchiGraph/πŸ› οΈ Utils

Inputs (2)

NameTypeDefaultDescription
items*Input a list to iterate over its items.
iteration_onBOOLEANtrueAlways re-run this node, even if the input list is unchanged.

Outputs (2)

NameTypeDescription
item*β€”
indexINTβ€”