KilimcininKorOglu/claude-code-mods/tree/main/plugins/diagram-render
diagram-render
설치된 mmdc로 모델 응답의 mermaid 블록을 렌더링하고 각 그림을 응답 아래에 그리는 Claude Code mod입니다.
이 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열 x 30행으로 그리며 kitty/Ghostty에서는 kitty graphics protocol로 표시하고 그 외에는 mermaid diagram 1로 대체합니다. 구문 오류 블록은 한 번만 기록하고 텍스트로 남기며 mmdc가 없으면 세션마다 한 번 npm 설치 힌트를 기록합니다. /diagram-render와 /diagram-render on|off(기본 on)를 제공합니다. 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
원문 / 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

