ComfyUI Node

Write Text

The node that finally saves a .txt file from ComfyUI

By kale4eat·Created 2 years ago·Updated 2 years ago· 0
Write Text
      text
      file_nametext.txt
      filename_prefixComfyUI
      mode
      encodingutf-8
      newline

      The name is doing exactly what it says, which is rarer in ComfyUI than it should be: this node takes the text you feed it and writes it to a .txt file on disk. It sounds trivial until you realize how much of the workflow-sharing culture runs on text that never gets saved. The prompt that made the image you're staring at lives only in PNG metadata, and stock ComfyUI has no built-in way to dump it to a plain text file. That's the gap text_file_util_WriteText fills - and for a lot of people the moment that matters is the first time they try to build a LoRA dataset and realize every image needs a matching .txt sidecar.

      This is a tiny, honest pack. The whole thing is one Python file with no dependencies beyond ComfyUI's own folder_paths module - no requirements.txt, no pip install, no model downloads. The README is literally one line. It ships five text I/O nodes under the text-file-util category in the node menu, and this is the most-used one.

      How it works

      Feed a string into text, pick a mode, and the node writes the file on every queue run. Two mechanics are worth understanding before you wire it up.

      Where files land. The pack creates two folders right next to ComfyUI's own code, not in your normal output/ directory: a text_input/ and a text_output/ folder in the ComfyUI install root. So this node writes to ComfyUI/text_output/. This is the #1 thing people hit - they save, queue, and then go hunting in output/ for a file that's sitting in text_output/ instead.

      How the filename is built. filename_prefix and file_name combine into <prefix>_<file_name>. Defaults give you ComfyUI_text.txt. But filename_prefix is a path, not just a name: put logs/prompts in it and the file goes to text_output/logs/prompts_text.txt. Handy for keeping runs organized.

      The inputs that matter

      • text - what gets written. Wire a prompt, a positive/negative pair, anything that resolves to a string.
      • mode - w overwrites the file, a appends. The one that bites people.
      • filename_prefix + file_name - decide where the file lands, as above.

      The optional bits are less exciting: encoding defaults to utf-8 (leave it), and newline lets you force LF, CRLF, or the weird LFCR (\n\r) when you care about line endings. Windows users feeding files to other tools often want CRLF.

      Installing it

      Via ComfyUI Manager, search for ComfyUI-text-file-util. Or the manual route:

      cd ComfyUI/custom_nodes
      git clone https://github.com/kale4eat/ComfyUI-text-file-util
      

      Restart ComfyUI and you're done - there's no dependency step to trip over, which is a pleasant surprise in a custom node ecosystem that usually means "fix one error and another appears."

      Where people get burned

      The classic trap is mode = w combined with a batch. If you queue 20 images and every run writes the same ComfyUI_text.txt, each run truncates the last one - you finish with only the final prompt. That's not a bug, it's what overwrite means, but it catches everyone once. Append mode fixes logging, and if you want a fresh unique file every run without thinking about it, the same pack's Write Text With Sequential Numbering node is the better tool - it auto-increments the filename like ComfyUI does for image saves.

      The other gotcha is just knowing where to look: text_output/ at the ComfyUI root, not output/. Check there first before you assume the write failed.

      Categorytext-file-util

      Inputs (6)

      NameTypeDefaultDescription
      textSTRING
      file_nameSTRINGtext.txt
      filename_prefixSTRINGComfyUI
      modeCOMBO2 options: w, a
      encodingoptSTRINGutf-8
      newlineoptCOMBO3 options: LF, CRLF, LFCR

      Outputs (0)

      No outputs