---
name: comfyui-image
description: Generate an image with the local ComfyUI (~/Documents/ComfyUI by default; change the paths below if yours lives elsewhere). Starts ComfyUI if it is not running, picks the image model from the prompt (NetaYume Lumina for anime, SDXL for photo/general, SD1.5 for quick drafts), asks the user when the right model is unclear, and when no installed model fits recommends one with the exact folder to put it in, and downloads it for the user if they want. Use when the user asks to generate, draw, render or make an image/picture/illustration with ComfyUI or locally.
---

# comfyui-image

All commands are PowerShell. Workflows live in `~/.claude/skills/comfyui-image/workflows/`. Never edit those files; always work on a temp copy.

## 1. Make sure ComfyUI is running

```powershell
try { Invoke-WebRequest -UseBasicParsing http://127.0.0.1:8188/system_stats -TimeoutSec 3 | Out-Null; "running" } catch { "down" }
```

If it is down, start it and wait (usually ~20s):

```powershell
Start-Process -FilePath python -ArgumentList "main.py" -WorkingDirectory $HOME\Documents\ComfyUI -WindowStyle Minimized
$ok=$false; for($i=0;$i -lt 60;$i++){ try { Invoke-WebRequest -UseBasicParsing http://127.0.0.1:8188/system_stats -TimeoutSec 2 | Out-Null; $ok=$true; break } catch { Start-Sleep 3 } }; "up=$ok"
```

If it is still not up after 3 minutes, tell the user, then stop. Don't try to fix it.

## 2. Pick the model

First list the checkpoints that are actually installed: `Get-ChildItem $HOME\Documents\ComfyUI\models\checkpoints -Name`.

| Prompt is about | Model | Workflow | Default size |
|---|---|---|---|
| anime, manga, waifu, chibi, character art, danbooru tags, illustration in anime style | `NetaYumev35_pretrained_all_in_one.safetensors` | `netayume.json` | 1024x1536 (portrait) / 1536x1024 (landscape) |
| photo, realistic, portrait photo, landscape, product, architecture, general art, painting | `sd_xl_base_1.0.safetensors` | `checkpoint.json` | 1024x1024 |
| user says quick, draft, fast, test, or low quality is fine | `v1-5-pruned-emaonly.safetensors` | `checkpoint.json` | 512x512 |

If the user named a model, use it. If the prompt clearly needs something no installed model does well, go to **2b**. If the prompt fits no row, fits two rows (e.g. "a cute girl in a cafe", "a fox illustration"), or a new checkpoint is installed that isn't in this table, **ask with AskUserQuestion**. List each installed model with a one-line description. Put your best guess first, marked "(Recommended)".

## 2b. No installed model fits: recommend one

Don't silently use a weak fit, and don't download without asking. Tell the user which model to get, its size, the link, and the exact folder to put it in. All paths are under `$HOME\Documents\ComfyUI\models\`.

| Need | Recommended model | Download | Put it in |
|---|---|---|---|
| readable text/logos in the image, best prompt following | FLUX.1 dev fp8 (all-in-one, ~17 GB, needs 12 GB+ VRAM) | https://huggingface.co/Comfy-Org/flux1-dev/blob/main/flux1-dev-fp8.safetensors | `checkpoints\` |
| very realistic people / photoreal | RealVisXL V5.0 | https://huggingface.co/SG161222/RealVisXL_V5.0 (file `RealVisXL_V5.0_fp16.safetensors`) | `checkpoints\` |
| a specific style, character or concept (pixel art, a game style, a person) | a LoRA for SDXL from https://civitai.com (filter: Base Model = SDXL 1.0, Type = LoRA) | that model's page | `loras\` (note: `checkpoint.json` has no LoRA node, so add a `LoraLoader` in a temp copy) |
| anything else | search Hugging Face / civitai for a single-file `.safetensors` checkpoint matching the need | that model's page | `checkpoints\` |

Folder by file type: full checkpoint → `checkpoints\`, LoRA → `loras\`, VAE → `vae\`, diffusion-only weights (`unet`) → `diffusion_models\`, text encoder (`t5`, `clip_l`) → `text_encoders\`, upscaler → `upscale_models\`. If the model page lists several files, name each one and its folder.

For the "anything else" row, search the web yourself (Hugging Face first) and pick one model, so the user doesn't have to.

Then ask with AskUserQuestion: "Download it for me (<size>)", "I'll download it myself" or "Generate now with the closest installed model (<name>)".

**Download it for me:**
1. Check free space first: `[math]::Round((Get-PSDrive C).Free/1GB)` GB. If it's less than the file size + 5 GB, say so and stop.
2. Use the direct file URL: on Hugging Face swap `/blob/` for `/resolve/`. Only download single-file `.safetensors`, never `.ckpt`/`.pt`/`.bin` (they can run code).
3. Run it as a background command (`run_in_background: true`) so you're told when it ends; don't poll:
   ```powershell
   comfy --workspace $HOME\Documents\ComfyUI --skip-prompt model download --url "<URL>" --relative-path "models\checkpoints"
   ```
   Use the folder from the table above (`models\loras`, `models\vae`, ...). Tell the user it's downloading and how big it is.
4. If it fails with 401/403 (civitai and gated Hugging Face models need a login token), don't ask for the token in chat. Tell the user to download it in the browser instead, and which folder to put it in.

After the download finishes or the user says it's downloaded, check the file is in the folder (`Get-ChildItem <folder> -Name`), then run it with `checkpoint.json` (for FLUX fp8 also set `"12.cfg=1" "12.steps=20" "12.sampler_name=euler" "12.scheduler=simple" "11.text="`). ComfyUI picks up new files without a restart; if the run says the file is missing, restart ComfyUI.

## 3. Write the prompt for that model

- **NetaYume**: use comma-separated danbooru-style tags in English, starting with `(masterpiece, best quality:1.2), `. An artist tag `@name, ` can go first. Don't add a system-prompt prefix, because the workflow already adds one.
- **SDXL / SD1.5**: write a natural descriptive sentence plus style/lighting words.

Keep the user's intent. Don't add content they didn't ask for.

## 4. Fill a temp copy and run

Use a random seed unless the user gives one. Use `filename_prefix` `claude_<model>`.

NetaYume:
```powershell
$t="$env:TEMP\comfyui_image_$(Get-Random).json"; Copy-Item "$HOME\.claude\skills\comfyui-image\workflows\netayume.json" $t
comfy workflow set-slot $t "48.value=<PROMPT>" "48.width=1024" "48.height=1536" "48.seed=<SEED>" "9.filename_prefix=claude_netayume" | Out-Null
```
Optional slots: negative prompt `48/35.value`, steps `48/33.steps` (30), cfg `48/33.cfg` (4).

SDXL / SD1.5:
```powershell
$t="$env:TEMP\comfyui_image_$(Get-Random).json"; Copy-Item "$HOME\.claude\skills\comfyui-image\workflows\checkpoint.json" $t
comfy workflow set-slot $t "15.ckpt_name=<CHECKPOINT>" "10.text=<PROMPT>" "11.text=<NEGATIVE>" "13.width=1024" "13.height=1024" "12.seed=<SEED>" "12.steps=25" "7.filename_prefix=claude_sdxl" | Out-Null
```
For SD1.5 use 512x512 and steps 20. The default negative prompt is `lowres, blurry, deformed, bad anatomy, watermark, text, signature`.

Inside a slot value, swap any `"` in the prompt for `'`.

Run and wait:
```powershell
$r = comfy run --workflow $t --wait --timeout 600 | Select -Last 1 | ConvertFrom-Json; Remove-Item $t
if ($r.ok) { $r.data.outputs } else { $r.error | ConvertTo-Json }
```

For batch size > 1, set `48/31.batch_size` (NetaYume) or `13.batch_size` (checkpoint).

## 5. Show the result

Read each output PNG path with the Read tool so the user sees it. Then give the path, the model, the seed, and the final prompt in one or two lines. If the run failed, show the error. Out-of-memory or connection errors usually mean the image is too large: offer a smaller size.
