Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

D2 CLI

$ d2 Official Low Risk
Terrastruct · Design & Docs · MPL-2.0 · macos / linux / windows

D2 (d2) compiles human- and agent-readable .d2 diagram scripts into crisp themed SVGs, PNGs, or PDFs with zero browser dependencies. It supports deterministic d2 fmt formatting, d2 validate syntax checking, and selectable layout engines (dagre, elk).

FCRS-1.0 Score
89 /100
Good
Medium Confidence
Zero-Friction Install
brew install d2
CLI vs MCP Decision CLI Only

d2 compiles .d2 files directly on the local machine in Go with d2 validate and d2 fmt, requiring no MCP wrapper.

Agent-Readiness Checklist

— JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 21 / 25

Native Go CLI with d2 validate, d2 fmt, --layout, and clean compiler error messages; lacks a JSON AST output flag.

  • d2 validate provides zero-write syntax checking
  • Clear line/column diagnostics on parse failures
Trust & Safety 23 / 25

Pure offline local compiler with no credentials needed for OSS layouts.

  • Zero network calls during standard SVG rendering
Setup & Portability 14 / 15

Single Go binary via Homebrew, go install, and GitHub releases; SVG requires no browser (PNG/PDF uses Playwright if enabled).

  • brew install d2 and cross-platform releases
Utility & Efficiency 14 / 15

Produces polished modern architecture diagrams with readable .d2 syntax that LLMs write accurately.

  • Supports themes, sketch mode, containers, SQL tables, and ELK/Dagre layouts
Maintenance & Lineage 9 / 10

Official Terrastruct repository (terrastruct/d2) actively maintained under MPL-2.0.

  • Official Terrastruct GitHub organization
Docs & Verifiability 8 / 10

Clean official tour and manpage docs at d2lang.com.

  • Official docs at d2lang.com/tour/man/

Security, Auth & Guardrails

Auth Modes
No Auth Env API Key Config File
Credential Storage

Open-source d2 (dagre/elk) needs zero auth; optional commercial TALA layout plugin reads TSTRUCT_TOKEN or ~/.config/tstruct/auth.json.

Side Effects
Read-Only Local Write
Cost & Quotas

CLI and dagre/elk engines are free (MPL-2.0); optional commercial TALA layout engine requires a Terrastruct license.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# D2 CLI Agent Rules
- Run `d2 validate <file>.d2` and `d2 fmt` after editing diagram sources.
- Prefer SVG output (`output.svg`) over PNG when no headless browser/Playwright rasterizer is installed.
- Do not pass `--watch` in synchronous agent commands.

Agent-Ready Command Recipes

Safe Read-Only Queries

Validate D2 diagram syntax
d2 validate architecture.d2

Parses and validates .d2 syntax without writing any rendered output file.

Check installed D2 version
d2 --version

Prints the installed d2 compiler version.

Controlled Writes & Previews

Compile a D2 architecture diagram to SVG
d2 --layout=elk architecture.d2 dist/architecture.svg

Renders architecture.d2 using the ELK layout engine into dist/architecture.svg.

Strengths for Agents

  • + Browser-free SVG rendering and d2 validate / d2 fmt in a single Go binary.
  • + Concise .d2 language is easy for coding agents to generate and diff cleanly.
  • + Supports --layout=elk and built-in themes out of the box.

Caveats & Pitfalls

  • ! Raster PNG/PDF export still relies on Playwright/browser unless sticking to SVG.
  • ! The TALA layout engine is proprietary and requires a Terrastruct license token.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI