Gives Claude a show_image tool and shows pasted images and images Claude reads inline in the terminal transcript

A Claude Code mod that shows images inline in your terminal.
It gives Claude a show_image tool. When you ask Claude to show you an image, the tool draws the file in the transcript. The image does not go into Claude's context. Claude uses Read when it must look at the image itself.
It also draws the images you paste into the prompt, under your message in the transcript, and the images Claude opens with Read, under the Read line.

Claude Code does not draw real images in iTerm2, so there the mod uses a fallback: colored half-block characters, two pixels per cell.

At the prompt of a Claude Code session in the terminal, type:
/plugin install inline-images --marketplace Mechazawa/claude-inline-images
Answer y to add the marketplace, then select a scope. The tool is available from the next prompt.
Orca 1.4.230 or later draws the images with the kitty graphics protocol when Claude Code knows the terminal can draw images. Orca tells Claude Code this in the Claude terminals it starts itself. When you start claude from a plain shell in Orca, add this to ~/.claude/settings.json, then quit and restart the Claude session (/reload-plugins is not enough):
{ "env": { "CLAUDE_CODE_FORCE_TERMINAL_IMAGES": "1" } }
Orca only reads image files from the project folder or the system temp folder ($TMPDIR), and only files up to 2 MiB. So in Orca the mod copies each image into the temp folder before drawing it. Larger images, images inside tmux and all images without the setting show as half blocks.
Ask Claude to show you a file:
show me ~/Downloads/screenshot.jpg
Claude calls show_image with these inputs:
| Input | Description |
|---|---|
path | Absolute or working-directory-relative path of the image |
columns | Width in terminal columns, 120 by default |
The image keeps its aspect ratio. It is never wider than the transcript.
To change the size limits, open /config and set these:
| Setting | Description |
|---|---|
inline-images.defaultColumns | Width of show_image when Claude gives none, 120 by default |
inline-images.maxColumns | Maximum width of every image, 255 by default |
inline-images.maxRows | Maximum height of every image, 40 by default |
When you paste an image into the prompt, the mod draws it 40 columns wide under your message. Images pasted before the mod was loaded are not drawn.
To turn this off, open /config and set inline-images.showPastedImages to false.
When Claude opens an image with Read (a screenshot it took, a chart it made), the mod draws that image 60 columns wide under the Read line in the transcript. Reads are usually folded into one line such as Read 3 files; the images go under that line. Images read before the mod was loaded are not drawn.
To turn this off, open /config and set inline-images.showReadImages to false.
Every image the mod draws has a [ copy ] button under it. Press it to put the image on the clipboard, then paste it into another app. The mod copies with osascript on macOS, and with wl-copy or xclip on Linux. These run on the machine where Claude Code runs, so in a session over SSH the image goes to that machine's clipboard.
To turn this off, open /config and set inline-images.showCopyButton to false.
Next to [ copy ] is an [ open ] button. Press it to open the image in your default image viewer, for example Preview on macOS. The mod uses xdg-open on Linux and open on macOS. Like the copy button, it runs on the machine where Claude Code runs.
To turn this off, open /config and set inline-images.showOpenButton to false.
Press [ collapse ] to hide an image and keep only its buttons. Press [ expand ] to show it again.
To turn this off, open /config and set inline-images.showCollapseButton to false.
sips, which macOS includes.sudo apt install imagemagick. For HEIC files, also install libheif-plugin-libde265.ffprobe.Converted and copied files go to a private claude-inline-images.XXXXXX folder in $TMPDIR, or in /tmp when TMPDIR is unset.
Run Claude Code with the mod loaded from this folder:
claude --plugin-dir .
Check and test it:
claude plugin validate .
claude plugin test .
hooks/register.tsx 447 lines1import { atom, read, update } from 'claude-code'
2import type { Elements, EngineInterface, Register } from 'claude-code'
3
4import type { Shown } from '../types'
5
6const TOOL = 'show_image'
7const FULL_NAME = 'mcp__inline-images__show_image'
8// Orca reads kitty image files only from the project or the system temp folder, and only up to 2 MiB.
9const ORCA_MAX_BYTES = 2 * 1024 * 1024
10const PASTED_COLUMNS = 40
11const READ_COLUMNS = 60
12// A terminal cell is about twice as tall as it is wide.
13const CELL_ASPECT = 2
14const DEFAULT_COLOR = 0x01000000
15const SPACE = 0x20
16const UPPER_HALF_BLOCK = 0x2580
17const LOWER_HALF_BLOCK = 0x2584
18
19// The BMP must be 24-bit, or 32-bit with alpha in the fourth byte, for rasterCells to read it.
20type Converter = {
21 binaries: string[]
22 size: (file: string) => string[]
23 png: (file: string, out: string) => string[]
24 bmp: (file: string, out: string, columns: number, rows: number) => string[]
25}
26
27const imageMagick = (binary: string): Converter => ({
28 binaries: [binary],
29 size: file => [binary, `${file}[0]`, '-format', 'width=%w height=%h', 'info:'],
30 png: (file, out) => [binary, `${file}[0]`, `png:${out}`],
31 bmp: (file, out, columns, rows) => [
32 binary, `${file}[0]`, '-resize', `${columns}x${rows}!`, '-type', 'TrueColorAlpha', '-define', 'bmp:format=bmp4', `bmp:${out}`,
33 ],
34})
35
36const CONVERTERS: Converter[] = [
37 {
38 binaries: ['sips'],
39 size: file => ['sips', '-g', 'pixelWidth', '-g', 'pixelHeight', file],
40 png: (file, out) => ['sips', '-s', 'format', 'png', file, '--out', out],
41 bmp: (file, out, columns, rows) => ['sips', '-s', 'format', 'bmp', '-z', String(rows), String(columns), file, '--out', out],
42 },
43 imageMagick('magick'),
44 imageMagick('convert'),
45 {
46 binaries: ['ffmpeg', 'ffprobe'],
47 size: file => ['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'default=nw=1', file],
48 png: (file, out) => ['ffmpeg', '-y', '-v', 'error', '-i', file, '-frames:v', '1', out],
49 bmp: (file, out, columns, rows) => [
50 'ffmpeg', '-y', '-v', 'error', '-i', file, '-frames:v', '1', '-vf', `scale=${columns}:${rows}`, '-pix_fmt', 'bgra', out,
51 ],
52 },
53]
54
55const findConverter = async ($: EngineInterface) => {
56 const found = await Promise.all(
57 CONVERTERS.map(async candidate => {
58 const checks = await Promise.all(candidate.binaries.map(binary => $.process.run(['sh', '-c', `command -v ${binary}`])))
59
60 return checks.every(check => check.exitCode === 0) ? candidate : undefined
61 }),
62 )
63
64 return found.find(candidate => candidate !== undefined)
65}
66
67let converter: Promise<Converter | undefined> | undefined
68
69const run = async ($: EngineInterface, argv: string[]) => {
70 const { exitCode, stdout, stderr } = await $.process.run(argv)
71
72 if (exitCode !== 0) {
73 throw new Error(`${argv[0]} failed: ${stderr.trim()}`)
74 }
75
76 return stdout
77}
78
79// mktemp makes the folder owner-only under a name nobody can take first, also in a shared /tmp.
80let tempDir: Promise<string> | undefined
81
82const makeTempDir = async ($: EngineInterface) => {
83 const tmp = (await $.env.get('TMPDIR').catch(() => undefined)) || '/tmp'
84
85 return (await run($, ['mktemp', '-d', `${tmp.replace(/\/+$/, '')}/claude-inline-images.XXXXXX`])).trim()
86}
87
88const inTempDir = async ($: EngineInterface, name: string) => {
89 tempDir ??= makeTempDir($).catch(error => {
90 tempDir = undefined
91 throw error
92 })
93
94 return `${await tempDir}/${Date.now()}-${Math.random().toString(36).slice(2, 8)}${name}`
95}
96
97// tmux does not pass kitty graphics through, and Claude Code draws an Image in Orca only with this flag.
98const drawsKittyInOrca = async ($: EngineInterface) =>
99 (await $.env.get('ORCA_IMAGE_PROTOCOL')) === 'kitty' &&
100 (await $.env.get('CLAUDE_CODE_FORCE_TERMINAL_IMAGES')) === '1' &&
101 (await $.env.get('TMUX')) === undefined
102
103const pixelSize = async ($: EngineInterface, using: Converter, file: string) => {
104 const stdout = await run($, using.size(file)).catch(() => '')
105
106 return {
107 width: Number(/width[:=] ?(\d+)/i.exec(stdout)?.[1] ?? 0),
108 height: Number(/height[:=] ?(\d+)/i.exec(stdout)?.[1] ?? 0),
109 }
110}
111
112// The terminal decodes PNG only, so every other format is converted first. Orca also gets a copy of a PNG, as the
113// PNG can sit outside the folders it reads.
114const asPng = async ($: EngineInterface, using: Converter, file: string) => {
115 const isPng = /\.png$/i.test(file)
116
117 if (isPng && !(await drawsKittyInOrca($))) {
118 return file
119 }
120
121 const converted = await inTempDir($, '.png')
122 await run($, isPng ? ['cp', file, converted] : using.png(file, converted))
123
124 return converted
125}
126
127type Look = { isCopyable: boolean; isOpenable: boolean; isCollapsible: boolean; maxColumns: number; maxRows: number }
128
129const cellBox = (shown: Shown, available: number, { maxColumns, maxRows }: Look) => {
130 const wanted = Math.min(shown.columns, available, maxColumns, 255)
131 const rows = Math.round((wanted * shown.height) / shown.width / CELL_ASPECT)
132
133 return rows <= maxRows
134 ? { columns: wanted, rows: Math.max(1, rows) }
135 : { columns: Math.max(1, Math.round((maxRows * CELL_ASPECT * shown.width) / shown.height)), rows: maxRows }
136}
137
138// Terminals without kitty graphics get the picture as half blocks: each cell shows two stacked pixels.
139const rasterCells = async ($: EngineInterface, using: Converter, file: string, columns: number, rows: number) => {
140 const bmp = await inTempDir($, '.bmp')
141 await run($, using.bmp(file, bmp, columns, rows * 2))
142 const { base64 } = await $.fs.read(bmp, { as: 'bytes' })
143 await $.process.run(['rm', '-f', bmp])
144 const view = new DataView(Uint8Array.fromBase64(base64).buffer)
145 const offset = view.getUint32(10, true)
146 const height = view.getInt32(22, true)
147 const bytesPerPixel = view.getUint16(28, true) / 8
148 const stride = Math.ceil((columns * bytesPerPixel) / 4) * 4
149
150 const pixel = (x: number, y: number) => {
151 const at = offset + (height < 0 ? y : height - 1 - y) * stride + x * bytesPerPixel
152
153 return bytesPerPixel === 4 && view.getUint8(at + 3) < 128
154 ? DEFAULT_COLOR
155 : (view.getUint8(at + 2) << 16) | (view.getUint8(at + 1) << 8) | view.getUint8(at)
156 }
157
158 const words = Array.from({ length: columns * rows }, (_, cell) => {
159 const x = cell % columns
160 const top = pixel(x, Math.floor(cell / columns) * 2)
161 const bottom = pixel(x, Math.floor(cell / columns) * 2 + 1)
162
163 if (top !== DEFAULT_COLOR) {
164 return [UPPER_HALF_BLOCK, top, bottom]
165 }
166
167 return [bottom === DEFAULT_COLOR ? SPACE : LOWER_HALF_BLOCK, bottom, DEFAULT_COLOR]
168 }).flat()
169
170 return new Uint8Array(Uint32Array.from(words).buffer).toBase64()
171}
172
173// wl-copy and xclip leave a child holding the clipboard, so its output goes to /dev/null, or the run waits for it.
174const CLIPBOARDS = [
175 ['osascript', '-e', 'on run argv', '-e', 'set the clipboard to (read (POSIX file (item 1 of argv)) as «class PNGf»)', '-e', 'end run'],
176 ['sh', '-c', 'wl-copy --type image/png < "$1" > /dev/null 2>&1', 'sh'],
177 ['sh', '-c', 'xclip -selection clipboard -t image/png -i "$1" > /dev/null 2>&1', 'sh'],
178]
179
180// xdg-open goes first because Debian's kbd package installs openvt as `open`. It can wait until the viewer it starts
181// is closed, so it runs in the background once it is found.
182const VIEWERS = [['sh', '-c', 'command -v xdg-open > /dev/null && { xdg-open "$1" > /dev/null 2>&1 & }', 'sh'], ['open']]
183
184const runFirst = async ($: EngineInterface, commands: string[][], file: string) => {
185 for (const argv of commands) {
186 if ((await $.process.run([...argv, file]).catch(() => undefined))?.exitCode === 0) {
187 return true
188 }
189 }
190
191 return false
192}
193
194const rasters = new Map<string, Promise<string>>()
195
196const describe = async ($: EngineInterface, using: Converter, path: string, columns: number): Promise<Shown> => {
197 const file = await asPng($, using, path)
198 const size = await pixelSize($, using, file)
199
200 if (size.width === 0 || size.height === 0) {
201 throw new Error(`${path} is not an image ${using.binaries[0]} can read`)
202 }
203
204 return { file, ...size, columns }
205}
206
207const picture = async (
208 $: EngineInterface,
209 { Box, Button, Image, Raster }: Elements['terminal'],
210 shown: Shown,
211 available: number,
212 key: string,
213 look: Look,
214) => {
215 const box = cellBox(shown, available, look)
216 const isCollapsed = look.isCollapsible && (await read($, collapsed))[key] === true
217 const copy = async () => $.ui.toast((await runFirst($, CLIPBOARDS, shown.file)) ? 'Copied the image' : 'Could not copy the image')
218 const open = async () => (await runFirst($, VIEWERS, shown.file)) || $.ui.toast('Could not open the image')
219 const toggle = () => update($, collapsed, all => ({ ...all, [key]: !isCollapsed }))
220 const withButtons = (drawn?: JSX.Element) =>
221 look.isCopyable || look.isOpenable || look.isCollapsible ? (
222 <Box flexDirection="column">
223 {drawn}
224 <Box flexDirection="row" columnGap={1}>
225 {look.isCollapsible && <Button key={`collapse-${key}`} label={isCollapsed ? 'expand' : 'collapse'} dimColor onPress={toggle} />}
226 {look.isCopyable && <Button key={`copy-${key}`} label="copy" dimColor onPress={copy} />}
227 {look.isOpenable && <Button key={`open-${key}`} label="open" dimColor onPress={open} />}
228 </Box>
229 </Box>
230 ) : (
231 drawn
232 )
233
234 if (isCollapsed) {
235 return withButtons()
236 }
237
238 const isKitty =
239 (await $.env.get('TERM_PROGRAM')) === 'ghostty' ||
240 (await $.env.get('TERM')) === 'xterm-kitty' ||
241 ((await drawsKittyInOrca($)) && ((await $.fs.stat(shown.file).catch(() => undefined))?.size ?? 0) <= ORCA_MAX_BYTES)
242
243 if (isKitty) {
244 return withButtons(<Image source={{ file: shown.file, format: 'png' }} {...box} alt={shown.file} />)
245 }
246
247 const using = await (converter ??= findConverter($))
248
249 if (using === undefined) {
250 return undefined
251 }
252
253 const cacheKey = `${shown.file}:${box.columns}x${box.rows}`
254 const cells = rasters.get(cacheKey) ?? rasterCells($, using, shown.file, box.columns, box.rows)
255 rasters.set(cacheKey, cells)
256
257 return withButtons(<Raster key={key} {...box} cells={await cells} />)
258}
259
260const pasted = atom({ plugin: 'inline-images', key: 'pasted' } as const, {})
261// Keyed by the key of the drawn image.
262const collapsed = atom({ plugin: 'inline-images', key: 'collapsed' } as const, {})
263// Keyed by the tool_use_id of a Read that returned an image.
264const reads = atom({ plugin: 'inline-images', key: 'reads' } as const, {})
265
266// A UserMessage row's requestId is its stored row's uuid with the last group zeroed.
267const rowKey = (id: string) => id.slice(0, 23)
268
269
270export const register: Register = (on, options) => {
271 const look = {
272 isCopyable: options.showCopyButton !== false,
273 isOpenable: options.showOpenButton !== false,
274 isCollapsible: options.showCollapseButton !== false,
275 maxColumns: typeof options.maxColumns === 'number' ? options.maxColumns : 255,
276 maxRows: typeof options.maxRows === 'number' ? options.maxRows : 40,
277 }
278 const defaultColumns = typeof options.defaultColumns === 'number' ? options.defaultColumns : 120
279
280 on('session.start', async ($, e, next) => {
281 await $.tool.register({
282 name: TOOL,
283 description:
284 'Show an image file to the user, drawn inline in their terminal. Use it when the user wants to see an image ' +
285 '(a screenshot, a chart, a generated picture). It does not put the image in your context: use Read for that.',
286 inputSchema: {
287 type: 'object',
288 properties: {
289 path: { type: 'string', description: 'Absolute or working-directory-relative path of a PNG, JPEG, GIF, WebP, HEIC or TIFF file' },
290 columns: { type: 'integer', minimum: 4, maximum: 255, description: `Width in terminal columns, ${defaultColumns} by default` },
291 },
292 required: ['path'],
293 },
294 isDeferred: false,
295 })
296
297 return next(e)
298 })
299
300 on('tool.call', { tool: FULL_NAME }, async ($, e) => {
301 const input = e as { path?: unknown; columns?: unknown }
302
303 if (typeof input.path !== 'string') {
304 return { deny: 'path must be a string' }
305 }
306
307 const real = (await $.fs.stat(input.path, { resolve: true }).catch(() => undefined))?.realPath
308
309 if (real === undefined) {
310 return { deny: `${input.path} does not exist` }
311 }
312
313 const using = await (converter ??= findConverter($))
314
315 if (using === undefined) {
316 return { deny: 'show_image needs sips (macOS), ImageMagick or ffmpeg to read images' }
317 }
318
319 const shown = await describe($, using, real, typeof input.columns === 'number' ? input.columns : defaultColumns)
320
321 return { result: JSON.stringify(shown) }
322 }).catch(($, e, next) => ({ deny: `show_image failed: ${next.error.message ?? next.error.kind}` }))
323
324 on('ui.render', { component: 'ToolResult', props: { tool: FULL_NAME } }, async ($, e, next) => {
325 // A stored result can lack columns.
326 const stored = typeof e.props.output === 'string' ? (JSON.parse(e.props.output) as Partial<Shown> & Omit<Shown, 'columns'>) : undefined
327 const shown = stored && { columns: defaultColumns, ...stored }
328
329 if (e.surface !== 'terminal' || e.props.isErrored || shown === undefined) {
330 return next(e)
331 }
332
333 return (await picture($, $.ui.resolve(e), shown, (e.viewport?.columns ?? 80) - 6, e.requestId, look)) ?? next(e)
334 })
335
336 if (options.showReadImages !== false) {
337 on('tool.call', { tool: 'Read' }, async ($, e, next) => {
338 const ran = await next(e)
339
340 if (ran.isError || ran.result?.type !== 'image') {
341 return ran
342 }
343
344 const using = await (converter ??= findConverter($)).catch(() => undefined)
345 const shown = using && (await describe($, using, e.file_path, READ_COLUMNS).catch(() => undefined))
346
347 if (shown) {
348 await update($, reads, all => ({ ...all, [e.tool_use_id]: shown })).catch(() => undefined)
349 }
350
351 return ran
352 }).catch(($, e, next) => next(e))
353
354 on('ui.render', { component: 'ToolUse', props: { tool: 'Read' } }, async ($, e, next) => {
355 const shown = (await read($, reads))[e.props.tool_use_id]
356
357 if (e.surface !== 'terminal' || shown === undefined) {
358 return next(e)
359 }
360
361 const elements = $.ui.resolve(e)
362
363 return (
364 <elements.Box flexDirection="column">
365 {await next(e)}
366 {await picture($, elements, shown, (e.viewport?.columns ?? 80) - 6, e.requestId, look)}
367 </elements.Box>
368 )
369 })
370
371 // A folded group draws one count line and no rows, so its image Reads are drawn under that line.
372 on('ui.render', { component: 'ToolGroup' }, async ($, e, next) => {
373 const all = await read($, reads)
374 const shown = e.props.calls.flatMap(call => (call.tool_use_id === undefined ? [] : (all[call.tool_use_id] ?? [])))
375
376 if (e.surface !== 'terminal' || e.props.isExpanded || shown.length === 0) {
377 return next(e)
378 }
379
380 const elements = $.ui.resolve(e)
381 const available = (e.viewport?.columns ?? 80) - 6
382 const pictures = await Promise.all(shown.map((one, index) => picture($, elements, one, available, `${e.requestId}-${index}`, look)))
383
384 return (
385 <elements.Box flexDirection="column">
386 {await next(e)}
387 {pictures}
388 </elements.Box>
389 )
390 })
391 }
392
393 if (options.showPastedImages === false) {
394 return
395 }
396
397 // The prompt row holds the pasted image's bytes; the note row right after it names the file.
398 let pastedRow: string | undefined
399
400 on('session.append', { door: 'prompt' }, ($, e, next) => {
401 pastedRow = e.message.content.some(block => block.type === 'image') ? e.uuid : undefined
402
403 return next(e)
404 })
405
406 on('session.append', { door: 'note' }, async ($, e, next) => {
407 const appended = await next(e)
408 const files = e.message.content.flatMap(block =>
409 block.type === 'text' ? [...String(block.text).matchAll(/\[Image: source: ([^\]]+)\]/g)].map(match => match[1] ?? '') : [],
410 )
411 const row = pastedRow
412
413 if (row === undefined || files.length === 0) {
414 return appended
415 }
416
417 pastedRow = undefined
418 const using = await (converter ??= findConverter($)).catch(() => undefined)
419
420 if (using !== undefined) {
421 const shown = await Promise.all(files.map(file => describe($, using, file, PASTED_COLUMNS).catch(() => undefined)))
422 await update($, pasted, all => ({ ...all, [rowKey(row)]: shown.filter(one => one !== undefined) })).catch(() => undefined)
423 }
424
425 return appended
426 })
427
428 on('ui.render', { component: 'UserMessage' }, async ($, e, next) => {
429 const shown = (await read($, pasted))[rowKey(e.requestId)]
430
431 if (e.surface !== 'terminal' || shown === undefined) {
432 return next(e)
433 }
434
435 const elements = $.ui.resolve(e)
436 const available = (e.viewport?.columns ?? 80) - 6
437 const pictures = await Promise.all(shown.map((one, index) => picture($, elements, one, available, `${e.requestId}-${index}`, look)))
438
439 return (
440 <elements.Box flexDirection="column">
441 {await next(e)}
442 {pictures}
443 </elements.Box>
444 )
445 })
446}
447types/index.d.ts 8 lines1export type Shown = { file: string; width: number; height: number; columns: number }
2
3declare module 'claude-code' {
4 interface PluginState {
5 'inline-images': { pasted: Record<string, Shown[]>; reads: Record<string, Shown>; collapsed: Record<string, boolean> }
6 }
7}
8