Nodes/NH-Nodes/Counter (NH)
ComfyUI Node

Counter (NH)

A counter that remembers between queue runs, so your loop knows where it is

By jetthuangai·Created 5 months ago·Updated 21 days ago· 6
Counter (NH)
    • current
    • is_done
    • progress
    • remaining
    start0
    step1
    max_value9
    resetfalse

    Most nodes in ComfyUI are stateless: run them a hundred times and they do the same thing a hundred times. Counter (NH) is the deliberate exception. It keeps a number in memory between queue runs and ticks it forward each time you hit the queue button. That statefulness is exactly what batch-style workflows need - "I've done 3 of 12, do the next one" - and it's why you'll find it in every workflow that processes a folder or a list one item per run.

    How it works

    You configure four things:

    • start - where the count begins (default 0).
    • step - how much it ticks each run (default 1, minimum 1).
    • max_value - the ceiling that makes is_done fire.
    • reset - flip this to true (or back) to snap the counter back to start.

    Internally the node stores its state in memory keyed to the node instance, so each Counter (NH) in your graph is independent. Every time the graph runs, it returns the current value and immediately increments for the next run. That one detail is the whole trick: the value you see this run is the number you use this run, and the counter is already one ahead for next time.

    Outputs:

    • current - the number for this run.
    • is_done - true once current passes max_value. Your loop-exit flag.
    • progress - current / max_value, clamped to 1.0. Feed it to a progress bar or a Math Eval (NH) to scale something.
    • remaining - how many ticks are left including this one.

    The loop pattern

    The standard combo: Counter → Batch Index (NH) (or List Index (NH)) → process one item → done. Each queue run advances the counter by one and pulls the next image or prompt. When is_done goes true, a Gate Switch (NH) or If/Else (NH) can stop the pipeline or trigger a save. It's the poor-man's iteration, and for a folder of 20 images it's genuinely the most reliable loop in ComfyUI - better than graph-internal repeat nodes that fight you over state.

    The catch you have to respect

    Because the state lives in the running process, it resets whenever you restart ComfyUI, and it advances on every run - including the runs where you were just testing and didn't mean to consume an item. The reset toggle exists precisely for that "oops, I ran it twice" moment. When in doubt, flip reset, run once to re-home the counter, and flip it back. It's janky, but it's a known jank, not a mystery.

    Installing

    cd ComfyUI/custom_nodes
    git clone https://github.com/jetthuangai/NH-Nodes.git
    cd NH-Nodes
    pip install -r requirements.txt
    

    Or install NH-Nodes via ComfyUI Manager and restart. No models, no extra dependencies.

    CategoryNH-Nodes/Batch

    Inputs (4)

    NameTypeDefaultDescription
    startINT0
    stepINT1
    max_valueINT9
    resetBOOLEANfalse

    Outputs (4)

    NameTypeDescription
    currentINT
    is_doneBOOLEAN
    progressFLOAT
    remainingINT