ModsCode / Claude Code Mods / Ranking / file-preview
file-preview
Click a markdown, JSON or YAML file link in a reply to preview it in a side pane, drawn like a docs page
What it does
- Draws a pane, toasts
- Adds /preview
- Hooks session.start, ui.close, ui.focus, ui.input and 2 more
- Starts processes
Good points
- No network calls
- Written in TypeScript
- Handles errors
- Writes no files
Code to start from
A starter ModsCode writes from the drawing it read, and the mod's own lines that draw, where there are any.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like file-preview by Artūras Bončkus (pane, toast), as ModsCode read it from the mod's code:
// https://modscode.com/claude-mods/mods/abonckus-file-preview/
// Written by ModsCode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
// the pane: open it with $.ui.open({ id: 'my-pane', title: "‹pop›" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Input, Button } = $.ui.resolve(e)
const crumbs = '…'
const name = '…'
const stats = '…'
const query = '…'
const text = '…'
return (
<Box flexDirection="column" paddingX={2}>
<Box flexDirection="row" flexWrap="wrap">
<Text dimColor wrap="truncate-start">
{`${crumbs} / `}
</Text>
<Text bold color="cyan">
{name}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{stats}
</Text>
<Text dimColor>
────────
</Text>
<Box flexDirection="column" rowGap={1} marginTop={1} />
<Box position="absolute" left={2} flexDirection="column">
<Box position="absolute" top={0} left={0} flexDirection="column">
<Text>
{" "}
</Text>
</Box>
<Text dimColor>
────────
</Text>
<Box flexDirection="column">
<Box flexDirection="row">
<Box flexGrow={1}>
<Input autoFocus placeholder="Fuzzy search…" value={`${query}`} />
</Box>
</Box>
<Text dimColor wrap="truncate-end">
8+ matches; Enter jumps to the first
</Text>
<Button plain label={`${text}`} />
<Button plain label={`${text}`} />
<Button plain label={`${text}`} />
</Box>
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" columnGap={1}>
<Button label="↑ Top" hotkey="u" />
<Button label="⌕ Search" hotkey="s" />
<Button label="✕ Close" />
<Button label="↻ Refresh" hotkey="r" />
</Box>
<Text dimColor wrap="truncate-start">
Esc closes search
</Text>
</Box>
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const pop = '…'
await $.ui.toast(`${pop} changed on disk; preview reloaded`)
await $.ui.toast(`Preview refreshed`)
return next(e)
})
}
The mod's own code
Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.
hooks/register.tsx lines 219–378 · Pane
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const els = $.ui.resolve(e)
const { Box, Text, Markdown, Code, Button } = els
const Input = 'Input' in els ? els.Input : null // mobile draws no fields: no search there
const { path, text } = await read($, doc)
const { block: marked } = await read($, mark)
await read($, view) // subscribes: a scroll's tick redraws the footer
const cols = e.props.bodyColumns
const width = Math.min(Math.max(20, cols - 2 * PAD), READ_MAX)
const frame = { borderStyle: 'round', borderDimColor: true, paddingX: 1, flexDirection: 'column' } as const
const table = (t: Table) => {
const widths = fit(t, width)
if (!widths) {
// Too many columns for the pane: one card per row, `header: value` lines.
return t.rows.map(row => (
<Box {...frame}>
{t.head.map((name, j) => (
<Box flexDirection="row">
<Box flexShrink={0}>
<Text bold color="cyan">{`${name}: `}</Text>
</Box>
<Text wrap="wrap">{row[j] ?? ''}</Text>
</Box>
))}
</Box>
))
}
const line = (cells: string[], isHead: boolean) => (
<Box flexDirection="row" columnGap={GAP}>
{cells.map((c, j) => (
<Box width={widths[j]} flexShrink={0} justifyContent={JUSTIFY[t.align[j] ?? 'left']}>
<Text wrap="wrap" bold={isHead} color={isHead ? 'cyan' : undefined}>{c}</Text>
</Box>
))}
</Box>
)
const rule = '─'.repeat(widths.reduce((a, b) => a + b, 0) + GAP * (widths.length - 1))
return (
<Box {...frame}>
{line(t.head, true)}
<Text dimColor>{rule}</Text>
{t.rows.flatMap((r, i) => (i === 0 ? [line(r, false)] : [<Text dimColor>{rule.replaceAll('─', '┈')}</Text>, line(r, false)]))}
</Box>
)
}
const mermaid = async (code: string) => {
const drawn = await renderMermaid($, code, width - 4)
if ('error' in drawn) {
return (
<Box flexDirection="column">
<Markdown text={`\`\`\`mermaid\n${code}\n\`\`\``} />
<Text dimColor wrap="wrap">{`mermaid-ascii could not draw this (${drawn.error}); showing the source.`}</Text>
</Box>
)
}
const art = drawn.art
const type = code.trim().split(/\s/)[0] ?? 'diagram'
return (
<Box {...frame} borderColor="magenta">
<Text color="magenta" bold>{`◆ ${type}`}</Text>
{art.split('\n').map(l => (
<Text wrap="truncate-end">{l || ' '}</Text>
))}
</Box>
)
}
// Claude Code's own highlighter: every language it knows, nothing to install.
// A highlighter from the `highlighters` setting for this language, else Claude
// Code's own: every language it knows, nothing to install.
const code = async (lang: string, source: string) => {
const src = clean(source)
const cmd = highlighters.get(lang.toLowerCase())
const spans = cmd && src.length <= MAX ? await external($, cmd, src) : null
const rows = spans
? lines(spans).map(segs => (
<Text wrap="wrap">
{segs.length ? segs.map(s => (s.color || s.italic ? <Text color={s.color} italic={s.italic}>{s.text}</Text> : s.text)) : ' '}
</Text>
))
: null
return (
<Box {...frame}>
{lang ? <Text dimColor>{lang}</Text> : null}
{rows && JSON.stringify(rows).length <= CODE_BUDGET
? rows
: chunk(src, MAX, MAX * 3).map(p => <Code source={p.source || ' '} language={lang || undefined} />)}
</Box>
)
}
// GitHub style: h1/h2 bold with a quiet rule beneath, h3 bold alone.
const heading = (level: 1 | 2 | 3, title: string) =>
level === 3 ? (
<Text bold>{title}</Text>
) : (
<Box flexDirection="column" marginTop={level === 2 ? 1 : 0}>
<Text bold color={level === 1 ? 'whiteBright' : undefined}>{title}</Text>
<Text dimColor>{'─'.repeat(Math.max(1, width))}</Text>
</Box>
)
const callout = (type: Callout, body: string) => {
const { color, icon, label } = CALLOUTS[type]
return (
<Box borderStyle="round" borderColor={color} paddingX={1} flexDirection="column">
<Text bold color={color}>{`${icon} ${label}`}</Text>
<Markdown text={body.slice(0, MAX) || ' '} />
</Box>
)
}
// A markdown file: the docs page.
const page = async () => {
const md = text.length > MD_MAX ? `${text.slice(0, MD_MAX)}\n\n_…truncated_` : text
const all = blocks(md || '_Nothing to preview._')
const parts = await Promise.all(
all.map(b =>
b.kind === 'md'
? <Markdown text={b.text.slice(0, MAX)} />
: b.kind === 'heading'
? heading(b.level, b.text)
: b.kind === 'callout'
? callout(b.type, b.text)
: b.kind === 'table'
? table(b.table)
: b.kind === 'code'
? code(b.lang, b.code)
: mermaid(b.code),
),
)
const words = text.split(/\s+/).filter(Boolean).length
const count = (kind: Block['kind']) => all.filter(b => b.kind === kind).length
const stats = [
`${text.split('\n').length} lines`,
`${words} words`,
`~${Math.max(1, Math.round(words / 220))} min read`,
count('table') && `${count('table')} tables`,
count('mermaid') && `${count('mermaid')} diagrams`,
]
const entries = all.flatMap((b, i) => blockLines(b).map(line => ({ block: i, text: line })))
const body = parts.map((p, i) => (
<Box key={`b:${i}`} flexDirection="column" backgroundColor={marked === i ? MARK_BG : undefined}>
{p}
</Box>
))
return { stats, body, entries }
}
// A JSON or YAML file: the whole source, highlighted and numbered, cut where the
// drawing would pass the engine's tree bounds.
const dataFile = async (kind: 'json' | 'yaml', lang: string) => {
const src = clean(text).replace(/\n$/, '')
const total = src.split('\n').length
const parts = chunk(src, MAX, DATA_BUDGET)
const last = parts.at(-1)
const shown = last ? last.startLine - 1 + last.source.split('\n').length : 0
const body = [Licence text (MIT)
MIT License Copyright (c) 2026 Artūras Bončkus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
How to build this: Pane (panel), Add a slash command
What its code calls
runs programsreads filesenv vars
What its code shows
Read from the source at commit da53af867a4d. The first group decides whether a mod is listed; the rest is for you to weigh. A later commit is not read until the next crawl.
| Decides the listing: code you can check | |
|---|---|
| Entry read | Every module hooks/hooks.json names was read.hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.5 files parsed |
| All its code is in the mod | Every import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod |
| Readable | No minified lines, no eval or new Function, no import of a computed path, no encoded blobs.no minified code, no eval, no encoded blobs |
| Calls in the open | Network and programs are reached as $.http.fetch and $.process.run in place, never passed around.every call outside goes through $ in the open |
| For you to weigh before installing | |
| Where it draws | The terminal, the desktop app, both, or nothing (hooks only: a guard or a prompt rewriter), as its code says. Shown, never a reason to leave a mod out.draws in the terminal and the desktop app, the same in both |
| Install line | Whether its repository's own .claude-plugin/marketplace.json lists it, so it installs from that marketplace with the lines on its page.listed in its repository's .claude-plugin/marketplace.json: installs from there |
| Programs on Windows | Whether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks |
| Network | Whether every fetch names its https host in the code.no network |
| Programs | Whether every program it starts is named in the code and is not a shell, an interpreter or a network tool.hooks/register.tsx:102 a program named at run time |
| Reads and sends | Whether it both reads something of yours (files, environment variables, the transcript, settings) and reaches outside (the network, an MCP server, another session, telemetry).reads environment variables, files, but reaches nothing outside |
| Keys in the source | Whether the source holds what looks like an API key or a private key.no keys in the source |
| Licence | An open licence (MIT, Apache-2.0, BSD, ISC, Unlicense, 0BSD, CC0) with its text lets ModsCode show its code; otherwise the code is linked.MIT |
| Settings hooks | Hooks declared in hooks/hooks.json or plugin.json beside the module: a command (a shell when it has no args), an HTTP request, an MCP tool or a model prompt at an event. They run outside $.no settings hooks: its function hooks alone |
| Servers it ships | MCP servers (a program, or a URL; a headersHelper is a shell command; a .mcpb bundle is unpacked at run time), LSP servers, monitors (a shell command for the whole session) and bin/ (on the PATH of the Bash tool).ships no MCP or LSP server, no monitor, no bin/ |
| Skills, commands, agents | What its Markdown declares beyond text: allowed-tools granted for the turn, hooks added when a skill is invoked, a command run before Claude reads the skill.no skills, commands, agents or workflows |
| Tools and MCP | Whether every tool it calls through $.tool.call and $.mcp.call is named in the code, and none is a shell (Bash through the tool runs a shell without $.process).calls no tool, MCP server or command |
| Asks of the model | Completions it runs ($.model.complete, fork, classify), subagents it spawns, prompts it submits as you, and the tools, commands and agents it adds.adds command preview |
| Events it hooks | By what a hook there can do: gates (refuse a tool call, a prompt, a setting, another plugin), shapes (what the model reads: the system prompt, tool descriptions, each request), reads (your input, the events of the settings hooks, every event with *), and the rest.gates: command.run (preview) · reads: ui.press, ui.input · also: session.start, ui.scroll, ui.focus, ui.close (+1) · timers: clock.every, clock.after |
| Reads, by name | The environment variables and files it names, and whether it reads the transcript, settings.json, the prompt box or the mouse selection.env: HOME, USERPROFILE; files: a path computed at run time |
| Writes, by name | The files and environment variables it names, and whether it changes settings, the prompt box, the clipboard, the conversation (a row the model reads) or another session.writes no files, environment variables, settings or conversation rows |
This is a reading of the code text, not a security review: it does not run the mod, and it cannot see what a program the mod starts does. The check before installing is yours. How mods are chosen
Install it
Check it yourself before you install it. Mods run unsandboxed, with your permissions, and ModsCode does not vouch for what this code does. Read its code (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
From its marketplace
Its repository is its marketplace. Add that marketplace (in the terminal with these commands, or in the desktop app's plugin settings) and install the mod from it:
/plugin marketplace add abonckus/claude-code-file-preview/plugin install file-preview@file-preview/reload-pluginsThis installs the marketplace's latest commit, which may not be the one read here (da53af867a4d). Compare them before you install. /reload-plugins loads it into a session that is already open.
Try the commit ModsCode read
No marketplace needed. In a terminal, clone the repository, check out the commit read, validate the mod, and load it for one session:
git clone https://github.com/abonckus/claude-code-file-previewgit -C claude-code-file-preview checkout da53af867a4dc4b7149d471613eae883af89864aclaude plugin validate claude-code-file-previewclaude --plugin-dir claude-code-file-previewThe validate line lists the events the mod hooks and what it asks Claude Code to do, without running it. The last line loads the mod for this session only and writes nothing to your settings. If the author has rewritten history, the commit may no longer exist.
Ask Claude about it
With the ModsCode connector added, Claude can read this mod's code and what it reaches, and build on them. Ask it like this:
Read the ModsCode mod "abonckus-file-preview" with its code and make me one like itSearch them from Claude: the MCP connector
Similar mods
- code-modernizationAnthropic★ 37,653
- lcu-approveLCU★ 894
- ai-maestro-secrets23blocks-OS★ 817
- filetreeKurt Buhler★ 131
- great-ctoAlexander Velikiy★ 103
- hopeSaad Shahd★ 35
More by Artūras Bončkus
Badge for your README
If this is your mod, paste this into your README. It links to this page.
[](https://modscode.com/claude-mods/mods/abonckus-file-preview/)