Skip to main content
On this page

CLI

diagramkit CLI command structure

The CLI is the recommended way to use diagramkit. It handles file discovery, incremental builds, watch mode, and output naming automatically.

Do it with an agent

Paste into your AI coding agent:

Render every diagram in this repo. If diagramkit is not installed yet, install it with npm add diagramkit and run npx diagramkit warmup unless the repo is Graphviz-only. Read node_modules/diagramkit/llms.txt for defaults. Run npx diagramkit render . and report any failures with their file path.

For a repeatable script, ask the agent to add "render:diagrams": "diagramkit render ." to package.json.

Do it manually

The rest of this page is the manual reference: how to invoke the CLI, every command, every flag, examples, and exit codes. Skim the section that matches what you’re trying to do.

Invocation Paths

After installation, these entrypoints all invoke the same CLI:

Shell
npx diagramkit --version./node_modules/.bin/diagramkit --versionnode ./node_modules/diagramkit/dist/cli/bin.mjs --version

Use whichever form fits your environment. Local npm bin shims and direct dist/cli/bin.mjs execution behave the same as npx diagramkit.

Commands

render

Render one or more diagram files to images.

Shell
diagramkit render <file-or-dir> [options]

A file renders that single diagram. A directory recursively discovers and renders all diagram files.

Shell
# Render all diagrams in the current directorydiagramkit render .# Render a single filediagramkit render docs/architecture.mermaid# Render a specific directorydiagramkit render ./content/posts

warmup

Pre-install the Playwright Chromium browser binary. Run once per environment.

Shell
diagramkit warmup

doctor

Validate environment readiness (Node, Playwright, Chromium, sharp):

Shell
diagramkit doctordiagramkit doctor --json

init

Create a config file in the current directory.

Shell
diagramkit init          # diagramkit.config.json5diagramkit init --ts     # diagramkit.config.ts with defineConfig()diagramkit init --yes    # accept defaults, non-interactive

The generated diagramkit.config.json5 includes a $schema reference so editors (VSCode, JetBrains, etc.) offer autocomplete out of the box. The schema ships in the npm package at diagramkit/schemas/diagramkit-config.v1.json.

validate

Validate generated SVG file(s) for structural correctness and <img>-tag renderability. Use after render (especially in CI) to catch SVGs with missing xmlns, missing dimensions, embedded <script>, broken <foreignObject>, or external resource references that silently fail in <img> embeds.

Shell
diagramkit validate <file-or-dir> [--recursive] [--json]

Examples:

Shell
diagramkit validate .diagramkit/                # all SVGs in a folder (top level)diagramkit validate .diagramkit/ --recursive    # recurse into subfoldersdiagramkit validate output.svg                  # single filediagramkit validate . --recursive --json        # CI-friendly machine-readable output

Exits non-zero when any SVG fails. The directory render and single-file render commands also run this check automatically and surface results inline.

Interactive wizards

When run on a TTY without enough arguments, the CLI launches a top-level interactive picker (render / validate / init / doctor / warmup). Inside render and validate it then walks you through targets, formats, and theme — seeded from the effective diagramkit.config.* it auto-discovers from the cwd.

Shell
diagramkit                              # top-level picker (TTY)diagramkit render --interactive         # force the render wizard, even with argsdiagramkit render . --no-interactive    # disable the wizard for CI/agentsdiagramkit render . --yes               # alias for --no-interactive (accept defaults)

--interactive falls back with a one-line warning when stdout is not a TTY (so CI logs stay clean).

Project skills (the diagramkit CLI does not install them)

Important

The previous diagramkit --install-skill flag was removed in v0.3. Skills now ship inside the npm package at node_modules/diagramkit/skills/<name>/SKILL.md. The diagramkit-setup skill writes thin pointer SKILL.md files into your repo (.agents/skills/diagramkit-* plus harness mirrors under .claude/skills/, .cursor/skills/, .codex/skills/) that defer to those bundled originals — so every agent reads guidance pinned to the installed CLI version.

Recommended (local pointers):

Shell
npm add diagramkit# Then have your agent follow:#   node_modules/diagramkit/skills/diagramkit-setup/SKILL.md# It writes pointer SKILL.md files for: setup, auto, mermaid, excalidraw,# draw-io, graphviz, review (validation + WCAG 2.2 AA contrast).

Alternative (GitHub-published skills via the standalone skills CLI), when you want skills that update independently of the installed diagramkit:

Shell
npx skills add sujeet-pro/diagramkit                               # all skillsnpx skills add sujeet-pro/diagramkit -a claude-code -a cursor -a codexnpx skills add sujeet-pro/diagramkit -s diagramkit-setup -s diagramkit-reviewnpx skills update sujeet-pro/diagramkit                            # refresh later

Pick one mechanism per repo (local pointers OR npx skills) so they don’t drift against each other.

Render Options

Output Format

Shell
diagramkit render . --format svg      # defaultdiagramkit render . --format pngdiagramkit render . --format jpegdiagramkit render . --format webpdiagramkit render . --format avifdiagramkit render . --format svg,png  # multiple formats in one pass

Tip

PNG, JPEG, WebP, and AVIF require sharp. Install with npm add sharp.

Theme

Shell
diagramkit render . --theme both      # default -- produces -light and -dark variantsdiagramkit render . --theme light     # light onlydiagramkit render . --theme dark      # dark only

Scale and Quality (Raster Only)

Shell
diagramkit render . --format png --scale 3       # 3x resolution for HiDPIdiagramkit render . --format jpeg --quality 80    # compression quality 1-100diagramkit render . --format webp --quality 85 --scale 2

Force Re-render

Shell
diagramkit render . --force      # ignore manifest cache, re-render everythingdiagramkit render . -f           # short form

Watch Mode

Shell
diagramkit render . --watch      # watch for changes, re-render on savediagramkit render . -w           # short form

See Watch Mode for details.

Dark Mode Contrast

Shell
diagramkit render . --no-contrast    # skip WCAG contrast optimization on dark SVGs

By default, dark-mode Mermaid and Graphviz SVGs are post-processed to fix fill colors with poor contrast.

Filter by Type

Shell
diagramkit render . --type mermaiddiagramkit render . --type excalidrawdiagramkit render . --type drawiodiagramkit render . --type graphviz

Custom Output

Shell
# Single file to a custom directorydiagramkit render diagram.mermaid --output ./build/images# Change the output folder name (default: .diagramkit)diagramkit render . --output-dir images# Place outputs next to source files (no subfolder)diagramkit render . --same-folder# Add prefix/suffix to output filenamesdiagramkit render . --output-prefix "dk-"diagramkit render . --output-suffix "-v2"

When you use --output, diagramkit writes to that folder directly. Directory renders skip manifest tracking for that run, and single-file renders do not update the source directory manifest. Use --output-dir if you want custom folder naming while keeping incremental manifests.

Explicit Config File

Shell
diagramkit render . --config ./custom.config.json5

Use --config to point at a specific config file instead of auto-discovery. Useful for CI or monorepo setups.

Manifest Control

Shell
diagramkit render . --no-manifest                        # disable incremental cachingdiagramkit render . --manifest-file custom-manifest.json # custom manifest filename

Scripting and CI

Shell
diagramkit render . --dry-run    # preview what would render, without renderingdiagramkit render . --plan       # include stale reasons in plan outputdiagramkit render . --quiet      # suppress info output, errors onlydiagramkit render . --log-level warndiagramkit render . --log-level verbosediagramkit render . --json       # machine-readable JSON outputdiagramkit render . --strict     # exit non-zero if any single render failsdiagramkit render . --strict-configdiagramkit render . --max-type-lanes 2

--strict (render-failure strictness) is independent of --strict-config (config-validation strictness). Use --strict when you want CI to fail loudly on a single broken diagram rather than just printing it to the failure list.

Global Flags

Shell
diagramkit --help              # show helpdiagramkit -hdiagramkit --version           # show versiondiagramkit -vdiagramkit --agent-help        # output full reference for LLM agentsdiagramkit --interactive       # force interactive wizard even when args are present (TTY required)diagramkit -i                  # short formdiagramkit --no-interactive    # disable interactive wizard (useful for CI / agents)diagramkit --yes               # alias for --no-interactive (accept defaults)diagramkit -y                  # short form

Project skills are installed by the diagramkit-setup skill as local pointers into node_modules/diagramkit/skills/ (default), or by the standalone skills CLI (npx skills add sujeet-pro/diagramkit) when the repo prefers GitHub-published skills. See Project skills.

Examples

Shell
# Render everything with defaultsdiagramkit render .diagramkit .    # alias for "render ."# High-res PNGs for documentationdiagramkit render ./docs --format png --scale 3# Watch mode during developmentdiagramkit render . --watch# Only mermaid, force re-renderdiagramkit render . --type mermaid --force# Graphviz DOT to dark-only SVGdiagramkit render dependency.dot --theme dark# Single file to a custom folderdiagramkit render flow.mermaid --output ./static/images# Explicit config file for CIdiagramkit render . --config ./ci.config.json5# CI: JSON output, no cachingdiagramkit render . --json --no-manifest# CI: explain stale reasons before renderingdiagramkit render . --plan --json

JSON Contract Upgrade

--json now emits a versioned envelope with schemaVersion: 1 and nested result.
If you parsed legacy root-level JSON fields directly, migrate to result.*.

JSON schema: diagramkit/schemas/diagramkit-cli-render.v1.json (exported from the npm package).

Exit Codes

Code Meaning
0 Success
1 Error (unknown command, render failure, etc.)

In watch mode, the process stays running until Ctrl+C (SIGINT).