Draw.io Diagrams
Overview
Generate .drawio XML files and export to PNG/SVG/PDF/JPG locally using the native draw.io desktop app CLI.
Supported formats: PNG, SVG, PDF, JPG — no browser automation needed.
PNG, SVG, and PDF exports support --embed-diagram (-e) — the exported file contains the full diagram XML, so opening it in draw.io recovers the editable diagram. Use double extensions (name.drawio.png) to signal embedded XML.
Bundled resources
When the workflow references one of these, read it on demand — none of them need to be in context up front.
| File | Read it when |
|---|---|
references/diagram-types.md | The user names a specific diagram type (ERD, UML class, sequence, architecture, ML/DL, flowchart) |
references/style-presets.md | The user asks to learn / save / list / set-default / delete a style preset, or you've resolved an active preset and need the application rules |
references/style-extraction.md | You're inside the Learn flow and need the extraction procedure (called from style-presets.md) |
references/troubleshooting.md | An export fails, vision rejects a PNG, or a rendering looks wrong |
scripts/repair_png.py | After every -e PNG export — fixes draw.io's truncated IEND chunk (issue #8) |
scripts/encode_drawio_url.py | The CLI is unavailable and you need a browser-fallback diagrams.net URL |
Prerequisites
The draw.io desktop app must be installed and the CLI accessible:
macOS sandbox / sandbox isolation note (e.g., codex.app): In some sandboxed macOS environments, invoking the draw.io desktop CLI (even draw.io --version) can crash the draw.io process or produce no output. If that happens, treat the CLI as unavailable in this sandbox isolation — do not keep retrying inside the sandbox. Prefer a non-sandboxed host environment (outside sandbox isolation) for any CLI export work, or use the browser fallback / XML-only outputs.
# macOS (Homebrew — recommended; CLI binary is `drawio`, not `draw.io`)
brew install --cask drawio
drawio --version
# macOS (full path if not in PATH)
/Applications/draw.io.app/Contents/MacOS/draw.io --version
# Windows
"C:\Program Files\draw.io\draw.io.exe" --version
# Linux
draw.io --version
Install draw.io desktop if missing:
- macOS:
brew install --cask drawioor download from https://github.com/jgraph/drawio-desktop/releases - Windows: download installer from https://github.com/jgraph/drawio-desktop/releases
- Linux: download
.deb/.rpmfrom https://github.com/jgraph/drawio-desktop/releases — do not use snap (AppArmor sandbox denies secrets/keyring on servers, causes crash)
Workflow
Before starting the workflow, assess whether the user's request is specific enough. If key details are missing, ask 1-3 focused questions:
- Diagram type — which preset? (ERD, UML, Sequence, Architecture, ML/DL, Flowchart, or general)
- Output format — PNG (default), SVG, PDF, or JPG?
- Output location — default is the user's working dir; honor any explicit path the user gives (e.g. "put it in
./artifacts/"). Don't ask if they didn't mention one. - Scope/fidelity — how many components? Any specific technologies or labels?
Skip clarification if the request already specifies these details or is clearly simple (e.g., "draw a flowchart of X").
Step 0 — Resolve active preset. Determine which (if any) user-defined style preset applies to this generation.
- Scan the user's message for a phrase that clearly names a style preset: "use my
<name>style", "with my<name>style", "in<name>mode", "in the style of<name>". A barewith <name>does not count — "draw a diagram with redis" names a component, not a style. If a clear match is found → active preset =<name>. - Else, check
~/.drawio-skill/styles/for any file with"default": true. If found → active preset = that one. - Else → no preset active; fall through to the built-in color/shape/edge conventions for the rest of the workflow.
Load the preset JSON from ~/.drawio-skill/styles/<name>.json, falling back to <this-skill-dir>/styles/built-in/<name>.json. If the named preset exists in neither location, tell the user the name is unknown, list the available presets (user dir + built-in), and stop — do not silently fall back to defaults.
When a preset loads successfully, mention it in the first line of the reply: "Using preset <name> (confidence: <level>)." See the Applying a preset subsection below for how the preset changes color/shape/edge/font decisions.
- Check deps — verify
draw.io --versionsucceeds; note platform for correct CLI path - Plan — identify shapes, relationships, layout (LR or TB), group by tier/layer
- Generate — write
.drawioXML file to disk. Default output dir is the user's working dir; if the user specified an output path or directory (e.g../artifacts/,docs/images/), use that instead —mkdir -pthe target dir first. Apply the same dir choice to PNG/SVG/PDF exports in steps 4 and 7. - Export draft — run CLI to produce a preview PNG. Do NOT pass
-eat this step — the embeddedzTXt mxGraphModelchunk it adds causes vision APIs (Claude included) to return 400 "Could not process image" in step 5. Save the clean preview as<name>.png(single extension). Embedding is for the final export only (step 7). - Self-check — use the agent's built-in vision capability to read the exported PNG, catch obvious issues, auto-fix before showing user (requires a vision-enabled model such as Claude Sonnet/Opus). If reading the PNG returns a 400 / "Could not process image" error, you almost certainly exported with
-eby mistake — re-export without-eand retry once. If it still fails, skip self-check and continue to step 6. - Review loop — show image to user, collect feedback, apply targeted XML edits, re-export, repeat until approved
- Final export — re-export the approved version to all requested formats. Use
-ehere (PNG/SVG/PDF) so the deliverable stays editable in draw.io; save as<name>.drawio.pngto signal embedded XML. For PNG with-e, runpython3 <this-skill-dir>/scripts/repair_png.py <name>.drawio.pngimmediately after — draw.io's CLI truncates the IEND chunk in-ePNG output (8 bytes missing), producing a corrupt file that vision APIs and strict PNG decoders reject (issue #8). Report file paths.
If draw.io --version crashes or prints nothing (common in restricted macOS sandbox isolation like codex.app):
- Do not keep retrying CLI invocations inside the sandbox.
- Skip steps 4, 5, 6, and 7 (CLI export + PNG-based review) and use Browser fallback (
scripts/encode_drawio_url.py) or deliver the.drawioXML only. - If the user needs PNG/SVG/PDF outputs, ask them to run the export commands in a non-sandboxed host environment (outside sandbox isolation) and share the resulting files.
Escalation rule:
- If the binary exists on PATH (or known app path exists) but execution fails with abnormal exit, empty output, Electron startup failure, display/session error, or likely sandbox restriction, prefer one escalated retry before falling back.
- If the binary is missing entirely, do not escalate just to search more aggressively; go to install guidance or fallback.
Step 5: Self-Check
After exporting the draft PNG, use the agent's vision capability (e.g., Claude's image input) to read the image and check for these issues before showing the user. If the agent does not support vision, skip self-check and show the PNG directly.
Important: the draft PNG read here must have been exported without -e. Draw.io's -e flag emits a PNG with a truncated IEND chunk (8 bytes of type+CRC missing) that the Anthropic vision API rejects with 400 "Could not process image" (issue #8). The simplest fix for the preview step is to skip -e entirely; the final export in step 7 keeps -e and runs the repair snippet. If you see the 400 error