Nodes/Comfyui-In-Context-Lora-Utils/Concatenate Context Window
ComfyUI Node Runs on cloud

Concatenate Context Window

The v2 composer for IC LoRA windows — this is the one to reach for

By lrzjason·Created 2 years ago·Updated about a year ago· 246
Concatenate Context Window
  • first_image
  • second_image
  • second_mask
  • IMAGE
  • MASK
  • target_width
  • target_height
  • x_offset
  • y_offset
  • total_width
  • total_height
patch_modeauto
patch_type3:4
output_length1536
patch_color#FF0000

ConcatContextWindow is the modern replacement for the pack's older AddMaskForICLora, and it's the one you should build new workflows on. When lrzjason rebuilt this pack in late November 2024, this node came out of that rewrite: the same "compose the two-panel context window" job as its predecessor, but with explicit aspect-ratio control and cleaner handling of the second image and mask.

If you're not up on the genre: an in-context LoRA is trained on FLUX.1 Fill to take a composed image - reference subject on one side, empty patch on the other - and fill the patch with the subject. ConcatContextWindow assembles that composed image. Give it one image and it lays the reference into one panel, fills the other with a solid color, and produces the composed canvas plus the mask that tells the model where to generate.

How it works

first_image is fitted into the reference panel (resize, pad, or center-crop - whichever the target ratio demands), and second_image is optional; give it one and both panels get real content, leave it out and the second panel becomes a solid patch_color block. The panels are then concatenated with hstack (patch_right) or vstack (patch_bottom) per patch_mode. The output MASK is the part that actually matters: zero over the reference panel, one over the patch panel (or your second_mask) - exactly the "generate here, keep the rest" signal FLUX.1 Fill's masked conditioning wants.

The inputs that matter

  • patch_mode - auto (default) picks patch_right vs patch_bottom from your image's orientation.
  • patch_type - 3:4 (default), 1:1, 9:16. This is the real upgrade over AddMaskForICLora, which can't set the panel ratio. Match it to the LoRA's training aspect.
  • output_length - 1536 default, silently snapped to a multiple of 64.
  • patch_color - the hex filling the empty panel (#FF0000 default). Not cosmetic: IC LoRAs are often trained on a specific patch color, and a mismatch can bleed into the fill.
  • Optional second_image and second_mask for the two-real-images variant.

Outputs

IMAGE and MASK feed straight into the Fill conditioning. Then the bookkeeping: x_offset/y_offset give the top-left of the patch panel inside the composed canvas - that's how a downstream ImageCompositeMasked knows where to paste the generated result back onto the original - and target_width/target_height/total_width/total_height describe the panel and full canvas.

How it sits in a real workflow

In the author's own "context window inpaint" example, this node feeds a Redux reference pass (StyleModelLoader + CLIPVisionEncode + StyleModelApply) plus InpaintModelConditioning into FLUX.1 Fill, and the offsets drive the composite back. That maps cleanly onto why this whole genre exists: FLUX.1 Fill is still the only open checkpoint actually trained for masked inpainting (the KB's inpainting essay hammers this), and these nodes just frame "reference one half, generate the other" in the way Fill is best at.

Installing it

One install gets you the whole pack:

cd ComfyUI/custom_nodes && git clone https://github.com/lrzjason/Comfyui-In-Context-Lora-Utils

then restart. Or ComfyUI Manager → search "Comfyui-In-Context-Lora-Utils". No pip deps in the pyproject - pure numpy/OpenCV - but the surrounding workflow needs FLUX.1 Fill, the T5 + CLIP-GmP encoders, the Flux VAE, Redux + SigLIP (all linked in the README), plus the in-context LoRA itself from Civitai.

Gotchas

Same family traits as the rest of the pack: DEBUG = True prints ===debug=== noise to the console on every run, only the first frame of a batch is processed, and it imports cv2 at module load (a bare ComfyUI env can throw ModuleNotFoundError: cv2 until you pip install opencv-python). And the honest 2026 note: instruction-edit models like Klein and Qwen-Image-Edit now do try-on and outpainting from a sentence, so this genre is aging - but for "reference this subject, generate its counterpart" with a stable identity and real positional control, it's still the cheapest and most predictable route.

CategoryInContextUtils/ConcatContextWindow

Inputs (7)

NameTypeDefaultDescription
first_imageIMAGE
patch_modeCOMBOauto3 options: auto, patch_right, patch_bottom
patch_typeCOMBO3:43 options: 3:4, 1:1, 9:16
output_lengthINT1536
patch_colorCOMBO#FF00004 options: #FF0000, #00FF00, #0000FF, #FFFFFF
second_imageoptIMAGE
second_maskoptMASK

Outputs (8)

NameTypeDescription
IMAGEIMAGE
MASKMASK
target_widthINT
target_heightINT
x_offsetINT
y_offsetINT
total_widthINT
total_heightINT