KilimcininKorOglu/claude-code-mods/tree/main/plugins/diagram-render
diagram-render
一个 Claude Code mod,使用已安装的 mmdc 渲染模型回复中的 mermaid 区块,并将每张图片绘制在回复下方。
关于这个 mod
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 设置。
安装
请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。
claude plugin marketplace add KilimcininKorOglu/claude-code-mods claude plugin install diagram-render@kilimcininkoroglu-mods
原文 / 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
- When a reply is drawn, each closed
```mermaidblock 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. - 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. - 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.
- A block mmdc refuses (a syntax error) logs
a diagram was not rendered: Error: Parse error ...once and stays text. - Without
mmdcon PATH the mod logsmmdc is not installed, so mermaid blocks stay text: npm i -g @mermaid-js/mermaid-clionce 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
- Install the mermaid CLI:
npm i -g @mermaid-js/mermaid-cli. It renders through puppeteer. If npm skips puppeteer's browser download, setPUPPETEER_EXECUTABLE_PATHto an installed Chrome, for example/Applications/Google Chrome.app/Contents/MacOS/Google Chrome. - Use a terminal that shows pictures (kitty, Ghostty) to see them.
- 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
获取徽章
这是你的项目吗?把这个徽章放进 README 或网站,链接回本页。


