Counter (from file) v1.2.1
A counter that survives restarts, because it lives in a file — perfect for dataset loops
- loop_count
This is the boring, invaluable node at the heart of the pack's dataset-captioning pipeline. It's a counter with no inputs and one output: every time the workflow runs, it reads the current count from a JSON file, hands you that number, and writes the next number back. That's the entire trick - state that lives in loops.json in your ComfyUI output folder instead of in memory, so it survives restarts, crashes, and workflow saves.
Why you'd reach for it: batch work where each queue processes one item. The pack's own vision pipeline wires this into a batch image loader's image_index - queue once, get image 0; queue again, the counter has advanced, get image 1 - and a Save Dataset Caption node follows along writing the matching .txt. Because the value persists on disk, you can close ComfyUI, come back tomorrow, and it picks up exactly where it left off instead of resetting. Nothing in stock ComfyUI does that out of the box, which is why people build counter nodes in the first place.
Mechanism details that matter:
- It's deliberately marked as always-changed (
IS_CHANGEDreturns a random value), so ComfyUI never caches it and every queue re-executes it. That's required for the counter to advance, but it also means your whole workflow re-runs on every queue even if nothing else changed. Plan for that if you're chaining expensive generation after it. - No file on first run? It starts at 0 and saves 1 for next time. It returns the current value and writes current + 1.
- The
loop_countoutput is an INT, ready to feed animage_indexor batch-index input.
The reset story: there's a sibling node in the same pack, Reset Counter (to file), with a trigger button that writes 0 back into loops.json. Or just delete the file. Both work, and both are worth knowing because you will need to reset mid-project.
The trap worth flagging: the file is shared. Every workflow using this node reads and writes the same output/loops.json. Run two different projects through it and they'll step all over each other's counts - a second dataset will pick up wherever your first one left off. It's a one-project counter, so reset between projects (or delete the file) before you start a new batch. That's a real footgun, and the node gives you no way to pick a different file path.
Install. ComfyUI Manager → search comfyui_AcademiaSD → install → restart, or cd ComfyUI/custom_nodes && git clone https://github.com/AcademiaSD/comfyui_AcademiaSD. No extra Python dependencies. Small-creator pack (the Academia SD channel) with a thin community footprint - the GitHub issues page is where fixes actually land.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| loop_count | INT | — |