Nodes/BrainDead Nodes/BD Save Context
ComfyUI Node

BD Save Context

Kill the concat-string filename spaghetti

By BizaNator·Created 8 months ago·Updated 3 days ago· 15
BD Save Context
    • context_id
    • status
    context_iddefault
    template%project%/%character%/%subfolder%/%character%_%name%_v%version%%suffix%
    character
    name
    version01
    project
    base_dir
    subfolder
    tag
    custom_vars
    auto_incrementtrue
    increment_padding3
    strictfalse

    Every serious ComfyUI workflow eventually turns into a pile of filename builders - a text concat node here, a string join there, and suddenly your save nodes are fed by something that looks like a Perl one-liner. BD Save Context is the BrainDead pack's answer: define the path template and variables once, and every downstream save node resolves its own filename from it. It's the rare plumbing node that actually deletes nodes from your graph.

    What it is

    A context-definition node. You give it a context_id (a name), a template, and a set of variables, and it registers that context globally. Any BrainDead save node - BD Save File, BD Bulk Save, BD Save Batch, BD Save MP Face Data - can then look it up by id and resolve a full path without you typing the path anywhere else.

    How it works

    The template is a %varname% pattern:

    %project%/%character%/%subfolder%/%character%_%name%_v%version%%suffix%
    

    Each save node that uses the context just supplies its suffix (e.g. _albedo, _skin_mask, _head) and the context fills in the rest. So one context named default with project=biloxi, character=letti, name=topwear, version=03 turns _albedo into biloxi/letti/letti_topwear_v03_albedo_001.png automatically. Add a save point later by wiring the same context_id - no string surgery.

    Details worth knowing:

    • Empty %vars% collapse cleanly - a/%b%/c with b="" becomes a/c. Undefined vars stay as literal %var% text, which is deliberate: it surfaces typos instead of silently writing weird filenames. Flip strict on if you'd rather it hard-error.
    • base_dir sets the root; empty means ComfyUI's output folder. You can also use an alias from the BD_SAVE_ALIASES env var, with optional lockdown via BD_SAVE_ALLOWED_ROOTS.
    • auto_increment (default on) appends _NNN so you don't overwrite - padding set by increment_padding.
    • Per-save custom_vars (key=value lines) layer on top of the context's own custom_vars, and this node's custom_vars are available to every save under it.

    The inputs

    context_id (make it meaningful if you run several - character_v1 vs mannequin_v1), template, and the convenience vars character, name, version, project, subfolder, tag. Outputs: context_id (so you can wire it explicitly) and status.

    The gotcha

    Auto-pick. If context_id is empty on a downstream save node and exactly one context is registered, the save node uses it silently. That's convenient and it's also how you save a file to a surprising location when you forgot you registered a context earlier in the graph. With multiple contexts registered, an empty id means the save node falls back to legacy behavior - so if saves stop following your template, check whether a second context got registered.

    Installing it

    ComfyUI Manager: search "BrainDead" → install. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/BizaNator/ComfyUI-BrainDead
    cd ComfyUI-BrainDead
    pip install -r requirements.txt
    

    Restart, find it under 🧠BrainDead/Cache. The canonical use from the README: one Save Context + a BD Bulk Save with labels=albedo,normal,roughness,metallic,ao → seven PBR maps land in the right folders in one run, and the whole graph stays readable. That's the payoff - you're not saving files, you're getting your workflow back.

    Category🧠BrainDead/Cache

    Inputs (13)

    NameTypeDefaultDescription
    context_idSTRINGdefaultIdentifier for this save context. Save nodes match by this id. Use distinct ids if you have multiple parallel contexts (e.g. 'character_v1' and 'mannequin_v1').
    templateSTRING%project%/%character%/%subfolder%/%character%_%name%_v%version%%suffix%Base template with %varname% placeholders. The save node's `suffix` input is appended to this template before resolution. Use %suffix% in the template to control suffix placement (defaults to end if omitted). Empty %vars% are cleaned up — `//` collapses to `/`.
    characteroptSTRING
    nameoptSTRING
    versionoptSTRING01
    projectoptSTRING
    base_diroptSTRINGRoot directory for saves. Empty = ComfyUI output dir (default, backward-compatible). Otherwise an absolute path the template resolves under — works cross-platform, e.g. 'D:/MyImages' or '/mnt/data/assets'. You can also use a short alias defined via the BD_SAVE_ALIASES env var. Optional lockdown via BD_SAVE_ALLOWED_ROOTS.
    subfolderoptSTRINGSub-organization within the output folder — e.g. a category or stage name. Empty cleans up to nothing in the path.
    tagoptSTRINGGeneric tag — typical use: part name like 'face', 'topwear', 'arm-l'.
    custom_varsoptSTRINGAdditional variables, one per line as key=value. e.g. resolution=4096, layer=topwear.
    auto_incrementoptBOOLEANtrueAppend _NNN to avoid overwriting. Applies to ALL save nodes using this context.
    increment_paddingoptINT30–10
    strictoptBOOLEANfalseIf True, save nodes raise an error when the template contains undefined %variables% at save time.

    Outputs (2)

    NameTypeDescription
    context_idSTRING
    statusSTRING