Generates, validates, and fixes diagrams from Mermaid markup using the mmdc CLI tool. Supports flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, and more.
Ships in mermaid-cli. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
mmdc (Mermaid CLI) converts Mermaid diagram definitions into SVG, PNG, or PDF output. It is the official command-line interface for the Mermaid diagramming library, enabling text-based diagram generation without a browser.
Write diagram definitions in .mmd files using Mermaid's declarative syntax, then run mmdc to produce publication-ready output. This is the primary tool for generating diagrams from text in automated and scripting workflows.
mmdc also serves as a syntax validator: any render attempt validates the diagram. If the Mermaid syntax is invalid, mmdc exits with a non-zero code and reports parse errors to stderr. This enables iterative validate-and-fix workflows.
CRITICAL: Before proceeding, you MUST verify that mermaid-cli is installed:
mmdc --version
If mmdc is not installed:
# npm (global install)
npm install -g @mermaid-js/mermaid-cli
# npx (no install, run directly)
npx -p @mermaid-js/mermaid-cli mmdc --help
# Docker
docker pull minlag/mermaid-cli
# See https://github.com/mermaid-js/mermaid-cli for more options
If mmdc is not available, exit gracefully and do not proceed with the workflow below.
Create a .mmd file with Mermaid syntax:
cat <<'EOF' > diagram.mmd
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action]
B -->|No| D[End]
EOF
# Generate SVG (default, best for web)
mmdc -i diagram.mmd -o diagram.svg
# Generate PNG (raster image)
mmdc -i diagram.mmd -o diagram.png
# Generate PDF (document embedding)
mmdc -i diagram.mmd -o diagram.pdf
On success, mmdc prints Generating single mermaid chart and exits with code 0. Check that the output file was created and is non-empty.
The most common workflow. SVG is the default and recommended format.
mmdc -i flowchart.mmd -o flowchart.svg
Customize appearance with theme and background color.
# Dark theme with white background
mmdc -i diagram.mmd -o diagram.png -t dark -b white
# Forest theme with transparent background
mmdc -i diagram.mmd -o diagram.png -t forest -b transparent
Use --pdfFit to scale the diagram to fit the PDF page.
mmdc -i diagram.mmd -o diagram.pdf --pdfFit
Write and render a diagram in one step without a separate file. Useful for scripted/automated workflows.
# Write diagram to temp file and convert
cat <<'EOF' > /tmp/seq.mmd
sequenceDiagram
Alice->>Bob: Hello Bob
Bob-->>Alice: Hi Alice
Alice->>Bob: How are you?
Bob-->>Alice: Great!
EOF
mmdc -i /tmp/seq.mmd -o sequence.svg
Replace all mermaid code blocks in a Markdown file with generated images.
# Replace mermaid blocks with SVG images
mmdc -i README.md -o README-out.md
# Replace with PNG images
mmdc -i README.md -o README-out.md -e png
The output Markdown file will have each ```mermaid block replaced with an <img> tag pointing to the generated image file.
Apply a Mermaid configuration file for consistent styling.
# Create a config file
cat <<'EOF' > mermaid-config.json
{
"theme": "forest",
"flowchart": {
"curve": "basis",
"useMaxWidth": true
}
}
EOF
# Use the config
mmdc -i diagram.mmd -o diagram.svg -c mermaid-config.json
Use mmdc to check if a .mmd file has valid Mermaid syntax. Any render attempt validates the diagram — if the syntax is invalid, mmdc exits with a non-zero code and prints parse errors to stderr.
# Validate by rendering to a temp file
mmdc -i diagram.mmd -o /tmp/_validate.svg -q 2>&1
echo "Exit code: $?"
# 0 = valid, non-zero = invalid (error details printed above)
rm -f /tmp/_validate.svg
Iteratively fix invalid Mermaid diagrams by rendering, reading errors, correcting syntax, and re-validating.
# Step 1: Attempt render to validate
mmdc -i diagram.mmd -o /tmp/_validate.svg -q 2>&1
# Step 2: If exit code is non-zero, read the error output
# Errors describe the syntax issue (e.g. "Parse error on line 3...")
# Fix the .mmd file based on the error messages
# Step 3: Re-validate after fixing
mmdc -i diagram.mmd -o /tmp/_validate.svg -q 2>&1
# Step 4: Once valid (exit code 0), generate final output
mmdc -i diagram.mmd -o diagram.svg
rm -f /tmp/_validate.svg
| Flag | Description | Example |
|---|---|---|
-i <file> | Input file (.mmd or .md) | -i diagram.mmd |
-o <file> | Output file (format from extension) | -o out.svg |
-t <theme> | Theme: default, forest, dark, neutral | -t dark |
-e <format> | Output format override: svg, png, pdf | -e png |
-b <color> | Background color | -b transparent |
-w <px> | Width in pixels | -w 1024 |
-H <px> | Height in pixels | -H 768 |
-s <factor> | Scale factor (default: 1) | -s 2 |
-c <file> | Mermaid config JSON file | -c config.json |
-C <file> | CSS file for styling | -C custom.css |
-p <file> | Puppeteer config JSON file | -p puppeteer.json |
--pdfFit | Fit diagram to PDF page | --pdfFit |
-q | Quiet mode (suppress logs) | -q |
-I <id> | SVG element id attribute | -I my-diagram |
--iconPacks | Icon pack names (comma-separated) | --iconPacks logos |
Mermaid supports a wide range of diagram types. Use the appropriate syntax in your .mmd file:
graph TD / graph LR / flowchart TD)sequenceDiagram)classDiagram)stateDiagram-v2)erDiagram)gantt)pie)mindmap)timeline)gitGraph)journey)sankey-beta)C4Context / C4Container / C4Component)quadrantChart)xychart-beta)block-beta)architecture-beta)zenuml)See Mermaid documentation for diagram syntax reference.
Four built-in themes are available:
| Theme | Description |
|---|---|
default | Standard blue/gray palette |
forest | Green-oriented natural colors |
dark | Dark background with light text |
neutral | Grayscale, suitable for printing |
mmdc -i diagram.mmd -o diagram.svg -t forest
For custom theming, use a configuration file with themeVariables or a CSS file with -C. See references/configuration.md for details.
For comprehensive documentation beyond common workflows, see:
"mmdc: command not found"
Chromium sandbox error on Linux
cat <<'EOF' > puppeteer-config.json
{
"args": ["--no-sandbox", "--disable-setuid-sandbox"]
}
EOF
mmdc -i diagram.mmd -o diagram.svg -p puppeteer-config.json
Docker permission errors
docker run --rm -u $(id -u):$(id -g) -v $(pwd):/data minlag/mermaid-cli -i /data/diagram.mmd -o /data/diagram.svg
Custom Chromium path
executablePath in a Puppeteer config file:cat <<'EOF' > puppeteer-config.json
{
"executablePath": "/usr/bin/chromium-browser"
}
EOF
mmdc -i diagram.mmd -o diagram.svg -p puppeteer-config.json
Blank or empty output
.mmd file has valid Mermaid syntax-q flag)graph, sequenceDiagram)Timeout errors
cat <<'EOF' > puppeteer-config.json
{
"timeout": 60000
}
EOF
mmdc -i diagram.mmd -o diagram.svg -p puppeteer-config.json
What SKILL.md sets; muted values are Claude Code's defaults
/mermaid-cli:mermaid-clifrom mermaid-cli
npx claudepluginhub dashed/claude-marketplace --plugin mermaid-cliOther plugins' skills for the same job