Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Docs: herdr and the paste preview in the README, the setup line in Install
razorback16a2b87746af3e
diff --git a/README.md b/README.mdindex daa2dab..c43e046 100644--- a/README.md+++ b/README.md@@ -38,7 +38,7 @@ You need Claude Code 2.1.298 or later, [Typst](https://typst.app) 0.15, and macO|---|---|---|| kitty 0.28+, Ghostty, cmux (macOS) | Yes | Nothing || iTerm2 3.6+ (macOS) | Yes | Run `/iui setup` one time |-| herdr, in kitty or Ghostty | Yes | Run `/iui setup` one time |+| herdr, in kitty, Ghostty or iTerm2 | Yes | Run `/iui setup` one time || Rio 0.5.27+ | Yes (not tested) | Set `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` || ssh | Yes, from kitty or Ghostty | Refer to [Install](docs/install.md#terminals) || tmux, screen | No | — |@@ -109,9 +109,9 @@ The mod sends nothing about you or your sessions anywhere.- **Network:** one GET request each day at most, to `raw.githubusercontent.com`, for the public `plugin.json` of this mod. It only tells you about a new version. `/iui updates off` stops it. It also stops when `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`, `DISABLE_UPDATES` or `DISABLE_AUTOUPDATER` is set.- **Clipboard, read:** a small `perl` process watches the clipboard while the mod is on and has drawn a picture (not over ssh). On macOS it reads only the change counter; when the counter changes, the mod reads the text once with a short `perl` script (PerlObjCBridge). On Linux a notifier (`wl-paste --watch`, `clipnotify` or GTK 3 from `python3`) tells it of each change, and it then reads the text with `wl-paste`, `xclip` or GTK. `/iui grab` with no mouse selection also reads the clipboard once. The text is only checked for picture cells (then a toast names `/iui grab`); it is kept in memory only and sent nowhere (`/iui dump` writes the last clipboard with picture cells to `copy-debug.json` in the cache folder). A password manager's copy is never read: on macOS a copy with a concealed or transient type, on Linux a copy that offers the `x-kde-passwordManagerHint` target, and on Wayland also a copy marked sensitive. (On Wayland, `wl-paste --watch` hands each new copy to `cat`, which drops it.)- **Clipboard, written:** only at these times: when you release a picture selection, when you click a link, a file path, a command or a copy button in a picture, on `/iui grab`, when you press the command button in a link row (in fullscreen with `/iui select off`, where Claude Code gets the click), and when the mod changes a `$.ui.copy` that has picture cells to its text.-- **Files:** a private cache folder in `$TMPDIR` (`cc-intelligent-ui-<uid>`, `/tmp` when `TMPDIR` is not set; mode 700, its folders deleted after 2 days). Each compile makes a folder of its own in it (the Typst root, see below) and deletes it after the compile. Also `~/.cache/cc-intelligent-ui/designs` (files deleted after 180 days) and `~/.cache/cc-intelligent-ui/fonts` (fonts copied out of a terminal app, such as Ghostty's JetBrains Mono; `$XDG_CACHE_HOME` in place of `~/.cache` when it is set). `/iui setup` on macOS changes your shell start file, only when you run it or agree to its question.-- **Processes:** `typst`, the `perl` watcher, and short helper commands such as `perl`, `sh`, `osascript`, `defaults`, `plutil`, `fc-list` and `fc-match`. On Linux also `wl-paste`, `xclip`, `clipnotify` or `python3 -I` (GTK 3; isolated, so it loads no code from the project folder) for the clipboard.-- **Typst:** each compile of an answer or a plan runs with a narrow root: a new folder with the mod's template, the theme and the images that the text names. So the code in an answer cannot read other files on your computer. The skill's `check.sh` compiles the same way.+- **Files:** a private cache folder in `$TMPDIR` (`cc-intelligent-ui-<uid>`, `/tmp` when `TMPDIR` is not set; mode 700, its folders deleted after 2 days). Each compile makes a folder of its own in it (the Typst root, see below) and deletes it after the compile. Also `~/.cache/cc-intelligent-ui/designs` (files deleted after 180 days) and `~/.cache/cc-intelligent-ui/fonts` (fonts copied out of a terminal app, such as Ghostty's JetBrains Mono; `$XDG_CACHE_HOME` in place of `~/.cache` when it is set). The previews of pasted images are made in the cache folder too, from the image files that Claude Code writes when you paste. `/iui setup` (iTerm2 on macOS, and herdr) changes your shell start file, only when you run it or agree to its question.+- **Processes:** `typst`, the `perl` watcher, and short helper commands such as `perl`, `sh`, `osascript`, `defaults`, `plutil`, `fc-list` and `fc-match`. In herdr, while the mod is on and pictures show, a check each second finds the herdr client that you use: `stat` of the terminals' devices (the time of the last key), and on macOS `lsappinfo` (the app in front); each 10 s also `ps` (the processes and, of your own herdr clients, their variables) and `lsof`. Of a client's variables, the mod keeps only those of the terminal (for example `TERM`, `ITERM_PROFILE`, `GHOSTTY_RESOURCES_DIR`); it writes none of this anywhere. On Linux also `wl-paste`, `xclip`, `clipnotify` or `python3 -I` (GTK 3; isolated, so it loads no code from the project folder) for the clipboard.+- **Typst:** each compile of an answer or a plan runs with a narrow root: a new folder with the mod's template, the theme and the images that the text names. So the code in an answer cannot read other files on your computer. The skill's `check.sh` compiles the same way, and so does the preview of a pasted image (a folder with only its template and the pasted image).## Docsdiff --git a/docs/how-it-works.md b/docs/how-it-works.mdindex 8cf5cff..21667c0 100644--- a/docs/how-it-works.md+++ b/docs/how-it-works.md@@ -20,6 +20,8 @@A picture cell holds its row and its column (kitty placeholder U+10EEEE plus two combining marks). The mod finds the drawn page that has these rows, at the size that it is drawn. Then it finds the position of each word on that page: it runs the probe (`typst query` on the same template, with the same inputs as the PNG compile, plus `probe=1` and `page=<n>`) only for the pages that a copy reads, and (for picture select) for the pages on the screen. The mod keeps the positions of the last 64 pages in memory. It writes nothing to disk for this, and the PNGs do not change. The mod takes the words in the selected cells.+10. Pasted images: the `prompt.edit` and `prompt.change` hooks note the `[Image #N]` numbers of the draft. A `ui.render` hook on `AbovePrompt` draws a small preview of each one above the prompt box, from the PNG that Claude Code wrote at the paste, and a hook on `UserMessage` draws them the same size under a sent prompt. Typst makes a copy that fills the preview's cells (`render/fill.typ`), in a root folder of its own with only that template and a link to the pasted PNG.+## Picture selectThe selection of Claude Code copies picture cells as kitty placeholder characters, not as text (from Claude Code 2.1.305, it skips picture cells). Thus the mod selects pictures itself (`hooks/lib/select.ts`):diff --git a/docs/install.md b/docs/install.mdindex 92d02c2..a68a790 100644--- a/docs/install.md+++ b/docs/install.md@@ -19,6 +19,15 @@- Pages are shorter in herdr, so that herdr can send each one to the terminal. Refer to [Limitations](limitations.md).- In iTerm2, herdr sends each row of a picture as one part of the image, and iTerm2 counts the top of that part from the bottom of the image. Thus the rows would show in the opposite order. When the herdr client that the mod uses is iTerm2, the mod keeps the rows of each page and each picture in an order that iTerm2 shows correctly. Picture select also works. When you go to a different terminal (for example Ghostty), the mod draws the pictures again in the usual order. `/iui details` then shows `pages and pictures stored upside down by rows`. With `herdr --remote` in iTerm2, the mod cannot find the client, so the rows of the pictures show in the wrong order. Refer to [Limitations](limitations.md).- **Rio 0.5.27 or later (not tested):** set `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` before you start Claude Code. Rio works on macOS and on Linux.+- **The setup line.** `/iui setup` (and a yes to the question in iTerm2 or herdr) adds this block to your shell's start file. It sets the variable in iTerm2 and herdr only, not in tmux or screen:++ ```sh+ # >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>+ if { [ "$TERM_PROGRAM" = "iTerm.app" ] || [ "$TERM_PROGRAM" = "herdr" ]; } && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi+ # <<< cc-intelligent-ui <<<+ ```++ For fish, the line is `if test "$TERM_PROGRAM" = "iTerm.app" -o "$TERM_PROGRAM" = "herdr"; and not set -q TMUX; and not set -q STY; set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1; end`. The markers stay as in older versions, whose line was for iTerm2 only. `/iui setup` replaces an older line, and `/iui setup remove` removes the block. If the mod cannot read the file, it changes nothing and shows the line to add.- Do not put the variable in the `env` of `~/.claude/settings.json`. It then applies in every terminal, also where pictures cannot show.- **Warp (not yet):** Warp does not draw kitty pictures with Unicode placeholders yet. The pull request [warpdotdev/warp#16312](https://github.com/warpdotdev/warp/pull/16312) adds them. The mod will support Warp when that pull request is merged.- **WezTerm (not yet):** WezTerm does not draw kitty pictures with Unicode placeholders yet, so it shows no pictures, also with the variable set. The pull request [wezterm/wezterm#7924](https://github.com/wezterm/wezterm/pull/7924) adds them. The mod will support WezTerm when that pull request is merged.diff --git a/docs/usage.md b/docs/usage.mdindex 3eeaecf..c795323 100644--- a/docs/usage.md+++ b/docs/usage.md@@ -38,7 +38,8 @@ Intelligent UI draws Claude's answers as rendered Markdown pictures. Only the drWhen you paste an image into the prompt box, the box shows `[Image #N]`. The mod then shows a small preview of the image above the prompt box, before you send the prompt. The number of the image (`#N`) shows in dim text at the left of its preview.-- The preview fills its cells. Typst makes a copy of the image that has the size of the cells, one time for each image and size, in the cache folder. Until the copy is ready, the preview shows the image as it is. Without Typst, or if Typst cannot make the copy, the preview also shows the image as it is.+- The preview fills its cells. Typst makes a copy of the image that has the size of the cells, one time for each image and size, in the cache folder. Typst runs in a folder of its own with only the pasted image, so it reads no other file. Until the copy is ready, the preview shows the image as it is. Without Typst, or if Typst cannot make the copy, the preview also shows the image as it is.+- In herdr in iTerm2, a preview shows only when its copy is ready (the mod stores the copy with its rows in the order that iTerm2 shows correctly).- The previews show side by side. When they do not fit in one line, they go on to the next line.- A preview is approximately 5 rows tall, or less when the space above the prompt box is small. The image keeps its shape.- When you delete the `[Image #N]` text, the preview of that image goes away. When you send or clear the prompt, all the previews go away.