replacing-backgrounds

Compiles a Visual Intent Object into a ComfyUI background-replacement prompt JSON using inpainting.

Updated Apr 8, 2026
One-click install
npx skills add https://github.com/ShinyGua/ComfyUI-Agent --skill replacing-backgrounds-shinygua
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: replacing-backgrounds
Source: https://github.com/ShinyGua/ComfyUI-Agent/tree/main/.claude/skills/replacing-backgrounds
Command: npx skills add https://github.com/ShinyGua/ComfyUI-Agent --skill replacing-backgrounds-shinygua

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Swapping the backdrop of an image while preserving the subject requires manually wiring a ComfyUI inpaint workflow with the correct mask, prompts, and sampler settings. This Skill automates that by compiling a Visual Intent Object (VIO) into a ready-to-run ComfyUI prompt JSON for background replacement. ## Core Features & Use Cases - Template-driven compilation: Patches a hand-authored SDXL inpaint template with the new background prompt, negative prompt, source image, and background mask. - Parameter overrides: Supports steps, cfg, sampler, scheduler, denoise, seed, and checkpoint overrides from the VIO, with negative seeds resolved to a random value. - Goal validation: Rejects VIOs whose goal is not replace_background, returning a structured JSON error. - Use Case: A planner emits a step with goal=replace_background and a background mask; this Skill produces the exact ComfyUI prompt JSON to regenerate the backdrop at high denoise while keeping the subject intact. ## Quick Start Provide a Visual Intent Object with goal replace_background, a background description prompt, the source image, and a background mask PNG to generate the ComfyUI prompt JSON.

Frequently Asked Questions about replacing-backgrounds

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace the background of an image in ComfyUI?▼

Use an inpaint workflow where the mask covers the background region and denoise is set high (0.95) to force strong regeneration. This Skill compiles a Visual Intent Object containing the new background prompt, source image, and mask into the ComfyUI prompt JSON automatically.

What inputs does background replacement with inpainting require?▼

It requires a source image, a mask PNG covering the background region to regenerate, and a text prompt describing the new backdrop. If no mask is available, a matting step must run first to produce one.

Can I override sampler settings like steps, cfg, and denoise?▼

Yes, the params field of the Visual Intent Object accepts steps, cfg, sampler_name, scheduler, and denoise overrides. A negative seed value is replaced with a time-based random seed, and model.checkpoint overrides the default SDXL checkpoint.

Why does the compile script fail with a goal error?▼

The script validates that the VIO goal equals replace_background and exits with a structured JSON error for any other goal such as inpaint. Ensure the planner step emits goal=replace_background before invoking compilation.

What are the limitations of mask-based background replacement?▼

The approach depends entirely on the quality of the caller-supplied background mask; inaccurate masks cause subject leakage or leftover backdrop. It also regenerates only the masked region, so lighting mismatches between subject and new background may still occur.