README.md

drawgent: your coding agent on a live Excalidraw canvas #

drawgent connects your own Claude Code, Codex or opencode (your install, login, config and repo) to an Excalidraw whiteboard. Ask for a diagram in the chat panel, or write AGENT: … next to the part of a drawing you want changed. The agent looks at the canvas (screenshot + scene), edits it live, checks the result, and marks the note DONE.

How it works #

drawgent architecture: the browser, the drawgent server, your coding agent and its MCP canvas tools

Quick start #

Prerequisite: one of claude, codex or opencode installed and logged in. Nothing else: no Node.js, no adapters (drawgent drives each CLI in its own headless protocol).

drawgent setup claude        # once per agent: claude | codex | opencode
cd ~/my-repo
drawgent up                  # new agent session in this repo + canvas in your browser
drawgent up --attach         # or: pick one of your running sessions and connect the canvas to it

Demo #

drawgent demo: the agent drawing on a live Excalidraw canvas

drawgent setup <agent> #

Checks everything once, fails with the exact fix when something is missing, and writes ~/.config/drawgent/config.toml:

  1. The agent CLI. Your claude / codex / opencode on PATH.

  2. Login. claude auth status, codex login status or opencode auth list.

  3. Bridge. drawgent talks ACP to every agent:

    • opencode speaks ACP itself (opencode acp).
    • Claude Code and Codex go through bridges built into drawgent (drawgent bridge claude|codex) that drive your CLI in its own headless protocol: Claude Code's stream-json mode (claude -p --input-format stream-json …, the protocol of the Claude Agent SDK) and Codex's app-server (codex app-server). Streaming, tool calls, permission prompts, Stop, forks for --attach and token usage all go through them.
    • Setup then verifies the ACP handshake (20 s at most: a bridge that doesn't answer fails with a reason instead of hanging). Configs from older versions that point at the Node.js adapters are switched to the built-in bridges automatically.
  4. Canvas tools for attached sessions. Only Codex needs a change: codex mcp add drawgent -- drawgent mcp. Claude and opencode get the tools at attach time.

  5. Headless Chrome for the renderer. Setup uses your Chrome/Chromium if you have one. Otherwise it proposes:

    • downloading Chrome Headless Shell (Chrome for Testing, ~120 MB, no sudo) into ~/.cache/drawgent/chrome, and telling you exactly which system libraries are missing, if any;
    • installing Chromium with your package manager (apt, snap, dnf, pacman, zypper, apk, brew, or nix without sudo).

    Non-interactive: --chrome download | system | /path/to/chrome.

drawgent up refuses to start until setup succeeded for that agent, or if something setup recorded disappeared.

drawgent up #

Runs in the current directory (the workspace):

  • starts the editor + API on 127.0.0.1:7300 (next free port if taken);
  • starts a new session of your agent over ACP, working in the workspace;
  • opens your browser. On a headless box it prints the ssh -L command instead.

The live scene and its sync state are kept in .drawgent/scene.json, which is git-ignored automatically.

Diagrams linked to code #

Shapes can point at the code they stand for: a file, a line range and a symbol (function, type, class…).

  • Linking: the agent links shapes when it draws your repo. You can link one yourself from the Code tab: open a file, click (or shift-click) the lines, select one shape on the canvas, then Link the selected shape. The symbol on the first selected line is detected.

  • Browsing code from the diagram:

    • clicking a shape's link icon opens its code in the Code tab at the right lines;
    • a file lists the shapes linked to it (click one to jump to it on the canvas);
    • the tab also has file search, full-text search, and VS Code to open the file locally.
  • Staying correct:

    • The Code tab lists every link on the board with its status: ✅ ok, ↕ moved (the symbol is now at other lines), ⚠ stale (the symbol is gone), ❌ missing (the file is gone; a same-name file elsewhere is suggested).
    • Check drift with the agent asks your agent to repair links and mark components or arrows that no longer match the code with DRIFT: notes.
  • In CI:

    drawgent check                 # the workspace's diagram (or: drawgent check docs/diagrams/)
    drawgent check --fix           # repair moved symbols and renamed files in the .excalidraw file
    

    drawgent check exits with 1 when links are broken; use --json for tooling.

Pointing at code #

Point at code instead of typing paths. Everything you point at lands in the context basket (chips at the top of the panel, visible on every tab). It is sent with your next chat message: excerpts with line numbers for code, listings for folders.

  • In the Code tab:
    • Browsing: a real folder tree, Files of this board (the files linked from the board), and Ctrl+P to go to a file (fuzzy).
    • Laser: switch on the laser (🔴, or the canvas laser K) and scribble over folders, files or lines. The rows you scribble over become chips; rows you merely cross don't.
    • Buttons: + ctx adds a folder, a file or the selected lines to the basket.
  • On the canvas:
    • Cards: 📌 pins a file (from a given line) or a folder as a live card. Resize it to show more; double-click it, then ▲▼ scrolls it for everyone.
    • Laser: the canvas laser over a card sends exactly the lines, or folder entries, it covers, together with the diagram around them.
  • Repo map: 🗺 Map repo draws the workspace as a board, a treemap where top-level folders are frames and files are boxes sized by line count, all linked to the code. Pointing at an area with the laser sends that folder or file. Gitignored files are left out of the map, the Code tab and search, even ones still tracked; every .gitignore level, .git/info/exclude and the global gitignore apply, even outside a git repo.

Build what I drew #

Change the diagram, then let the agent change the code to match it.

  1. Draw the change: add a box between two others, rename a component, re-wire an arrow.
  2. Click 🔨 Build what I drew: it's above the chat input and counts the changes since the last build (what changed? lists them). Point at part of the diagram with the laser first to build only that zone.
  3. The agent receives the semantic changes, not pixels. It gets shapes and arrows added, removed, relabelled or re-wired, plus new notes; moves and restyling are ignored.
  4. It plans, implements and reports on the canvas:
    • Each changed element gets a marker (📝 planned → 🔧 in progress → ✅ done with the files it touched, or ⛔ blocked).
    • New shapes are linked to the code it wrote.
    • Removed shapes are proposed, never deleted from the code without your confirmation.

The baseline: changes count from the committed diagram file (git HEAD), or from when drawgent first saw the board, and each build moves the baseline forward. Mark as built resets it when the code already matches. Progress markers stay out of the committed .excalidraw file; clear markers removes them.

Several whiteboards #

A workspace can hold several boards, for the "one big whiteboard with many diagrams" habit without the mess:

  • Boards tab in the side panel: switch boards (the URL keeps ?board=<id>), create, rename, delete.
  • Move or copy a selection to another board: select a diagram, part of one, or a frame, then use Move here / Copy on the target board. Labels, frame children and arrows between the moved shapes come along.
  • Split by frames turns every frame of a big board into its own board.
  • Agents work on the board you talk to them from. They can also list_boards, use_board, create_board and move_elements.

Keeping the diagram in the repo: --diagram #

drawgent up --diagram docs/architecture.excalidraw   # the main board, remembered for this workspace
drawgent up --diagram docs/diagrams/                 # a folder: one <board>.excalidraw per board

In folder mode, every board is a file:

  • new boards create files, and renaming a board renames its file;

  • a file that appears in the folder (e.g. after git pull) becomes a board.

  • What's written: a standard .excalidraw file (it opens on excalidraw.com) that follows the canvas. It holds only the live drawing (no deleted elements, no laser traces), pretty-printed and without per-edit sync fields, so it diffs cleanly and is rewritten only when the drawing changes. Commit it like any other source file.

  • Changes from git: if the file changes outside drawgent (git pull, checkout, a hand edit), it wins. The canvas updates live, deletions included, and a file already on disk at start is applied too. A file that doesn't parse (e.g. merge-conflict markers) is reported in the chat panel and ignored until fixed.

  • Picking the file: a drawgent.excalidraw at the workspace root is used automatically, so a fresh clone needs no flag.

  • Rooms: --diagram can't be combined with --room, where the room holds the drawing.

drawgent up --attach [id] #

Connects the canvas to a session you already run. Without an id it lists the sessions it finds (current directory first) and lets you pick one:

agent discovery how the canvas reaches it
Claude Code claude agents --json (interactive and background sessions) fork: a new session carrying the full conversation, driven by drawgent over ACP. Your terminal session is left untouched
opencode opencode servers listening locally: start the TUI with opencode --port 4096 (or opencode serve) live: messages go into your running session (you see them in your TUI); drawgent adds its MCP tools to that server at runtime; replies, tool calls and prompts you type in the TUI are mirrored into the chat panel
Codex sessions in ~/.codex/sessions live: codex queue --thread <id>; replies are mirrored from the session's rollout file. The session needs the drawgent MCP (registered by setup, loaded when Codex starts)

Using the canvas #

  • Chat panel (right side): send a request, watch replies and tool calls stream in, approve permission prompts, press Stop to cancel a turn. Under each turn: the tokens it used (input, of which cached, and output), how full the agent's context window is, and what the turn cost, when the agent reports them (Claude does).

  • On the canvas: write a text starting with AGENT: next to or inside a shape, or draw an arrow from the note to a shape. It fires about 2.5 s after you stop typing, with its position, what it points at and what is nearby. The agent resolves it into a green DONE: … note. Edit it back to AGENT: to send it again.

  • Laser zones: pick Excalidraw's laser (K) and circle or scribble over part of the diagram. The trace stays on the canvas as a red outline, and the chat panel opens ready for your instruction, with a chip listing what is under the zone (🔴 Laser zone · API, Redis ×). Your next message goes to the agent together with the zone (bounds and covered elements), and the trace disappears when the agent is done. Strokes within 4 s of each other form one zone; × discards it.

  • Laser gestures: drawgent reads what the strokes mean, shows it on the zone chip, and tells the agent (with the elements at each end). A help card with these gestures shows in the bottom-left corner while the laser is on (× hides it; the Gestures button brings it back):

    | Gesture | Meaning | |---|---| | tap (dot), ✕ | this spot (empty space: put it here) or this element | | arrow (one stroke, or a line plus a head) | from → to: move, connect, insert, data flow | | line | join its two ends | | zigzag, scribble, or a line through an element | cross it out. The agent also learns what deleting it breaks: dangling arrows, the flow to bridge, the gap to close, frame contents, code links | | ✓ | approve / keep | | circle | select what it encloses | | circle plus an arrow out of it | move what it holds there | | ↔ / ↕ (a line with a head at each end) | more room here: that diagram is pushed apart along the axis, and its frames and areas grow |

  • Gesture poll: two seconds after your last stroke, a poll in the chat offers 2 or 3 tasks for the agent, chosen from what the gesture is on, plus Other… to say it in words. The tasks are the kind that are tedious by hand. On shapes linked to code:

    • circle: Drill down (internals from the code), Check it against the code, Explain it;
    • arrow A → B: Trace A → B in the code (draws the real path), Plan A → B;
    • strike: Remove from the architecture (code impact, every board), Is it still used?;
    • strike through an arrow: Cut this dependency.

    Without code links the tasks stay on the diagram: Expand, Find its code, Remove it everywhere, Propose a replacement, Extract to a board, Tidy the diagram, Detail the flow. Cancel, or Esc at any time, discards the gesture.

  • Undo: agent edits land on the editor's undo stack, so Ctrl+Z reverts them one edit at a time. A turn that changed the canvas has ↶ Undo N canvas changes under it in the chat, and the agent has undo_changes (its last edit, or a whole turn). Elements a human changed since are kept as they are.

  • Prompts are queued and run one at a time. A queued note that was already handled is skipped.

Shared rooms: excalidraw.com and self-hosted Excalidraw #

drawgent up --room 'https://excalidraw.com/#room=<id>,<key>'
  • drawgent joins the room as a collaborator (🤖 Agent, with a cursor that follows its edits). Humans can stay on excalidraw.com: their AGENT: notes reach your agent, and its edits appear there live.
  • Traffic is end-to-end encrypted with the room key. Empty rooms are loaded from and saved to excalidraw's Firestore storage.
  • The local editor mirrors the room and still has the chat panel.

Self-hosted servers (company instances, behind SSO or not) work the same way once they're known to drawgent. Register one from any document link, then join its documents:

drawgent remote add 'https://draw.example.org/document/<id>' --token-file ~/.config/drawgent/draw.token
drawgent up --room 'https://draw.example.org/document/<id>'

remote add finds the collab server in the app (or takes --collab), guesses where the room id sits in links (or takes --room '/document/{id}'), checks the server accepts the token, and saves a [remote."<host>"] entry to the config. drawgent only speaks the standard Excalidraw collaboration protocol, never the server's own API. Keep the document open in a browser: that tab loads and saves it. See docs/remote-rooms.md for how it works, the config reference and the limits.

Other commands #

  • drawgent mcp: stdio MCP server with the canvas tools. Agents launch it; it finds the running drawgent up by itself.
  • drawgent serve: low-level server with explicit agents (--agent claude,codex,opencode as set up, or name=command for any ACP agent); for scripts and containers.
  • drawgent remote add <link> / drawgent remote list: self-hosted Excalidraw servers for --room (see above).
  • Options for up / serve: --port, --room, --token (API bearer + ?token= in the URL), --permissions canvas|ask|all (default canvas: drawing tools auto-approved, anything else asked in the chat panel), --data, --settle-ms.

Optional: Docker #

docker compose up --build runs a canvas server (drawgent + Chromium, no agents), e.g. to host a shared canvas or a room bridge on a server. Agents are never bundled: they always run with your own setup.

Build from source #

npm ci && npm run build      # editor + renderer pages -> dist/ (embedded into the binary)
cargo install --path .       # or: cargo build --release

Release builds (nix develop -c make … provides the toolchain, or rustup + cargo-zigbuild):

command output
make musl / make dist static Linux x86_64 binary / tarball (MUSL_TARGET=aarch64-unknown-linux-musl for ARM)
make darwin / make dist-darwin macOS universal binary (Intel + Apple Silicon, macOS ≥ 13) / tarball
  • How the macOS build is made: it's cross-built from Linux with zig and no Apple SDK (drawgent links only libSystem, libiconv and libcharset).
  • Signing: the arm64 slice is ad-hoc signed by the linker. It is not notarized, so after downloading run xattr -d com.apple.quarantine drawgent once.
  • Status: not yet tested on a real Mac.
  • Small machines: use JOBS=1. One dependency (chromiumoxide_cdp) needs a lot of memory to compile.

Agent tools (MCP) #

drawing_guide (colours by role, sizes, layout, common mistakes; adapted from the official excalidraw-mcp guide, MIT), get_scene (after the first read: only what changed since, minus the agent's own edits; full for everything), check_layout (geometry lint: overlaps, overflowing / broken labels, arrows through shapes or clipped by frames, small or low-contrast text, near-misalignment, crowding; fixes as update patches; edit replies carry the issues they introduce), add_graph (nodes, edges, groups → layered auto-layout with frames), make_space (push a diagram apart along an axis at a point), undo_changes (revert the agent's last edit or turn), get_screenshot (vision, 1000 px by default; element_ids crops to the area, max_size), link_code, check_links, get_diagram_changes, mark_progress, map_repo, list_boards, use_board, create_board, move_elements, add_elements (Excalidraw skeletons; arrows bind by id and are routed edge-to-edge), add_mermaid (auto-layout), update_elements (labels follow shapes, bound arrows re-route, frameId), delete_elements (reconnect: drop attached arrows and bridge the flow), clear_canvas, list_instructions, resolve_instruction, set_status.

API #

GET /api/health · GET /api/scene · GET /api/screenshot?ids=&padding=&max= · POST|PATCH|DELETE /api/elements · POST /api/mermaid · POST /api/graph · GET /api/lint?ids= · GET /api/zone?zone= (gestures + poll options) · POST /api/space · POST /api/undo {scope|turn} · POST /api/clear · GET /api/instructions · POST /api/instructions/{id}/resolve · POST /api/status · POST /api/chat {agent?, text} · WS /ws (browser sync + chat events)

Tests #

cargo test                          # fractional indices, room links/crypto/framing
node scripts/smoke.mjs [url]        # chat turn + AGENT: note against a running drawgent
node scripts/e2e-browser.mjs [url]  # real browser: chat panel + note typed on the canvas
node scripts/room-e2e.mjs           # fresh excalidraw.com room ↔ drawgent, both directions
node scripts/remote-room-e2e.mjs    # self-hosted room ([remote], peers storage): token, leave-when-alone, plain JSON both ways (fake collab server)
node scripts/laser-e2e.mjs          # laser zone → chat → agent edits only that zone (needs setup claude)
node scripts/diagram-e2e.mjs        # --diagram file: clean output, git pull / hand edits flow back
node scripts/efficiency-e2e.mjs     # check_layout, add_graph, small/cropped screenshots, incremental get_scene, token usage
node scripts/claude-bridge-e2e.mjs  # built-in Claude bridge: streaming, permission prompt, Stop, usage (fake claude CLI)
node scripts/codex-bridge-e2e.mjs   # built-in Codex bridge: same, over a fake codex app-server
node scripts/gestures-e2e.mjs       # laser gestures (strike, ↔, tap), make_space, delete+reconnect, undo (agent, Ctrl+Z, per turn)
node scripts/boards-e2e.mjs         # several boards: move/copy/split, folder mode, editor switching
node scripts/code-e2e.mjs           # code links: agent + Code tab, link icon, drawgent check/--fix
node scripts/build-e2e.mjs          # build what I drew: diff, Build button, agent implements + marks progress (needs setup claude)
node scripts/pointing-e2e.mjs       # pointing at code: tree/Ctrl+P, Code-tab laser, basket, code cards, repo map (fake agent)

Layout #

src/ (Rust), one folder per role; dependencies only point down the list:

  • main.rs: CLI parsing and dispatch.
  • cli/: setup.rs, attach.rs (session discovery and picker), up.rs (up / serve, starts the server; resolves --diagram), check.rs (drawgent check), remote.rs (drawgent remote add|list).
  • sync/: hub.rs (routing, notes, chat log), server.rs (HTTP/WS + REST), room.rs (Excalidraw room client: excalidraw.com and configured servers).
  • agents/: mod.rs (queue, workers), acp.rs (ACP driver: new / fork sessions), opencode.rs / codex.rs (live sessions). Agents report to the hub through an event channel.
  • bridge/: ACP bridges built into the binary (drawgent bridge <agent>): claude.rs (Claude Code stream-json), codex.rs (codex app-server).
  • canvas/: scene.rs (store and edit operations), boards.rs (boards and their files), diagram.rs (.excalidraw files), build.rs (baselines and the semantic diff), lint.rs (layout lint), autolayout.rs (graph layout), gesture.rs (laser gestures and delete impact), history.rs (agent edits, undo), el.rs, geometry.rs, fractional.rs. No renderer dependency: it asks a Layout.
  • code/: mod.rs (workspace files, search, code links and their checks), repomap.rs (repo map boards).
  • render/: mod.rs (Chrome over CDP, implements Layout), chrome.rs (find / install Chrome).
  • config.rs: config file and cache paths. mcp.rs: MCP server (REST client).

web/: editor (main.jsx, chat.jsx, boards.jsx, code.jsx, cards.jsx, build.jsx, laser.js, laserpoint.jsx) and renderer page (render.jsx).

Limits #

  • The renderer needs Chrome (a native renderer is planned).
  • Claude "attach" is a fork, because Claude Code has no public way to inject into a running terminal session.
  • Codex live attach is implemented, but was not yet tested against a logged-in Codex.
  • A room mirrors the main board only. Images/files are not synced.
  • On self-hosted servers, drawgent relays but doesn't save: a browser must have the document open (see docs/remote-rooms.md).

License #

drawgent is free software: GPL-3.0-or-later, with no warranty. drawgent licenses prints the notice, and the editor's menu has About drawgent (/licenses).

The binary bundles third-party work under its own GPL-compatible licenses:

  • Rust crates and the npm packages built into the web pages: MIT, Apache-2.0, ISC, BSD-2/3-Clause, Zlib, Unicode-3.0, CDLA-Permissive-2.0 (Mozilla's CA roots), MPL-2.0 OR Apache-2.0, CC0, Unlicense, 0BSD.
  • Excalidraw's fonts: SIL OFL 1.1, and MIT for Comic Shanns. Liberation Sans 1.05 is left out because its license is GPLv2 with a font exception.
  • The drawing guide, adapted from excalidraw-mcp (MIT).

Nothing is copyleft-only or GPL-incompatible. Every text is in THIRD_PARTY_LICENSES.md. After changing dependencies, regenerate it with make licenses; make dist fails while it is out of date.

The coding agents (Claude Code, Codex, opencode) and Chrome are not part of drawgent. drawgent starts them as separate programs from your own install, under their own terms.