Load Most Recent Image
Load the Newest Image in a Folder Automatically
- image
- mask
You know the dance: you hit generate in some other tool, then drag the fresh PNG back into ComfyUI's Load Image node, then re-run. Repeat it enough times and you start wondering why you're still doing this by hand. Load Most Recent Image is the answer to that specific, small, very real annoyance. Give it a folder path and it does the dragging for you - it finds the newest image in that folder, loads it, and hands it to the rest of your graph.
It's basically the built-in Load Image node minus the file picker. Instead of you choosing a file from ComfyUI's input folder, it scans any folder on disk you point it at and picks the file with the newest modification timestamp. The README calls this "do-over" territory, and that's the honest framing: it's for iteration loops where you keep re-feeding your own latest output back into a workflow, or for pulling in a file that some other program (A1111, a game, a screenshot script) just dropped on disk.
How it works
The mechanism is about as straightforward as it gets, and the source confirms it. The node globs the folder with your extension list, sorts every match by modification time newest-first, and grabs whichever position you asked for. index 0 is the most recent file, 1 is the second-most-recent, and so on up to 1000. It then opens the file with PIL, converts it to a tensor, and returns it with the standard IMAGE output plus a MASK output.
Two details are worth knowing. First, the mask is the inverted alpha channel - opaque pixels become 0, transparent pixels become 1 - which is the exact convention ComfyUI's own Load Image uses. So if you're wiring this into an inpainting or compositing workflow, the mask semantics are what you already expect. Images with no alpha get a full-white (opaque) mask.
Second, and this is the clever bit: the node implements IS_CHANGED by returning the selected file's modification time. ComfyUI sees a new value and re-runs everything downstream. Drop a fresh image into the watched folder and your whole chain re-executes without you touching a node. That live-refresh behavior is the whole point of the node.
The inputs that actually matter
folder_path- the only required input, and the one you'll always set. Full path to a directory on disk; unlike the built-in Load Image it does not have to be insideComfyUI/input.image_extensions- comma-separated, defaults tojpg,jpeg,png,bmp,tiff,tif,webp. The search is case-insensitive (it checks both cases), so.PNGfiles get found too.index- which file to load by recency. Keep it at 0 for "just give me the newest"; bump it to 1 when you want to compare the latest generation against the previous one.
Outputs are image (IMAGE tensor) and mask (MASK), wired into whatever sampler, inpainting, or compositing nodes you already use.
Installing it
No model files, no hidden downloads, no dependencies you don't already have. The requirements are torch, torchvision, Pillow, and numpy - every one of those ships with ComfyUI, so this install is effectively a copy-and-restart. ComfyUI Manager can find it under the pack title "ComfyUI Load Most Recent Image Node," or clone it directly:
cd ComfyUI/custom_nodes
git clone https://github.com/benstaniford/comfy-load-last-image
Then restart ComfyUI. That's the whole install.
Where people get burned
The README's own top troubleshooting entry is the one you'll actually hit: "Invalid image file" when the newest file in the folder is still being written. A partially-flushed PNG gets picked, fails PIL's validation, and the node errors. If you're watching a folder that another process is actively filling, this will happen to you - let the writer finish before your workflow runs, or accept the occasional red error as the cost of automation.
Two more gotchas the docs don't advertise. First, the scan is not recursive - it only looks at files directly in folder_path, not subfolders. Second, "most recent" is a silent contract: if a screenshot or unrelated file lands in that folder, index 0 quietly becomes that file and your results change with no obvious reason why. For a utility this small that's the trade-off you sign up for.
One last thing worth flagging: this pack is young and clearly a small side project - the README's clone instructions still contain placeholder your-username URLs, so don't copy-paste those literally. Use the URL above or Manager. Small package, narrow job, and it does that job cleanly.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| folder_path | STRING | — | |
| image_extensionsopt | STRING | jpg,jpeg,png,bmp,tiff,tif,webp | — |
| indexopt | INT | 00–1000 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |