---
title: "diagram-render"
url: "https://claudemods.dev/zh-tw/builds/diagram-render-6b9efd"
source: "https://github.com/KilimcininKorOglu/claude-code-mods/tree/main/plugins/diagram-render"
source_type: "github"
repo: "https://github.com/KilimcininKorOglu/claude-code-mods/tree/main/plugins/diagram-render"
author: "KilimcininKorOglu"
author_handle: "KilimcininKorOglu"
stars: 13
category: "工具與整合"
categories: ["tools"]
tags: ["diagrams", "hooks", "kitty", "mermaid", "mmdc", "terminal-graphics"]
permission_level: 2
scan_complete: true
install: "claude plugin marketplace add KilimcininKorOglu/claude-code-mods\nclaude plugin install diagram-render@kilimcininkoroglu-mods"
added: "2026-10-05T01:50:36.092Z"
updated: "2026-10-04T23:54:15Z"
locale: "zh-tw"
content_locale: "zh-tw"
---

# diagram-render

一個 Claude Code mod，使用已安裝的 mmdc 渲染模型回覆中的 mermaid 區塊，並將每張圖片繪製在回覆下方。

## Description

diagram-render 掛鉤 turn.complete 和 assistant message render，偵測已閉合的 ```mermaid 區塊，然後將它們排入背景渲染。每輪結束後，它透過 argv 執行 `mmdc -i <hash>.mmd -o <hash>.png -b transparent -t dark -q`（每個上限 60 秒），將檔案快取到依區塊雜湊命名的 $TMPDIR/diagram-render 中，因此每個區塊在每個工作階段只渲染一次。準備好的圖片會在回覆下方以最多 100 欄、30 列繪製；在 kitty/Ghostty 中使用 kitty graphics protocol 顯示，在其他地方替換為 `mermaid diagram 1`。語法錯誤區塊只記錄一次並保留為文字；缺少 mmdc 時每個工作階段只記錄一次 npm 安裝提示。它提供 `/diagram-render` 和 `/diagram-render on|off`（預設開啟）。透過 `claude plugin marketplace add KilimcininKorOglu/claude-code-mods`，接著 `claude plugin install diagram-render@kilimcininkoroglu-mods` 安裝；function hooks 需要 Claude Code 2.1.288+，另外需要 `npm i -g @mermaid-js/mermaid-cli`。達到 L2：讀取回覆文字和 PNG 標頭，在本機執行 mmdc，寫入區塊來源檔和 PNG，並儲存 on/off 設定。

## Install

```
claude plugin marketplace add KilimcininKorOglu/claude-code-mods
claude plugin install diagram-render@kilimcininkoroglu-mods
```

## Original README

# diagram-render

When the model explains a flow or an architecture, it often writes a mermaid diagram, and in the terminal you only see the source code of that diagram. This mod renders each mermaid block with an installed `mmdc` and draws the picture under its reply. The block stays in the reply as text; the picture comes beneath it.

## What it does

1. When a reply is drawn, each closed ` ```mermaid ` block in it is queued, and the last text of each turn is queued at the turn's end too. A block that is still streaming has no closing fence yet, so it waits.
2. After the turn ends, the queued blocks render one at a time in the background: `mmdc -i <hash>.mmd -o <hash>.png -b transparent -t dark -q`, by argv, at most 60 s each. The files live under `$TMPDIR/diagram-render`, named after a hash of the block, so a block renders once per session.
3. When a picture is ready, the reply redraws with the picture under it: at most 100 columns wide and 30 rows tall, keeping the picture's shape.
4. A block mmdc refuses (a syntax error) logs `a diagram was not rendered: Error: Parse error ...` once and stays text.
5. Without `mmdc` on PATH the mod logs `mmdc is not installed, so mermaid blocks stay text: npm i -g @mermaid-js/mermaid-cli` once per session and runs nothing more.

The picture shows in a terminal with the kitty graphics protocol (kitty, Ghostty). Other terminals show `mermaid diagram 1` in its place. Only the terminal surface draws it.

In the live check without mmdc, the install line came once after the reply. With mmdc on PATH, a three-node flowchart rendered in 1.1 s and `mermaid diagram 1` appeared under the reply in tmux, with no refused tree in the debug log.

## Command

    /diagram-render            on or off, whether mmdc was found, and the counts of this session
    /diagram-render on | off   on by default

## Install

    claude plugin marketplace add KilimcininKorOglu/claude-code-mods
    claude plugin install diagram-render@kilimcininkoroglu-mods

Function hooks are early access. Claude Code 2.1.288 and later load them by default, so there is nothing to switch on.

## After installing

1. Install the mermaid CLI: `npm i -g @mermaid-js/mermaid-cli`. It renders through puppeteer. If npm skips puppeteer's browser download, set `PUPPETEER_EXECUTABLE_PATH` to an installed Chrome, for example `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`.
2. Use a terminal that shows pictures (kitty, Ghostty) to see them.
3. Restart Claude Code.

## What it can reach

Validated with `claude plugin validate` on Claude Code 2.1.288:

    ❯ ./register.tsx hooks: session.start, command.run{command=diagram-render}, turn.complete, ui.render{component=AssistantMessage}
    ❯ ./register.tsx calls: $.clock.after, $.command.register, $.env.get (via workDir), $.fs.read (via renderOne), $.fs.write (via renderOne), $.process.run (via mmdcReady, renderOne), $.store.get (via readSettings), $.store.set (via runCommand), $.ui.invalidate (via drain, readSettings, runCommand), $.ui.log (via drain, mmdcReady), $.ui.resolve
    ❯ ./register.tsx env writes: nothing
    ❯ ./register.tsx env reads: TMPDIR

Reach L2: it runs processes and writes files.

    1. Reads:    the text of the model's replies and the header of each rendered PNG
    2. Runs:     mmdc --version once, and mmdc per new block, by argv
    3. Sends:    nothing to the model; nothing leaves the machine
    4. Persists: the block source and its PNG under $TMPDIR/diagram-render, and the on/off setting in $.store
    5. Hostile input: the block source comes from the model and reaches mmdc only as a file mmdc parses; mermaid runs it in a headless browser, so a hostile block runs inside that browser

## Limits

- The pictures live in memory: a resumed session draws its old replies without them until the next turn ends.
- The theme is dark on a transparent background, so on a light terminal the lines are hard to see.
- The mod does not delete the files under `$TMPDIR/diagram-render`; the system clears the temp directory.

## Development

    make install     # eslint, typescript-eslint, typescript
    make lint        # complexity limit 10, the build fails above it
    make typecheck   # needs .claude/types/ from /plugin-types
    make validate
    make test        # claude plugin test
