Thumbnails of the images you paste, above the prompt; click the magnifier to enlarge one in a pane.

A mod (function hooks that run inside Claude Code) that shows the images you paste while they are still in the prompt box.
Ctrl+V): a thumbnail of it appears above the prompt, one per [Image #N] in the box.🔍 #N button under a thumbnail: the picture opens enlarged in a pane, with its pixel size.🙈 Hide preview (end of the button row): the thumbnails fold away, leaving a 👁 Show preview (N) button to bring them back. The choice lasts for the session.The thumbnail itself is not clickable (an Image element takes no onPress), hence the button under it.
sips, and the clipboard fallback uses osascript./plugin install image-peek --marketplace shdennlin/agent-plugins
<tmp>/claude-<uid>/<project>/<session>/images/N.png as soon as it is pasted. The mod reads the file from there, the terminal decodes it (Image with a file source), nothing is copied.prompt.edit, so the mod looks at the box every 300 ms with $.prompt.read() and follows the [Image #N] tags.$DARWIN_USER_TEMP_DIR/image-peek/<session>/N.png (macOS's per-user temp folder; each folder is created mode 700 and checked to be a real directory of yours before anything is written) and shows that.await next(e)), so it sits beside other mods' bands such as cut-input instead of replacing them.claude plugin validate plugins/image-peek
claude plugin test plugins/image-peek
claude --plugin-dir ./plugins/image-peek # lays .claude-plugin/types/ for tsc -p plugins/image-peek
/private/tmp, sips, osascript).hooks/register.tsx 252 lines1import { atom, read, update } from 'claude-code'
2import type { Engine, Register } from 'claude-code'
3
4const PANE = 'image-peek'
5const THUMB_COLS = 16
6const THUMB_ROWS = 6
7const RETRIES = 12
8
9const tags = atom({ plugin: 'image-peek', key: 'tags' } as const, [])
10const selected = atom({ plugin: 'image-peek', key: 'selected' } as const, null)
11const isHidden = atom({ plugin: 'image-peek', key: 'isHidden' } as const, false)
12
13let imagesDir: string | null = null
14let cacheBase: string | null = null
15const sizes = new Map<string, { w: number; h: number }>()
16const snapped = new Set<number>()
17const missingFor = new Map<number, number>() // polls a tag has gone without its file
18let retries = 0
19let isWaiting = false
20
21// The folder Claude Code stores pasted images in: <tmp>/claude-<uid>/<project>/<session>/images
22async function dirOf($: Engine): Promise<string | null> {
23 if (imagesDir !== null) return imagesDir
24 const uid = (await $.process.run(['id', '-u'])).stdout.trim()
25 const session = await $.session.id()
26 const root = `/private/tmp/claude-${uid}`
27 for (const project of await $.fs.list(root)) {
28 const dir = `${root}/${project.name}/${session}/images`
29 if (await $.fs.exists(dir)) {
30 imagesDir = dir
31 return dir
32 }
33 }
34 return null
35}
36
37// The copy lives under macOS's per-user temp folder (mode 700), never the shared /tmp, so no
38// other user can plant a link at the path or read the picture.
39async function cacheRoot($: Engine): Promise<string> {
40 if (cacheBase === null) {
41 const base = (await $.process.run(['getconf', 'DARWIN_USER_TEMP_DIR'])).stdout.trim().replace(/\/$/, '')
42 cacheBase = `${base}/image-peek`
43 }
44 return cacheBase
45}
46
47async function cacheOf($: Engine, n: number): Promise<string> {
48 const session = await $.session.id()
49 return `${await cacheRoot($)}/${session}/${n}.png`
50}
51
52// Make `dir` ourselves (no -p) and use it only if it is a real directory, ours, mode 700; stat
53// does not follow a link, so a planted link shows as something else and is refused.
54async function isPrivateDir($: Engine, dir: string): Promise<boolean> {
55 const uid = (await $.process.run(['id', '-u'])).stdout.trim()
56 await $.process.run(['mkdir', '-m', '700', dir])
57 const seen = (await $.process.run(['stat', '-f', '%u %Lp %HT', dir])).stdout.trim()
58 return seen === `${uid} 700 Directory`
59}
60
61async function fileOf($: Engine, n: number): Promise<string | null> {
62 const dir = await dirOf($)
63 if (dir !== null && (await $.fs.exists(`${dir}/${n}.png`))) return `${dir}/${n}.png`
64 const cached = await cacheOf($, n)
65 return (await $.fs.exists(cached)) ? cached : null
66}
67
68// Fallback for a paste whose file Claude Code has not written: copy the clipboard's PNG.
69async function snapshot($: Engine, n: number) {
70 const file = await cacheOf($, n)
71 const session = file.slice(0, file.lastIndexOf('/'))
72 if (!(await isPrivateDir($, await cacheRoot($))) || !(await isPrivateDir($, session))) return
73 await $.process.run([
74 'osascript',
75 '-e', 'set d to (the clipboard as «class PNGf»)',
76 '-e', `set f to open for access POSIX file "${file}" with write permission`,
77 '-e', 'set eof f to 0',
78 '-e', 'write d to f',
79 '-e', 'close access f',
80 ])
81}
82
83async function sizeOf($: Engine, file: string) {
84 const known = sizes.get(file)
85 if (known) return known
86 const out = (await $.process.run(['sips', '-g', 'pixelWidth', '-g', 'pixelHeight', file])).stdout
87 const w = Number(/pixelWidth: (\d+)/.exec(out)?.[1] ?? 0)
88 const h = Number(/pixelHeight: (\d+)/.exec(out)?.[1] ?? 0)
89 const size = w > 0 && h > 0 ? { w, h } : { w: 4, h: 3 }
90 sizes.set(file, size)
91 return size
92}
93
94// Fit a picture into maxCols x maxRows cells, keeping its aspect (a cell is about 1:2).
95function fit(size: { w: number; h: number }, maxCols: number, maxRows: number) {
96 const ratio = size.w / size.h / 0.5
97 let columns = maxCols
98 let rows = Math.round(columns / ratio)
99 if (rows > maxRows) {
100 rows = maxRows
101 columns = Math.round(rows * ratio)
102 }
103 return { columns: Math.max(1, Math.min(255, columns)), rows: Math.max(1, Math.min(255, rows)) }
104}
105
106const sameTags = (a: number[], b: number[]) => a.length === b.length && a.every((n, i) => n === b[i])
107
108// Look at the box on a timer (a paste raises no prompt.edit). The band is redrawn only when the
109// tags change, never on a plain edit.
110async function syncTags($: Engine) {
111 const { text } = await $.prompt.read()
112 const found = [...text.matchAll(/\[Image #(\d+)\]/g)].map(m => Number(m[1]))
113 const old = await read($, tags)
114
115 for (const n of found) {
116 if (snapped.has(n)) continue
117 if ((await fileOf($, n)) !== null) {
118 missingFor.delete(n)
119 continue
120 }
121 const polls = (missingFor.get(n) ?? 0) + 1
122 missingFor.set(n, polls)
123 if (polls >= 4) {
124 snapped.add(n)
125 await snapshot($, n)
126 }
127 }
128
129 if (!sameTags(old, found)) {
130 await update($, tags, () => found)
131 }
132
133 // A file that was missing at the last draw: redraw once it is there.
134 if (isWaiting && retries < RETRIES) {
135 retries += 1
136 const files = await Promise.all(found.map(n => fileOf($, n)))
137 if (files.every(f => f !== null)) {
138 isWaiting = false
139 $.ui.invalidate('ui.render')
140 }
141 }
142}
143
144export const register: Register = on => {
145 on('session.start', async ($, e, next) => {
146 $.clock.every(300, () => {
147 void syncTags($)
148 })
149
150 return next(e)
151 })
152
153 on('prompt.submit', async ($, e, next) => {
154 update($, tags, () => []).catch(() => {})
155 update($, selected, () => null).catch(() => {})
156 $.ui.close({ id: PANE }).catch(() => {})
157 retries = 0
158
159 return next(e)
160 })
161
162 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
163 const list = await read($, tags)
164 if (e.surface !== 'terminal' || e.props.hasSurvey || list.length === 0) {
165 return next(e)
166 }
167
168 const { Box, Text, Image, Button } = $.ui.resolve(e)
169 const below = await next(e)
170 const toggle = async () => {
171 await update($, isHidden, hidden => !hidden)
172 }
173
174 // Hidden: one small button keeps the way back; no thumbnails, no file lookups.
175 if (await read($, isHidden)) {
176 isWaiting = false
177 return (
178 <Box flexDirection="column">
179 {below}
180 <Box flexDirection="row">
181 <Button key="show" label={`👁 Show preview (${list.length})`} onPress={toggle} />
182 </Box>
183 </Box>
184 )
185 }
186
187 const items = await Promise.all(
188 list.map(async n => {
189 const file = await fileOf($, n)
190 return { n, file, size: file ? await sizeOf($, file) : null }
191 }),
192 )
193 isWaiting = items.some(i => i.file === null)
194
195 const room = Math.max(2, Math.min(THUMB_ROWS, e.props.maxRows - 5))
196 const cols = Math.max(6, Math.min(THUMB_COLS, Math.floor(e.props.bodyColumns / items.length) - 4))
197
198 return (
199 <Box flexDirection="column">
200 {below}
201 <Box flexDirection="row">
202 {items.map(({ n, file, size }) => (
203 <Box flexDirection="column" alignItems="center" borderStyle="round" borderDimColor>
204 {file && size ? (
205 <Image key={`img-${n}`} source={{ file, format: 'png' }} {...fit(size, cols, room)} alt={`Image #${n}`} />
206 ) : (
207 <Text dimColor>loading…</Text>
208 )}
209 <Text dimColor>#{n}</Text>
210 </Box>
211 ))}
212 </Box>
213 <Box flexDirection="row">
214 {items.map(({ n }) => (
215 <Button
216 key={`open-${n}`}
217 label={`🔍 #${n}`}
218 onPress={async () => {
219 await update($, selected, () => n)
220 await $.ui.open({ id: PANE, title: `Image #${n}`, focus: true })
221 }}
222 />
223 ))}
224 <Button key="hide" label="🙈 Hide preview" onPress={toggle} />
225 </Box>
226 </Box>
227 )
228 })
229
230 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
231 const n = await read($, selected)
232 const { Box, Text, Image } = $.ui.resolve(e)
233 const file = n === null ? null : await fileOf($, n)
234
235 if (n === null || file === null) {
236 return <Text dimColor>No image.</Text>
237 }
238
239 const size = await sizeOf($, file)
240 const box = fit(size, Math.max(8, (e.viewport?.columns ?? 80) - 6), Math.max(4, (e.viewport?.rows ?? 24) - 6))
241
242 return (
243 <Box flexDirection="column">
244 <Image key={`big-${n}`} source={{ file, format: 'png' }} {...box} alt={`Image #${n}`} />
245 <Text dimColor>
246 #{n} · {size.w}×{size.h}px
247 </Text>
248 </Box>
249 )
250 })
251}
252types/index.d.ts 8 lines1export type PeekTag = number
2
3declare module 'claude-code' {
4 interface PluginState {
5 'image-peek': { tags: PeekTag[]; selected: PeekTag | null; isHidden: boolean }
6 }
7}
8