MD: Filename Counter
The counter that never resets when you blink
- formatted_counter
- current_value
- info
Every workflow eventually wants numbered output - #0001, #0002, and so on. The naive way is a counter widget that resets the moment ComfyUI restarts. FilenameCounterNode is the version that survives restarts, because the count lives in a JSON file on disk rather than in the node's memory.
That persistence is the whole trick. Each counter is keyed by a context_key - give different projects different keys and they count independently - and the current value is stored in md_filename_counters.json under ComfyUI's input directory. Close the app, come back tomorrow, and Daily_Renders picks up exactly where it left off.
How to use it
Four required inputs cover the basics:
context_key- the counter's name.default_counteris fine for a single project; use something likeProject_Alphaper project to keep counts separate.start_value- where counting begins (default 1).increment- how much each run adds (default 1).padding- zero-padding width. 4 gives0001; 8 gives00000001. Handy when filenames need to sort alphabetically.
The optional inputs are where the flexibility lives. prefix and suffix wrap the number - the default prefix # turns 1 into #0001. reset_counter forces the value back to start_value when you want a fresh batch. And trigger is the quiet star: ON means "increment and save," OFF means "read-only" - return the current value without touching it. That's perfect for previewing a filename before you commit to advancing the count.
Outputs
Three wires: formatted_counter (STRING, the padded, prefixed text - this is what you paste into a filename template or a Save node's prefix), current_value (INT, the raw number), and info (STRING, a human-readable summary of what the node did - initialized, incremented, reset).
A clean pattern: feed formatted_counter into the filename_prefix of a save node alongside a date, and every render gets a unique, sortable, non-overwriting filename. It pairs just as naturally with this pack's FilenameTokenReplacer - drop {counter} into a template and let this node supply the value.
Installing it
Part of MD Nodes (MDMAchine/ComfyUI_MD_Nodes). ComfyUI Manager → search MD_Nodes → Install, then restart. Or manually:
cd path/to/ComfyUI/custom_nodes
git clone https://github.com/MDMAchine/ComfyUI_MD_Nodes.git
cd ComfyUI_MD_Nodes
pip install -r requirements.txt
Restart ComfyUI. Usual pack notes: Python 3.10+, GPL v3, pure Python.
Common issues
The classic confusion is expecting the counter to advance when trigger is off - it won't, by design; that's the read-only mode. And because the node always considers itself changed (it forces a re-run each queue), it won't silently skip counts in batch mode. If you reset a counter and it looks wrong, check that context_key matches the one that was counting - separate keys are separate counters, and it's easy to create a second counter under a new name instead of resetting the first.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| context_key | STRING | default_counter | CONTEXT KEY • Purpose: Unique name to identify this counter in the JSON save file. • Usage: Use different keys for different projects to keep counts separate. ⭐ e.g., 'Project_Alpha', 'Daily_Renders' |
| start_value | INT | 10–999999 | START VALUE • Purpose: Initial value if key doesn't exist or is reset. |
| increment | INT | 11–100 | INCREMENT • Purpose: Amount to increase counter by on each run. |
| padding | INT | 40–8 | ZERO PADDING • Purpose: Number of digits to pad (e.g. 4 padding -> 0001). |
| reset_counteropt | BOOLEAN | false | RESET COUNTER • Purpose: If True, forces counter back to 'start_value'. |
| prefixopt | STRING | # | PREFIX • Purpose: String added before the number (e.g., '#0001'). |
| suffixopt | STRING | SUFFIX • Purpose: String added after the number. | |
| triggeropt | BOOLEAN | true | TRIGGER • Purpose: Controls if the counter saves and advances. • ON (Increment): Updates value and saves to disk. • OFF (Read Only): Returns current value without changing it. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| formatted_counter | STRING | — |
| current_value | INT | — |
| info | STRING | — |