Early version. Edit mode is new: expect rough edges, and tell us about them on GitHub.

d2-live

D2 · state machines · any editor

Draw it.
Watch the code change.

A live preview for D2 diagrams that you can also edit. Whatever writes the .d2 file, the picture follows; press E and the picture writes back — by exactly the lines you changed.

Install GitHub

Viewer

  • Live — redraws whenever the file changes, whoever wrote it
  • One server — open a file or a whole directory; switch files in the tab
  • Layouts and sketch — ELK, dagre or tala and hand-drawn mode, switched in place
  • Pan and zoom — position kept across redraws; F fits to screen
  • Export — copy or download PNG and SVG
  • From your editor — opens with the file via d2-live --lsp

Edit mode E

  • Basic editing by clicking for diagrams of shapes and arrows — state machines, flowcharts: rename, label, class, shape, style, connect, add, reverse, delete, comments
  • Code panel — click a shape to see its code, a line to see its shape; type and the picture follows, ⌘S saves
  • Minimal diffs — only the lines you touched change
  • Undo, and a choice when someone else edits the file at the same time
  • Containers, chains and sequence diagrams preview live and edit as code

Install

nix profile install github:pltanton/d2-live
Update
nix profile upgrade d2-live
Remove
nix profile remove d2-live
# flake.nix
inputs.d2-live.url = "github:pltanton/d2-live";

# configuration.nix or home.nix
environment.systemPackages = [
  inputs.d2-live.packages.${pkgs.stdenv.hostPlatform.system}.default
];
Update
nix flake update d2-live
Remove
drop the input and the package
go install github.com/pltanton/d2-live@latest
Update
run the same command
Remove
rm "$(go env GOPATH)/bin/d2-live"

Needs Go 1.25 or newer.

/plugin marketplace add pltanton/d2-live
/plugin install d2-live@d2-live
Update
/plugin marketplace update d2-live
Remove
/plugin uninstall d2-live@d2-live

A skill for coding agents (commands above are Claude Code's): it registers the diagrams the agent writes with your running d2-live, hands you the preview link and re-reads a file before editing it.

Run
d2-live diagram.d2

A file or a directory of them. A tab opens; press E to edit. The d2 CLI is optional: only the tala layout and PNGs of diagrams with markdown labels use it. More in the README.