A Claude Code slash command that renders your last response as a beautiful document.
Shows assistant text, file changes, tool calls, and bash output — with one-click copy buttons.
Install · Usage · What gets rendered · Formats · CLI
Claude Code outputs raw text in the terminal. That's fine for quick answers, but falls apart when Claude just:
- Edited 5 files and explained the changes
- Ran several commands and showed their output
- Wrote a detailed architecture explanation with code examples
/preview opens all of that as a beautiful, readable document — same design language as a professional PDF report.
You: Refactor the auth module to use JWT
Claude: [edits 4 files, runs tests, explains what changed]
You: /preview
→ browser opens with full response: text + diffs + bash output + copy buttons
You: /preview pdf
→ PDF saved and opened automatically
curl -fsSL https://raw.githubusercontent.com/ranahaani/preview/main/install.sh | bashThis installs the preview CLI and the /preview slash command for Claude Code.
Manual install
# 1. Install the CLI
pip install git+https://github.com/ranahaani/preview.git
# 2. Add the slash command
mkdir -p ~/.claude/commands
curl -o ~/.claude/commands/preview.md \
https://raw.githubusercontent.com/ranahaani/preview/main/commands/preview.md
# 3. Restart Claude CodeSystem dependencies for PDF (WeasyPrint)
PDF export uses WeasyPrint, which needs system libraries:
| OS | Command |
|---|---|
| macOS | brew install pango libffi |
| Ubuntu/Debian | sudo apt install libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev |
| Fedora/RHEL | sudo dnf install pango gdk-pixbuf2 libffi-devel |
| Windows | pip install weasyprint (bundles GTK on recent versions) |
Verify:
preview --check
# all dependencies installedInside any Claude Code session:
| Command | What it does |
|---|---|
/preview |
Open last response in browser |
/preview pdf |
Export as PDF |
/preview docx |
Export as Word document |
/preview html |
Save as standalone HTML |
/preview md |
Save raw Markdown |
/preview 3 |
Last 3 responses in browser |
/preview 3 pdf |
Last 3 responses as PDF |
Reads directly from Claude Code's session files — no copy-paste needed.
Each response is rendered as a complete document:
Markdown rendered with Georgia serif body, blue headings, Monokai dark code blocks.
Every tool call is shown as a collapsible block:
| Tool | What's shown |
|---|---|
| Edit | File path + red/green diff of what changed |
| Write | File path + file content |
| Bash | Command (with copy button) + output |
| Read | File path |
| Glob / Grep | Pattern used |
Every code block and every bash command has a Copy button in the top-right corner.
| Browser | DOCX | HTML | ||
|---|---|---|---|---|
| Headings | ✓ | ✓ | ✓ | ✓ |
| Bold / Italic / Code | ✓ | ✓ | ✓ | ✓ |
| Fenced code blocks | ✓ | ✓ | ✓ | ✓ |
| Syntax highlighting (Monokai) | ✓ | ✓ | — | ✓ |
| Copy buttons | ✓ | — | — | ✓ |
| File diffs | ✓ | — | — | ✓ |
| Bash output | ✓ | — | — | ✓ |
| Tables | ✓ | ✓ | — | ✓ |
| Blockquotes | ✓ | ✓ | ✓ | ✓ |
| Page numbers | — | ✓ | — | — |
PDF renders the assistant text only (tool blocks are not print-friendly).
Works with any Markdown file, independent of Claude Code:
preview README.md # browser
preview README.md -f pdf # PDF
preview README.md -f docx # DOCX
preview README.md -f html # HTML
preview notes.md -f pdf -o ~/Desktop/notes.pdf # custom pathClaude Code session (JSONL files in ~/.claude/projects/)
│
▼
preview --session (or /preview slash command)
│
├── Reads latest session JSONL
├── Groups entries into turns
│ (tool results don't break turns — one real user msg = one turn)
├── Finds last substantive turn (has tool use + text)
├── Extracts text blocks + tool calls + results
│
▼
Rich HTML renderer
│
├── Markdown text → Georgia serif, blue headings
├── Edit events → red/green diff blocks
├── Bash events → dark command + output panels
├── Copy buttons injected on all code/command blocks
│
▼
preview / pdf / docx / html / md
pip uninstall preview
rm ~/.claude/commands/preview.mdMIT — use it however you want.
