Chat attachments
One text marker carries every file in a message:
[attachment: notes.txt (txt, 18 KB, 4210 lines) @json "/abs/path/notes.txt"]
Written only by format_marker in openprogram/state/attachments.py; a fifth source calls it too. Read on the web only by parseAttachments. An optional @previewjson names a saved preview. The older @ /abs/path spelling stays readable. How content enters model context: Attachment handling.
Inbound
| Source | Bytes | Model input | Chat |
|---|---|---|---|
| Web image: paste, drag, picker | Session workdir attachments/, SHA-256 dedup in the session, 32 MB per file, 64 MB per turn | Image content and path | Thumbnail chip, click for full size |
| Web document: PDF, code, binary | Same store; local files can stay at their path | Path; tools read on demand | Clickable chip, overlay viewer |
@mention, entered path | Unchanged location, zero copy | Path | Clickable chip |
| Telegram, Discord, Slack, WeChat | <state>/channels/<channel>/accounts/<account>/attachments/, 20 MB, no dedup | Images up to 4 MB as image content, others as path | Thumbnail chip, marker hidden |
Channel text is prefixed with [display name (id)] and markers follow. _one_line removes brackets from the name so a prefix cannot be forged. Unnamed pasted images get an extension from their media type.
In a message
| Where | How |
|---|---|
| User messages, message rail | AttachmentChips; AttachmentPreview opens an overlay around FileViewer's absolute-path mode, so the reading position stays |
| Assistant replies | AssistantFileCards, same markers; opens in a center file tab |
| Just sent | chat_ack echoes the stored text, so a new attachment is clickable at once |
Reply file cards
| File attached to a reply | Preview |
|---|---|
| Image, video, audio | Shown or played in place |
| First page, cut to a 16:9 frame | |
| Word, PowerPoint, Excel | First page as the worker draws it (/api/file-thumbnail): macOS Quick Look, else the picture the authoring app saved in the file; cut to a 16:9 frame. Neither: name row only. The in-app editor is an optional 730 MB install, too heavy to boot per card |
| HTML | Drawn at 1280 × 720, scaled into a 16:9 frame |
| zip, tar | First level, with a file count per folder |
| Text | Opening lines |
Every card with a preview is a third of the text column (240–440 px), three to a row: enough to tell files apart, and the full view is one click away. A card with no preview is a name row on its own line.
A card is drawn only for an attachment the server put on the message: a send_file file or a file the turn produced. The browser derives no card of its own.
When the turn's final text is assembled (with_attachments), a marker the model typed for a file the turn did not record becomes the file's name, in the content and the text blocks: no card, path or automatic preview, live or after a reload. Upload and mention markers in the person's message stay.
- A marker stays only when its path and any
@previewjsonpath were both recorded. - The text a reply stores while streaming, kept by a reply a restart cut off, and an always-on report get the same treatment.
parseAttachmentsreads only the forms the server checks.
A script the reply links ([build.py](/abs/build.py)) or a file the agent only read stays a link in the prose (Paths in a reply).
When a reply finishes in the focused chat, its first attachment not already shown in the reply opens in the preview beside it: the deliverable the turn just made.
Below the preview: file-type icon, name, type and size (plus page or file count), then Open and Reveal in Finder (File Explorer, File Manager by platform). A file the app cannot show puts Download in the open slot; when the worker is not on the user's machine, the reveal slot downloads. Previews load as the card nears the screen.
HTML sandbox and archives
GET /api/file-pageserves only .html and .htm, withsandbox allow-scriptsand noallow-same-origin. Asrcdocframe would inherit the app'sscript-src 'self'and a script-drawn page would be blank.- The page has an opaque origin: no access to the app or its storage, its
Origin: nullrequests are refused, it cannot navigate or open windows. Relative files are missing from the strip because the strict cookie is not sent; the page opened in a browser tab has them. FileViewersends a zip or tar toArchivePreview: full tree on the left, the selected member on the right through the sameFileViewer. Nothing is extracted to disk.
Paths in a reply
A file the reply only names, as `exports/plan.pptx` or [plan](/Users/me/exports/plan.pptx:3), is a link to that file. A click opens it in the preview beside the chat: an office file in the document editor, a PDF in the PDF viewer, a web page as a page.
| Step | Rule |
|---|---|
| Candidates | Inline code spans and markdown link targets of a settled reply (never code blocks, never while it streams). A path-shaped string: a folder separator or a name with an extension, absolute, ~ or relative; a :12 or #L12 suffix is dropped. Commands, web addresses and links to the app's own pages (/s/…, /settings) are not candidates |
| Confirmed by the worker | GET /api/file-paths answers which candidates are files: absolute and ~ paths against readable_roots, relative ones joined to the chat's working directory first. Only confirmed paths become links, so a code span that looks like a name never turns into a dead link |
| Cost | The candidates of every reply on screen go out in one request per chat (64 paths each, stat only), answers are kept five minutes (a missing file twenty seconds, since the agent may still make it). The text is drawn first and never waits |
| Not a route | A markdown link that can only be a local path (/… that is not an app page, ~/, ./, ../, file://, a drive) is stopped before the shell's router, which would take /Users/… for a page. Not confirmed yet, it is looked up on click; a file that is not there says so. A bare target (notes/plan.md, or docs.example.ai, a web address without its scheme) becomes a file link only once confirmed, and until then keeps its own click |
| Spaces in a path | A link to a root, ~/, file:// or drive path with a space in it ([deck](/Users/me/ICDM 2026/deck.pptx)) is still a link, though CommonMark ends a destination at a space and would print it as text. Models write paths this way. Web addresses keep the stock rule (lib/markdown/spaced-path-links.ts) |
| Look | Drawn as the app's rendered-markdown links are (the file preview's): the link colour over a faint underline that turns solid on hover. A code span keeps its chip and takes the colour and the underline, so it is told apart from plain code at rest even where the link colour is close to the code colour. Only decoration changes, so the paragraph keeps its layout when a path becomes a link. Enter opens it |
File menu
A right-click on a path in a reply, on a reply file card or on a row of the turn's changed files opens one menu, from FilePathMenuContent:
| Item | What it does |
|---|---|
| Open preview | The click's action; left out on a card whose file nothing here can show |
| Copy › | Absolute path, Relative path (to the chat's project; disabled outside it), Filename |
| Reveal in Finder | File Explorer or File Manager by platform, through POST /api/file-reveal; only when the worker runs on this machine |
| Open in default app | The desktop app's files:open-default: the system opens the file as a double-click would, so a deck opens in Keynote or PowerPoint. Refuses a folder, an executable and anything the system would run (scripts, apps, installers, shortcuts). Absent in a browser or on another machine |
| Attach as context | Adds an @ mention of the file to the chat's message box |
Right-click elsewhere in a reply keeps the browser's own menu, and a card inside a reply keeps its own. A deleted file in the changed-files card has no menu.
Outbound
send_file(path)resolve symlinks, check allowed roots, report; no delivery- Turn endrecorded
send_filecalls plus the files the turn produced, checked again, as markers onfinal_text - Webfile card under the replyChannel
post_file, marker removedFails: note with the path
| Aspect | Rule |
|---|---|
| Limit | 32 MB per file |
| Approval | None, in any mode. Attaching a file to the turn's own conversation is replying, so send_file is a no-decision tool (SAFE_TOOL) and needs fs.read, not network.send. Model review would judge an attachment a disclosure and refuse it, and after one refusal a model stops attaching for the rest of the chat. A paired chat-app speaker has no fs.read, so the owner's files are not sent to them |
| Files the turn produced | Attached without a send_file call (see below) |
| Where the tool exists | Not in cli, tui or plan (unsafe_in): the model cannot try and fail. Elsewhere it is a resident tool, a function of every request, never one to search for; a tool_search for it answers that it is already callable (Deferred tools) |
| What the prompt says | Call send_file for each deliverable when it is in the tools list, with no search first. Say that a file was not sent only when a send_file call refused it, with its reason, and never conclude it from a tool search. Not "never say it": the tool does refuse (a home file in a platform chat, a file over the limit), and hiding that leaves the user waiting for a file |
| Pause | The record is the source, so a resumed turn keeps its files |
| Refused path | An error to the model that says the path is outside and names this conversation's own folders: its working folder, its project folder and its chat folder. Every other project's chats/ folder is also a root, but only counted ("40 other folders"), so the message stays short however many projects there are |
| Boundary | In-process Python, outside openprogram/host/sandbox/, which governs shell commands. The path check is the whole boundary |
| Why a tool | A MEDIA: line leaks to the user when extraction fails. A tool can report a missing file. Mentioning a path the turn did not modify sends nothing |
| Marker the turn did not attach | Nothing uploads. The channel checks the marker's path against the files the turn attached (its send_file calls and the files it produced), because a marker is text the model can also write. The turn's final text already reads such a marker as the file's name; one in text streamed before that becomes a Chinese note without the path |
post_file not supported or failed | The marker becomes a Chinese note with the path, and failures are logged. Clickable links would need an externally reachable web URL |
Files the turn produced
A model that builds a deck with a script and answers “done, it is at exports/plan.pptx” has attached nothing. At turn end, produced_files attaches such files itself, with the same marker, so the same card appears and a channel uploads them.
| Step | Rule |
|---|---|
| Candidates | Paths the reply names: markdown link targets (also <…> and %20), code spans and bare tokens; absolute, ~, or relative to the project and then the session workdir; a :12 or #L12 suffix is dropped. Plus files write wrote and image_generate saved |
| Kept when | A regular file inside sendable_roots, at most 32 MB, modified at or after the turn started (one second of slack); a resumed turn uses its user message's time. Not a file the user sent in (workdir/attachments/, steer-images/): its mtime falls inside the turn too |
| Formats | Office and other documents, PDF, images, audio, video, archives; and HTML, Markdown, CSV, TSV, SVG and notebooks unless the edit tools changed them, since the edit card already shows those with their diff. The rule is the same for every candidate, whether the reply named it or write or image_generate saved it, so the script that built a deck stays out. Source code and logs never, nor .key, which is also a private key's extension |
| Limits | At most 64 candidates looked at with stat only, at most 8 attached, each once, after the send_file files. Any failure attaches nothing and never reaches the turn |
| Where | Only where send_file exists (not cli or tui) and for a speaker with fs.read |
The modification time is the guard: a file the model only read or mentioned is older than the turn and stays put.
The base guide asks the model to name each file it produced as a markdown link to its absolute path and to attach deliverables with send_file; the send_file description says it is for any file the user should see, office files a script made included.
File access
| Root | Displayreadable_roots | Sendsendable_roots |
|---|---|---|
Conversation folders projects/*/chats | Allowed | Allowed |
| Project bound to the session | Allowed | Allowed |
| OpenProgram checkout | Allowed | Refused |
Channel attachments folders | Allowed | Refused |
| Folder of a chat with no project (the default project's, often home) | Guarded, for that chat | Guarded, while the chat stays in the App |
| Default project folder for any other request | Refused | Refused |
resolve_within resolves symlinks before testing containment, so a link to ~/.ssh fails. Every session is auto-bound to the default project, so only non-default bindings count as a project. Channels are globbed down to the attachments leaf because credentials.json is a sibling.
A chat with no project
Such a chat works in the default project's folder, often the home directory, so a deck it builds lands there. That folder is a root only as a WorkdirRoot, for a conversation that exists and has no real project. A folder that is the filesystem root is never one, or the whole disk would be a root. The rules:
| Surface | Rule |
|---|---|
Preview, path links, file cards, reveal (readable_roots) | Allowed for that chat's own requests. These are local to the owner's App |
send_file and turn-end attach (sendable_roots) | Allowed while the conversation does not deliver to a chat platform. An owner chat bound to one (its meta names a channel), or one that arrived from a platform contact (its meta names a peer_id, kept after unbinding since the contact's next message returns there), keeps the narrow roots: the tool refuses a home file, and the turn-end check refuses it again, so nothing from home is uploaded to WeChat or Telegram |
| Always refused under that folder | Any path through a dot-folder or dot-file (~/.ssh, ~/.aws, ~/.openprogram*, .env); any path through a folder named Library or AppData, where macOS and Windows keep keychains, browser profiles and cookies; key and keystore files (.key, .pem, .p12, .kdbx and similar); names such as id_ed25519, credentials.json, token; and the state directory, whose conversation folders are roots of their own. Uploads and steer images stay out of turn-end attach as before |
| Choice | Why |
|---|---|
| Not a plain root | The folder may be $HOME, and send_file can reach a chat platform |
| Not left out | A chat with no project could neither send, link nor open what it built. Claude Code desktop, Codex, Hermes, MiniMax Code and KimiCode all open files the turn wrote from the reply, wherever the working directory is |
| No per-file journal | Files the turn's tools wrote outside every root are not opened: the working folder covers where they land, and a journal would be a second rule |
| Route | Contract |
|---|---|
GET /files/raw | Project and relative path for the file panel and center tabs. Always refuses absolute paths; keep this invariant |
GET /api/file-raw | Absolute path against readable_roots; nosniff, CSP sandbox, PDF exempted from it for the browser viewer |
GET /api/file-read | Text. A relative path under a root, or an absolute path against readable_roots |
GET /api/archive-list | Entries from the zip central directory or tar headers, at most 5000, flagged when cut |
GET /api/archive-member | One member up to 32 MB with /api/file-raw's headers. The name is only looked up in the archive index, so ../ reaches nothing |
POST /api/file-reveal | Selects the path in the worker's file manager after the same check. Never opens or runs it; opening in the default app is the desktop app's, which checks the file itself (File menu) |
GET /api/file-paths | Many path parameters, at most 64; each mapped to the absolute file it names inside readable_roots or null, without saying whether it was missing, a folder or outside. Relative paths are joined to the chat's working directory. stat only |
| On the event loop | /api/file-paths, /api/file-search and /api/file-resolve find the chat's working directory under its conversation lock, and the search walks folders. That lookup runs in a worker thread in that conversation's lane, so a turn holding the conversation delays only these requests, never the Worker. The search's folder walk runs in a plain worker thread after it, outside the lane, so an @-mention typed while a large folder is walked never queues a Send or Stop of the same chat |
Both archive routes take an absolute path or a project id and relative path. FileViewer has one abs switch, so image, PDF, Markdown, line-numbered code and download-card rendering stay in one implementation.
Deferred
| Item | Why not now | When |
|---|---|---|
| Center tab for user attachments | The overlay covers a quick look; project-keyed tabs would need new handling. Reply cards already use tabs | When someone reads an attachment at length |
send_file caption | The marker has no caption field and reply text already accompanies the file | When a platform needs text attached to the file |
| Outbound tool allowlist | send_file is the only outbound entry and checks roots | When plugins or MCP tools can trigger delivery |
| Short-lived signed tokens | Local listener, same-origin guard, root checks | First addition once the web UI leaves localhost |
| Syntax highlighting | Line-numbered pre is enough; docs-site highlighting is build-time only | When users report a need |
Also absent: multiresolution thumbnails for large images.
Target design
Any file, from any source, opens through the same viewer in every interface. User and agent files differ only in their source field.
| Capability | Solves | Today | Why deferred |
|---|---|---|---|
One attachment record (id, SHA-256, name, MIME, location, count, source, session, message); text holds only [attachment:<id>] | Rename, dedup and cross-session references become queries | A text marker holds everything | Needs a schema change and history migration; wait for cross-session references |
| One parser, every interface, including inline terminal images (iTerm2, kitty; file card elsewhere) | One rendering decision per resource | True on the web. The TUI has no attachment concept and cannot paste images | Independent of the web. Peers show the practical gain is modest |
| Full symmetry | One data model and UI for user and agent files | Grammar, parser, chips and viewer are shared; only fallbacks differ | Partly done; all four platforms upload |
| Output as a live page | Watch a document develop | canvas writes Markdown blocks with ids; no panel renders them | Wire format settled. The most valuable next addition; three peers built it |
Excluded: global content-addressed blob storage. Each session workdir is committed every turn and stays replayable, so large binaries staying in git history is the accepted cost.
Canvas file content
| Call | Result |
|---|---|
set, append with content="" | Empty string is content; the block keeps an empty body and get returns the empty string |
| Content omitted or null | Error, file unchanged |
content with body or text | Explicit content wins, even when empty |
The plain callable and registered tool share this, with the same block format and sandbox path checks.
Eight peers compared
| Repository | Into context | Display | Agent sends files | Viewing, cleanup |
|---|---|---|---|---|
| claude-code (TUI) | Inline base64; bytes in ~/.claude/image-cache/<session>/, 0600. 5 MB, 2000 px, sharp resize, JPEG steps 80/60/40/20. Bridged web and mobile inject paths | [Image #N] with OSC-8 link to the system viewer. Non-images: Read <path> (N lines) | SendUserMessage attachments: string[]; upload returns file_uuid; 30 MB | TUI Markdown and highlighting. PDFs as document blocks or per-page JPEGs. Each session start removes others' caches; 200-entry path LRU |
| codex-cli (TUI) | Base64 input_image in an <image name path> tag. Bytes stay in place. 2048 px, SHA-1 64 MB LRU. Remote URLs rejected | [Image #N], not clickable. Kitty and sixel only for the mascot | No general tool. Image generation prints file:// and claims it was shown | Markdown, syntect. file_opener rewrites references to editor URIs |
| openclaw (web, TUI) | Vision models get base64; others get a media://inbound/<id> receipt. Store 0700. Images 6 MB, audio/video 16 MB, documents 100 MB. EXIF normalised, JPEG re-encoded | Web thumbnails open a new tab; cards; audio player with status badges. TUI labels | MEDIA: line and a message tool. Only allowlisted core tools may send local paths | Markdown-it, DOMPurify. Documents extracted for the model only. Two-minute TTL |
| opencode (web, TUI) | Base64 data URLs in SQLite. @ runs read on submit and injects two synthetic plain-text parts. 5 MB, 2000 px, Lanczos3 | Image cards with a lightbox; non-images not clickable; @ highlighted in text | No; tool attachments go to model context | GET /file/content; images, audio, SVG, tabs, diffs. Deleted with session rows |
| hermes-agent (channels) | Per-turn routing: native base64 plus a path hint, or vision_analyze text. Documents as paths, text inlined. No first limit; compress to 4 MB after rejection | Native on Telegram and Discord; CLI, TUI and xterm web not clickable | Most complete: MEDIA:, send_message, symlink-first root check, per-platform prompts;  extracted | Rich Markdown. 24-hour TTL |
| pi-mono (TUI) | @file inlined with a <file name> marker. Clipboard writes a temp file and inserts its path. 2000 px, 4.5 MB, can be disabled | The only real inline terminal images (Kitty, iTerm2), off under tmux and screen; tool results only, user images not echoed | No | Markdown, diffs; no PDF, no cleanup of temp images |
| pi-ai (protocol) | Read-only copy of the pi-mono package. Image blocks removed when the model declares no image input; tool-result images split into text and a synthetic user message | No | No | No |
| weclaw (WeChat) | Images intercepted, saved, “Saved: filename”; agent cannot see them. Voice uses WeChat's transcript. No limit | WeChat is the client | Implicit: bare absolute-path lines or  uploaded and replaced with “Attachment sent”. Roots default to ~/.weclaw/workspace, extension allowlist | Markdown stripped to plain text |
Four ways to send a file
| Design | Used by | Gains | Costs |
|---|---|---|---|
| Tool parameter | claude-code, OpenProgram | Typed, existence checked at the tool | One tool call; speech and files are separate actions |
| Instruction line | openclaw, hermes | Sent with speech, no extra round trip; per-channel prompt | Bad paths need checks; partial extraction leaks the line |
| Implicit scan | weclaw | Nothing to learn, no prompt cost | Mentioning a path can send it |
| Host attaches what the turn produced | Claude Code desktop, hermes Deliverable Mode, OpenProgram | Works when the model forgets the tool or a script made the file | Needs a rule for what counts as produced |
| None | codex-cli, opencode, pi-mono, pi-ai | Nothing to build | The model can only paste a path |
Instruction-line and implicit designs all keep paths inside allowed roots, resolving symlinks first.
Delivering produced files: peers and choices
Among the 21 harnesses on frontierharness.org/live, none of the strong ones relies on the model remembering to attach every file. They layer a host step, actionable paths in the reply, and a prompt line, with the send tool as a backup.
| Peer | What it does |
|---|---|
| Claude Code desktop, Cowork | Presents files Write and Edit produced by itself; SendUserFile is for files a script made. A setting opens HTML, images, PDF and video it writes |
| hermes Deliverable Mode | Scans the reply for absolute or ~ paths ending in .pptx, .docx, .xlsx or .pdf and uploads them; its docs admit the agent does not reach for files by default |
| Codex app, MiniMax Code | Opens a generated file after the task; lists files generated or referenced as results |
| Codex, Antigravity prompts | Ask the model to write file paths as clickable links and never to say a report is ready without its link |
| Choice | Why |
|---|---|
| Attach at turn end, not only through the tool | Claude Code desktop's split. Office files and PDFs come from scripts, which no edit journal records, and a model whose attachment was refused stops trying |
| Require a modification during the turn | hermes' scan has no such test, so naming an input file sends it back. The time test is one stat and separates a result from a mention |
| Accept relative paths and links | Models write exports/plan.pptx and markdown links more often than bare absolute paths, which are all hermes reads |
Same roots as send_file | The host step must not reach further than the tool. A file outside the roots is still opened from the link in the reply |
fs.read, not reply | Attaching is replying, but it shows a file's bytes. reply would let a paired speaker, who may not read the owner's files, have them sent |
No new prompt, no MEDIA: tag | Fewer prompts is the product direction, and a tag still depends on the model remembering |
Paths in a reply: peers and choices
| Peer | What it does |
|---|---|
| Claude Code desktop | A path in a reply opens the file pane or browser pane; right-click gives Attach as context, Copy (absolute, relative, filename), Open in, Show in Finder |
| KimiCode | Click opens File Preview; right-click gives Copy path and Reveal |
| OpenCode v2 | Links inline-code paths only after confirming the file exists, after unchecked guesses gave dead links |
| Codex app | Prompts for [app.py](/abs/path/app.py:12) links and opens them in its editor |
| Choice | Why |
|---|---|
| Link only what the worker confirms | OpenCode v2's fix. A code span like os.path.join has a path's shape; asking costs one batched stat request and no dead link is drawn |
One batched route, not /api/file-resolve per path | file-resolve answers one root-relative path and refuses absolute ones outside the chat's folder; documents/stat answers one path without its absolute form. A reply names many paths, and the menu's Copy needs the real path |
| Claude Code desktop's menu, in the app's own menu parts | The menu the user named. Built from ContextMenu and MenuRow so it looks like every other right-click menu; one component for paths, cards and changed-file rows |
| Open in default app in the desktop app, not the worker | The desktop app runs where the user sits; the worker route stays read-only and never runs a file. The app refuses anything the system would run, so the item cannot start a script the agent wrote |
| Scan settled replies only | A streaming reply redraws its last block on every delta; links would flicker and the questions would repeat |
Other techniques
- Output as a page: openclaw serves canvas documents embedded with
[embed ref=…]; Codex materialises::codex-inline-vis{in a sandboxed viewer (2 MB, strict CSP); pi-mono's/sharepublishes a session as a private gist. - Signed tokens: openclaw's
mediaTicket,v1.<payload>.<signature>, five-minute TTL. - Chips as editing units: claude-code sends an image only while its
[Image #N]stays in the text. - Hermes rewrites host cache paths to container paths. Codex has
view_image.
Implementation status
| Item | Status |
|---|---|
Marker grammar, root policy, inbound paths, chips, overlay, reply cards, file routes, send_file with no review, files the turn produced, paths in a reply as links, the file menu, channel delivery on all four platforms, canvas content rules | Implemented |
| Center tab for user attachments, caption, outbound allowlist, signed tokens, highlighting, multiresolution thumbnails | Not implemented |
| Attachment record, TUI inline images, live canvas panel | Not implemented |
document modality (model input in openprogram/models/providers/types.py) and a delivery-choice capability switch | Not implemented |
Code locations
- Marker, roots
openprogram/state/attachments.py- Web persistence
openprogram/interfaces/server/ws_actions/chat/attachments.py- Channel inbound
openprogram/interfaces/channels/inbound/_attachments.py- Channel delivery
openprogram/interfaces/channels/inbound/_conversation.py,_transport.py- Tool, turn end
openprogram/programs/tools/interaction/send_file.py,openprogram/runtime/conversation/turn_runtime/__init__.py- Routes
openprogram/interfaces/server/routes/files/file_search.py,archives.py- Chips, cards
apps/web/components/chat/messages/attachments/- Paths in a reply, file menu
apps/web/components/chat/messages/bubbles/prose-file-links.tsx,apps/web/lib/files/prose-file-paths.ts,file-path-lookup.ts,apps/web/components/files/file-path-menu.tsx,apps/desktop/main/files/open-default.js- Viewer
apps/web/components/files/file-viewer.tsx,preview/archive-preview.tsx