AI Engineering No. 244

Image Generation skill for Claude Code

Consistent image sets, priced per accepted image. Claude builds image pipelines that produce usable sets rather than lucky samples. It picks a hosted API or open diffusion model by task and license, writes structured prompt templates, locks consistency with seeds, references, or LoRAs, uses a vision LLM as a calibrated critic, moderates prompts and outputs, composites real logos and text afterward, and tracks cost per accepted image.

  • nameimage-generation
  • size199 lines · ≈2,200 tokens
  • files1
  • licenseMIT
  • updated

What Claude sees before loading it

This description is the only part of the skill that sits in context all the time. Claude reads it to decide when to load the full playbook below.

description: Builds image generation pipelines with hosted image APIs and open diffusion models via diffusers - model choice by task and license, structured prompts, seeds and reference images for consistency, LoRA and editing for characters and brand style, an LLM with vision as prompt writer and QA critic, upscaling, moderation and provenance, caching, and cost per accepted image. Use when generating product shots, illustrations, marketing assets, thumbnails, or game art programmatically, when outputs are inconsistent across a set, text in images is garbled, or a generation feature needs safety filtering and cost control.

Try asking

  • Generate 200 consistent product shots of our mug in different kitchen scenes
  • Our generated thumbnails all look different and the text is garbled. Fix the pipeline
  • Set up self-hosted image generation with moderation for user prompts in our app

Use it when

  • Generating marketing, product, illustration, or game images programmatically
  • A set of generated images must share a character, product, or style
  • Adding a user-facing image generation feature that needs safety filtering
  • Choosing between hosted image APIs and self-hosted diffusion models

Skip it when

How to check the result

Measure first-pass acceptance by human reviewers on a sample, check the vision critic agrees with them, and confirm every output carries its full generation metadata.

The common mistake it prevents

Asking the model to draw your logo or exact legal text instead of compositing the real asset afterward.

~/.claude/skills/image-generation/SKILL.md

--- name: image-generation description: Builds image generation pipelines with hosted image APIs and open diffusion models via diffusers - model choice by task and license,… license: MIT ---

An image pipeline works when a reviewer accepts most outputs on the first or second try, a set of images looks like it belongs together, every output passed moderation, and the cost per accepted image (not per generated image) is known. Individual pretty samples are easy; repeatable sets are the job.

Ground rules

  • Pick the model by task and license first; prompt craft cannot fix the wrong model.
  • Prompts are structured specs, not mood paragraphs. Keep a template per asset type.
  • Record everything per image: model and version, prompt, negative prompt, seed, size, steps, guidance, reference images, and post-processing. Without it nothing is reproducible.
  • Never generate likenesses of real private individuals, sexual content involving minors, or deceptive images of real events; block these at the prompt and output stage.
  • Check the license of open weights before commercial use; several popular checkpoints are non-commercial or have revenue thresholds.

Choose the model

TaskPrefer
General marketing and illustration, no infrastructureA hosted image API from a major provider
Legible text in the image (posters, UI mockups, logos as drafts)A model known for text rendering; test 5-10 prompts with exact strings
Editing an existing image (background swap, inpainting, variations)A model or endpoint with image-edit / reference-image input
Consistent character or product across many imagesReference-image conditioning, or a LoRA trained on 15-40 images
Self-hosted, high volume, full controlOpen diffusion models via diffusers (FLUX or Stable Diffusion 3.5 class) on a GPU
Fast drafts and previewsDistilled few-step models (1-4 steps)

Claude models read images but do not generate them; use an LLM like Claude to write prompts from briefs and to critique outputs, and a dedicated image model to render.

Workflow

- [ ] 1. Write the asset brief and acceptance criteria
- [ ] 2. Pick the model (task, license, cost, latency)
- [ ] 3. Build a prompt template; generate a small grid
- [ ] 4. Lock consistency controls (seed, references, LoRA, style)
- [ ] 5. Generate at scale with caching and metadata
- [ ] 6. Automated QA (vision critic + checks) and moderation
- [ ] 7. Upscale and post-process accepted images
- [ ] 8. Track acceptance rate and cost per accepted image

1. Brief and acceptance criteria

Per asset type: purpose, aspect ratio and pixel size, subject, required elements, forbidden elements, brand colors, style references, text (exact strings), and what makes an image unusable (extra fingers, wrong product color, cropped logo, unreadable text).

3. Prompt template

[subject and action], [setting], [composition and camera: shot type, angle, lens],
[lighting], [style/medium], [color palette], [mood], [details that must appear],
text: "EXACT STRING" in [font style] at [position]

Example:

A matte black ceramic coffee mug on a light oak table, morning kitchen background
softly out of focus, three-quarter view at eye level, 50mm lens, soft window light from
the left, clean commercial product photography, warm neutral palette with a single
terracotta accent, the mug shows the word "ROAST" in white sans-serif, centered.
RuleWhy
Most important elements firstMany models weight early tokens more
Concrete visual terms over adjectives (“soft window light from the left” vs “beautiful”)Adjectives are noise
Exact text in quotes, short (1-4 words)Long strings garble
Negative prompts only where the model supports them, and shortLong negative lists often hurt
One subject per prompt for reliable compositionMulti-subject scenes swap attributes

Generate a grid (4-8 seeds x 2-3 prompt variants), pick winners, and edit the template, not individual prompts.

LLM as prompt writer and critic

import anthropic, base64
client = anthropic.Anthropic()

def critique(png: bytes, brief: str) -> str:
    resp = client.messages.create(
        model="claude-sonnet-5-5",
        max_tokens=800,
        messages=[{"role": "user", "content": [
            {"type": "image", "source": {"type": "base64", "media_type": "image/png",
             "data": base64.standard_b64encode(png).decode()}},
            {"type": "text", "text":
             f"Brief:\n{brief}\n\nCheck this image against each acceptance criterion. "
             "Return JSON: {\"pass\": bool, \"failures\": [..], \"prompt_fix\": str}."},
        ]}],
    )
    return resp.content[0].text

Use structured outputs for the JSON in production (see structured-outputs). Calibrate the critic on 50 human-labeled images before trusting it to auto-reject; vision critics miss small anatomy errors and hallucinate text correctness on tiny fonts.

4. Consistency controls

ProblemControl
Same composition, new variationsFix the seed, vary one prompt element at a time
Same character or product across scenesReference images / image-conditioning endpoint; or train a LoRA
Same visual style across a setStyle reference image, fixed style block in the template, same model version
Brand colors driftPost-process color grading, or recolor in an edit step; models do not hit hex codes
Exact logo placementComposite the real logo afterward; never ask the model to draw your logo

Seeds are only reproducible with the same model version, scheduler, size, steps, and hardware precision. Hosted APIs may not expose seeds or may change models silently; pin model versions where the API allows.

Self-hosted with diffusers

import torch
from diffusers import FluxPipeline

pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell",
                                    torch_dtype=torch.bfloat16).to("cuda")
image = pipe(
    prompt,
    height=1024, width=1024,
    num_inference_steps=4,          # distilled model: few steps
    guidance_scale=0.0,
    generator=torch.Generator("cuda").manual_seed(1234),
).images[0]
image.save("out.png")
  • Memory: pipe.enable_model_cpu_offload() trades speed for VRAM on smaller GPUs.
  • Check each checkpoint’s license on its model card (some FLUX and SD variants restrict commercial use or revenue).
  • Batch requests per GPU and keep the pipeline loaded; load time dwarfs inference.

5. Generate at scale

  • Cache by hash of (model, prompt, negative, seed, size, steps, references).
  • Bounded concurrency respecting provider rate limits; retry transient failures.
  • Store image plus a JSON sidecar with all parameters and the critic verdict.

6. QA and moderation

  • Prompt-side: block disallowed requests (real-person likeness, minors, explicit content, trademarks you do not own, deceptive news imagery) before generation.
  • Output-side: provider safety filters plus your own image moderation classifier; log blocked items without storing disallowed content longer than needed.
  • Deterministic checks: dimensions, aspect ratio, not blank, not near-duplicate of another output (perceptual hash), file size.
  • Provenance: keep or add content credentials (C2PA) and label AI-generated images where platforms or regulations require it.

7. Upscale and post-process

  • Generate at the model’s native resolution, then upscale (Real-ESRGAN class models or the provider’s upscaler) 2-4x. Generating directly at odd large sizes causes duplicated subjects and tiling.
  • Crop to final aspect ratios after generation with safe margins.
  • Composite logos, legal text, and UI text with an image library; never rely on generated text for anything that must be exact.

8. Metrics

Acceptance rate (first pass and after retries), retries per accepted image, critic agreement with human reviewers, moderation block rate, cost and latency per accepted image.

Gotchas

  • Hands, text, and counts (“exactly three cups”) remain weak spots; design compositions that avoid them or verify them explicitly.
  • Prompt weighting syntax ((word:1.3)) is specific to some UIs and pipelines; hosted APIs treat it as literal text.
  • Changing size changes composition even with the same seed.
  • Stock-photo phrasing (“4k, masterpiece, trending”) is noise on modern models.
  • Training a LoRA on images you do not have rights to creates legal risk; use owned or licensed images.

Output contract

**Asset type:** <name>, size <WxH>, model <id@version>, license checked <yes>
**Template:** <link>, consistency via <seed/reference/LoRA>
**QA:** critic <model>, agreement with humans <x>%, moderation <filters>
**Results:** <n> generated, <n> accepted (<x>% first pass), cost per accepted <$>
**Post-process:** upscale <method>, composites <logo/text>

About this skill

Written and maintained by the Claude Skills editors to the same editorial standard as every skill in the directory: a selective trigger, a real workflow, known pitfalls and a verification step. First published , last updated . MIT licensed.

esc