Nodes/ComfyUI-Loop/♾️ Loop Any
ComfyUI Node

♾️ Loop Any

Write a file, load it back, improve the result

By Hullabalo·Created 2 years ago·Updated 8 months ago· 14
♾️ Loop Any
  • input
  • mask
  • output
  • path
  • width
  • height
  • mask
loop_filefalse
filenameloop_file
subfolder
loop_maskfalse

Here's a workflow you hit constantly in manual inpainting: render the region, look at it, decide it needs another pass, fix it, render again. The first pass is easy to build in ComfyUI. The repeat is the hard part, because nothing in the graph carries state between runs. Loop Any (LoopAny) is the state. It's one half of ComfyUI-Loop's file-loop pair (with ♾️ Save Any), and its whole trick is that it saves your input to a file in /output and then, on the next run, loads that same file back. Suddenly "run it again" means iterate, not redo.

How the loop works

The mechanism is almost stupidly simple, which is why it's reliable. Loop Any takes your input, writes it to /output/<subfolder>/<filename> (extension inferred from the input type), and then - here's the loop - if loop_file is on and that file already exists, it loads the existing file instead of writing a new one. So the first run seeds the file, and every run after that starts from the previous run's output. You get iteration with zero Python: run the graph, tweak a denoise value, run again, and the input is your own last result.

That "Any" in the name is doing real work. The node pattern-matches the input tensor:

  • 4D image tensor → .png
  • 3D tensor (a mask) → .png
  • a latent dict - and it knows the architectures: 4-channel SD/SDXL latents, 16-channel Flux/SD3/Chroma, 5D Qwen/WAN video latents, even audio latents
  • a {waveform, sample_rate} dict → .flac
  • str/int/float.txt

Same pair of nodes loops images, masks, latents, audio, and text. Most people only ever loop PNGs, but the audio and latent paths are genuinely useful for img2img and audio-inpainting workflows.

The inputs that matter

  • loop_file - the loop toggle. On: load the existing file each run. Off: just write a fresh file (that's your "first pass" mode).
  • filename - base name without extension, default loop_file. The extension is added automatically from the input type.
  • subfolder - where in /output to read/write. Leave empty for the root.
  • loop_mask - on, the node reads the mask from the PNG's alpha channel instead of the mask input. This is the inpainting link: Save Any can write a mask into the alpha, and Loop Any pulls it back out on the next pass.
  • mask (optional) - the mask to use when loop_mask is off.

Outputs: output (the loaded or fresh data - wire it into whatever does the actual work), path (the full file path - feed this straight into Save Any so the loop writes back to the same file), plus width/height and mask for images.

What it's actually for

The README is blunt: "primarily intended for inpainting workflows." The shape is Loop Any → your sampler/edit pipeline → Save Any, with path wired across. Each re-run refines the previous result instead of starting over, and because unmasked pixels flow through untouched, drift doesn't compound the way it does with whole-frame edit models. Run it, eyeball it, change the denoise, run again - that's the workflow this node exists to make pleasant.

Install and gotchas

Same as every node in this pack: no dependencies, no models. ComfyUI Manager → search "Loop" → ComfyUI-Loop, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Hullabalo/ComfyUI-Loop

Three things will bite you:

  • It overwrites the file every run. That's the point, but it means work on a copy of any source you care about, or you'll discover why the README screams about it.
  • No batch or list support. Batch inputs just don't work - this is a single-image/single-file loop.
  • Not Nodes 2.0 compatible. Tested on ComfyUI 0.3.64–0.8.2 with the legacy frontend; the new Vue-based canvas breaks it, and the author says it will likely never be ported.
CategoryLOOP

Inputs (6)

NameTypeDefaultDescription
input*
loop_fileBOOLEANfalseEnable image loop mode. Disable to load from image input
filenameSTRINGloop_file(fac.) Filename of loop file without extension. Define/Use an existing file to load from /output or its subfolders.
subfolderSTRING(fac.) Subfolder to load or copy input file. Default root to /output
loop_maskBOOLEANfalseEnable mask loop mode. Disable to load from mask input
maskoptMASK

Outputs (5)

NameTypeDescription
output*
pathSTRING
widthINT
heightINT
maskMASK