natsukium/claude-code-figures-plugin

natsukium/claude-code-figures-plugin

一個 Claude Code mod,使用 kitty graphics 協定,在終端機轉錄中內嵌繪製圖表、LaTeX 數學公式與工具結果圖片。

如果圖片依尺寸上限縮小後會低於自然尺寸的 60%,它會放大到終端機高度;如果仍然太小,則會在圖片下方說明,例如 shown at 43% · /figures to enlarge。
/figures 會開啟顯示目前工作階段圖片的面板,起始顯示最近一張小到難以閱讀的圖片;如果沒有,則顯示最新圖片。按 p 與 n 瀏覽圖片,按 o 使用 open(macOS)或 xdg-open 開啟目前圖片,按 Escape 或輸入下一個提示關閉面板。

外掛還附帶一個 diagrams skill,用來告訴 Claude 哪些語言會被繪製,以及應如何撰寫這些語言才能轉譯。
每張轉譯後的 PNG 都會快取在 $TMPDIR/claude-figures/ 下,檔名由原始碼與主題的雜湊值組成,因此恢復工作階段時可以重新繪製圖片而不用再次轉譯。工作階段開始時會刪除超過七天的檔案。
需要 Claude Code 2.1.287 或更新版本,在啟用 mods(function-hook plugins)的終端機中執行,且該終端機被 Claude Code 視為支援 kitty graphics;請參閱 Terminal support。每種圖片也需要 PATH 中存在相應程式:
| 圖片 | 需要的程式 | | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | mermaid | mmdr 或 mmdc;建議 resvg | | dot、graphviz | Graphviz 的 dot 與 resvg | | d2 | d2 與 resvg | | svg、數學公式 | resvg | | PNG 以外的工具圖片 | magick(ImageMagick)或 sips(macOS 內建) |
claude plugin marketplace add natsukium/claude-code-figures-plugin
claude plugin install figures@figures
使用 cargo install mermaid-rs-renderer 安裝 mmdr。
使用 /config 或 claude plugin configure figures 設定以下選項。
| 選項 | 預設值 | 意義 | | --------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | theme | auto | auto 跟隨 Claude Code 的主題;也可使用 dark、default、forest、neutral、modern(僅 mmdr 支援;mmdc 會將其繪製為 default)。在 dark 下數學公式以淺色繪製,其他主題下以深色繪製 | | background | transparent | 圖表背景;transparent 會讓終端機背景透出 | | scale | 2 | 圖片的像素密度;大於 1 時需要 resvg | | cell_width_px | 8 | 假定一個終端機儲存格的寬度,單位是圖表排版使用的像素 | | cell_aspect | 2.1 | 假定一個終端機儲存格的高寬比 | | max_columns | 120 | 圖片允許的最大寬度,單位是儲存格;圖片也會維持在終端機範圍內 | | max_rows | 30 | 圖片在為了可讀性而放大前允許的最大高度,單位是儲存格 | | renderers | (空) | 按優先順序排列的轉譯器 id,以逗號分隔;見下文 | | tool_images | true | 繪製工具結果中找到的圖片 | | tool_image_max_rows | 12 | 工具結果縮圖允許的最大高度,單位是儲存格 |
renderers 會選擇並排列繪製各語言的程式。id 包括 mmdr 與 mmdc(mermaid)、dot、d2、svg、mathjax。如果某種語言列出了任何轉譯器,就只使用這些轉譯器,並依列出的順序執行;其他語言繼續使用預設設定。因此,mmdc 會只用 mmdc 繪製 mermaid,而 mmdc,mmdr 會先嘗試 mmdc。工作階段開始時會回報不存在轉譯器的 id。
只有當終端機的 XTVERSION 回覆名稱包含 kitty(0.28.0 或更新版本)或 Ghostty 時,Claude Code 才會啟用圖片。即使終端機用其他名稱回應 kitty graphics 查詢,只要回應正確,仍會取得替代文字,例如 [mermaid diagram 1]。設定 TERM 或 TERM_PROGRAM 不會有任何作用。
要在這類終端機使用外掛,請設定 Claude Code 讀取的覆寫值:
CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 claude
這也會略過 Claude Code 的 tmux 檢查。在 tmux 內,圖片還需要 set -g allow-passthrough on。
若要查看 Claude Code 的判斷結果,請用 --debug 啟動它,並在偵錯記錄中尋找 Terminal capabilities: 那一行。
tsconfig.json 會延伸 .claude-plugin/types/ 中的引擎型別定義,Vite、Vitest 與 tsc 都會讀取這些定義。Claude Code 只有從這個資料夾載入外掛時才會寫入型別定義,而且沒有其他指令會單獨寫入它們,因此 pnpm types 會使用虛假的 API key 啟動 claude -p --plugin-dir .,型別定義存在後會忽略失敗的請求。build、test 與 typecheck 會先執行它。Claude Code 是開發相依套件,所以指令稿和 pnpm exec claude 使用 pnpm-lock.yaml 中鎖定的版本,與 PATH 上的 claude 版本無關。
pnpm install
pnpm build # regenerate hooks/vendor/
pnpm test # unit tests (Vitest, tests/unit/*.spec.ts)
pnpm typecheck
pnpm exec claude plugin validate .
pnpm exec claude plugin test . # hooks through the engine (tests/engine/*.test.ts)
Claude Code 會將 hooks/ 作為 TypeScript 原始碼載入,因此只有第三方程式碼會被建置。pnpm build 會使用 Vite 將 MathJax 與 @noble/hashes 打包到 hooks/vendor/,並提交這些檔案,讓儲存庫保持可直接安裝。Hooks 模組不能匯入超過 1 MiB 的檔案,也不能在執行階段匯入模組,因此建置會將套件拆分成多個區塊,並把字型的每個字形範圍寫成 JSON;外掛會在公式第一次使用該字形範圍時讀取它。
引擎拒絕在匯入之間傳遞 $ 的模組,因此 hooks/register.tsx 會把外掛需要的 $ 包裝在 Io 物件(hooks/io.ts)中,其他每個模組都會使用該物件。
Apache-2.0。hooks/vendor/ 由 MathJax 及其 New Computer Modern font 建置,兩者均為 Apache-2.0;noble-hashes 使用 MIT 授權。
請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。
claude plugin marketplace add natsukium/claude-code-figures-plugin claude plugin install figures
A Claude Code mod that draws diagrams, LaTeX math, and tool-result images inline in the terminal transcript, using the kitty graphics protocol.

mermaid, dot (or graphviz), d2, or svg in Claude's
reply is rendered and drawn under the reply. The code stays visible above the picture.$$ … $$, \[ … \], or a math, latex, or tex code block, is
typeset with MathJax. Inline $…$ stays text, since a picture cannot
sit inside a line, and a latex block holding a whole document (\documentclass) stays code.Read on a PNG, JPEG, GIF, WebP, or SVG file, or a screenshot an MCP
tool returns, is drawn under the tool's row, where Claude Code otherwise shows only a size line;
an SVG read only in part is left alone. In a collapsed tool group they are thumbnails; ctrl+o
unfolds the group and draws them full size. A PNG, JPEG, GIF, WebP, or SVG Claude sends to another
device with SendUserFile is drawn under its attachment line too, so it is on screen when you
come back to the terminal. It is read from disk when the row is first drawn; overwriting the file
later leaves that picture as it was.A picture the size caps would shrink below 60% of its natural size grows up to the terminal's
height, and one still smaller says so under it, such as shown at 43% · /figures to enlarge.
/figures opens a pane with the session's pictures, starting on the newest one drawn too small to
read, or else the newest. p and n step through them, o opens the current one with open
(macOS) or xdg-open, and Escape or your next prompt closes the pane.

The plugin also ships a diagrams skill, which tells Claude which languages are drawn and how to
write them so they render.
Each rendered PNG is cached under $TMPDIR/claude-figures/, named by a hash of the source and the
theme, so a resumed session draws its pictures again without re-rendering. Files older than seven
days are removed when a session starts.
Claude Code 2.1.287 or later, with mods (function-hook plugins) enabled, in a terminal it treats as
kitty-graphics capable; see Terminal support. Each kind of picture also needs
programs on PATH:
| Picture | Needs |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| mermaid | mmdr or mmdc; resvg recommended |
| dot, graphviz | Graphviz's dot and resvg |
| d2 | d2 and resvg |
| svg, math | resvg |
| Tool images other than PNG | magick (ImageMagick) or sips (built into macOS) |
scale option.claude plugin marketplace add natsukium/claude-code-figures-plugin
claude plugin install figures@figures
Install mmdr with cargo install mermaid-rs-renderer.
Set these with /config or claude plugin configure figures.
| Option | Default | Meaning |
| --------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| theme | auto | auto follows Claude Code's theme; or dark, default, forest, neutral, modern (mmdr only; mmdc draws it as default). Math is drawn light on dark and dark otherwise |
| background | transparent | Diagram background; transparent lets the terminal's background show through |
| scale | 2 | Pixel density of the picture; above 1 needs resvg |
| cell_width_px | 8 | Assumed width of one terminal cell, in the pixels diagrams are laid out in |
| cell_aspect | 2.1 | Assumed height-to-width ratio of one terminal cell |
| max_columns | 120 | Widest a picture may be, in cells; it is also kept inside the terminal |
| max_rows | 30 | Tallest a picture may be before it is grown for legibility, in cells |
| renderers | (empty) | Renderer ids in preference order, comma-separated; see below |
| tool_images | true | Draw images found in tool results |
| tool_image_max_rows | 12 | Tallest a tool-result thumbnail may be, in cells |
renderers picks and orders the programs that draw each language. The ids are mmdr and mmdc
(mermaid), dot, d2, svg, and mathjax. A language with any of its renderers listed uses only
those, in the listed order; the others keep the default. So mmdc draws mermaid with mmdc alone,
and mmdc,mmdr tries mmdc first. An id no renderer has is reported when a session starts.
Claude Code enables pictures only when the terminal's XTVERSION reply names kitty (0.28.0 or later)
or Ghostty. A terminal that answers the kitty graphics query correctly under any other name still
gets the alt text, such as [mermaid diagram 1]. Setting TERM or TERM_PROGRAM has no effect.
To use the plugin on such a terminal, set the override Claude Code reads:
CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 claude
This also skips Claude Code's tmux check. Inside tmux, the pictures additionally need
set -g allow-passthrough on.
To see what Claude Code decided, start it with --debug and look for the Terminal capabilities:
line in the debug log.
cell_width_px and cell_aspect, since mods are
not told the terminal's cell size in pixels. Adjust them if pictures look stretched.theme=auto follows Claude Code's own
theme (/config): a light variant draws light pictures, the others dark. When Claude Code's
theme is itself auto, its resolved value is not exposed, so COLORFGBG decides where the
terminal exports it, and dark otherwise.A --> B -->|ok| C) is misparsed; write one edge per line. Such a block renders
without an error, so it is not handed to mmdc; set renderers to mmdc to avoid mmdr.\text{日本語}, is drawn by resvg with a system
font./figures pane shares the screen with the prompt, so in a short terminal it has only a few
rows; o opens the picture at full size outside the terminal.tsconfig.json extends the engine's typings in .claude-plugin/types/, which Vite and Vitest read
as well as tsc. Claude Code writes them only when it loads the plugin from this folder, and no
command writes them alone, so pnpm types starts claude -p --plugin-dir . with a dummy API key
and ignores the failed request once the typings exist. build, test, and typecheck run it
first. Claude Code is a dev dependency, so the scripts and pnpm exec claude use the version
pinned in pnpm-lock.yaml, whatever claude is on PATH.
pnpm install
pnpm build # regenerate hooks/vendor/
pnpm test # unit tests (Vitest, tests/unit/*.spec.ts)
pnpm typecheck
pnpm exec claude plugin validate .
pnpm exec claude plugin test . # hooks through the engine (tests/engine/*.test.ts)
Claude Code loads hooks/ as TypeScript source, so only third-party code is built. pnpm build
bundles MathJax and @noble/hashes with Vite into hooks/vendor/, which is committed so the
repository stays installable as is. A hooks module imports no file over 1 MiB and cannot import
modules at run time, so the build splits the bundle into chunks and writes each of the font's
glyph ranges as JSON, which the plugin reads the first time a formula uses it.
The engine refuses a module that passes $ across an import, so hooks/register.tsx wraps what
the plugin needs from $ in an Io object (hooks/io.ts), and every other module takes that.
Apache-2.0. hooks/vendor/ is built from MathJax and its
New Computer Modern font, both Apache-2.0, and
@noble/hashes, MIT.