/primer:primerfrom primer
Publish and iterate on LLM-generated HTML or Markdown artifacts in Primer. Use when the user wants to share an artifact at a stable URL, push a new version as they iterate, or pull reviewer comments/feedback on a version. Auth is handled at connector-install time via OAuth in the browser; the skill just drives the tool surface.
Ships in primer. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Workflow brain over the Primer MCP tools. Use the five steps below in order; deeper detail (full tool I/O, error taxonomy, file schemas) lives in reference.md — read it on demand.
Disk round-tripping: when the Primer MCP server runs locally (@polygonlabs/primer-mcp over stdio — its content tools list contentPath / toDisk params in their input schemas), keep the document body out of your context in both directions: upload with contentPath (absolute path the server reads) whenever the artifact already exists as a file, and fetch with toDisk: true whenever the content is large, has embedded images, or is destined for disk — the server saves to a fresh temp file it owns and returns its savedTo path; move it into place with your own file tools. Byte-perfect and orders of magnitude cheaper than inline. The remote connector (HTTP) has no filesystem access; with it, content is always inline. Details and thresholds: reference.md → Disk round-tripping.
If the user reports the MCP tools aren't available, tell them to install/reconnect the Primer connector in their Claude client (Settings → Connectors → Primer), then re-run the request. Auth is one-time browser OAuth at install; there is no login flow inside the agent.
Call primer_whoami first. If it succeeds, skip to step 2.
If it errors, parse the JSON payload in the tool result's text and branch on code (never on message text):
not_authenticated → tell the user to reconnect the Primer connector (Settings → Connectors → Primer → Reconnect / Reauthorize), then stop. Do not attempt to drive an in-agent login flow — OAuth is handled by the Claude client, not by the skill.Two branches, in order:
A. User gave you a Primer URL to iterate on (paste of a /d/<id> or /d/<id>/v/<n> URL, or an explicit ask to update an existing doc):
primer_resolve_url with the URL. On bad_request "not a Primer URL", tell the user and stop.documentId with primer_add_version.B. Otherwise, check for .primer/document.json in process.cwd() (only meaningful when the environment has filesystem access — Claude Code, Codex; skip in Claude Web/Desktop where there is no cwd):
primer_create_document.
format from the source: .md or .markdown extension → "markdown"; everything else → "html".mkdir -p .primer in process.cwd(), then write .primer/document.json with the shape from reference.md.primer_add_version with the recorded documentId. After success, update lastVersionId, url, and savedAt in the file.Surface the url from the response immediately. One line, no decoration:
Published: <url>
When the user revises the artifact, regenerate the content and call primer_add_version with a concise versionNote describing what changed (e.g. "fixed Y-axis scale", "addressed reviewer Q on assumptions"). If you have .primer/document.json, update it with the new version id.
Call primer_get_comments with { documentId } to target the latest version automatically (or { versionId } if pinning to a specific revision). Provide exactly one of the two.
The tool returns a markdown summary. For each open thread, use the quoted selection text (the > ... line) as the locator — that's the literal text the reviewer anchored to in the document, and it maps directly back to your source. Propose or apply fixes for each open thread, then push a new version via primer_add_version with a versionNote that references the addressed feedback.
The correct transport for a large page is a file, not your context window.
Write the document to disk as you build it, then upload with contentPath
(local stdio server — see "Disk round-tripping" above). Byte-perfect, a
handful of tokens, and the only limit is the API's 10 MB cap. Page size stops
being a publishing concern entirely: emitting a large page inline pays for
every byte twice (into context, then out again in the tool call) and gambles
on byte-level reproduction — there is no reason to do it when a path is
available.
Inline-transmission fallbacks — remote connector only. Only when the tools
have no contentPath (HTTP connector, no filesystem) does payload size shape
authorship:
<script type="application/json" class="cat">…</script> blocks (~15 KB each)
and reassemble at runtime ([...document.querySelectorAll('script.cat')].map(s=>s.textContent).join('') → JSON.parse). Escape < as < inside the JSON so it can't break out of the script tag.Primer renders documents in a sandboxed iframe (allow-scripts, no
allow-same-origin). Inline <script> runs, but the sandbox constrains
interactive pages regardless of how they were uploaded:
navigator.clipboard API is blocked in the sandbox.
Any copy control must fall back to a hidden-textarea + document.execCommand('copy').<use> icons
lose their fill/stroke in the sandbox and render as black blobs./api/versions/<id>/content URL directly, which renders immediately.To embed a diagram, use inline SVG in an HTML-format document. Markdown
format is a dead end for diagrams: the renderer escapes raw <svg> (it shows as
source text) and does not parse data-URI images (
stays literal text). Published as format: "html", the sanitizer keeps SVG
shape/<text>/<path>/<marker> tags and the diagram renders.
Mind the transport on the remote connector. With the local stdio server,
inline SVG is free to publish — contentPath keeps the whole body (SVG
included) out of context (see "Disk round-tripping" above), so author diagrams
as richly as you like. With the remote HTTP connector there is no
contentPath: the model is the sole transport to the server, so every byte of
inline SVG is an output-token cost paid on every version. That makes a large
inline diagram something to actively avoid there, not a neutral default — apply
the decision rule in the last bullet below.
<text>. Don't lean on Primer's ```mermaid rendering for flowcharts — it
under-measures label widths and clips node/edge text, and a
%%{init: {flowchart: {htmlLabels: false}}}%% directive does not fix it.<style>
(fonts, tables, code, and light/dark via @media (prefers-color-scheme: dark)
plus :root[data-theme]). Pastel fills with dark text stay legible on both
themes; use a mid-grey (#888) for connectors so they show on either./brand assets). A hosted-asset upload path for
arbitrary assets is tracked in #87. On the local stdio server none of this
applies — contentPath already keeps the body out of context, so inline
freely.Every tool error result is JSON-encoded as { code, message } in the result text. Branch on code:
| code | action |
|---|---|
not_authenticated | Tell the user to reconnect the Primer connector (Settings → Connectors → Primer). Stop — do not drive login in-agent. |
forbidden | Tell the user this document isn't theirs (uploader-only ownership). Stop. |
not_found | If the id came from .primer/document.json, the recorded document was deleted on the server. Prompt the user before creating a new one — never silently overwrite the file. For other 404s, surface the message. |
bad_request | Surface the server's message verbatim — it carries validation/size/format/URL-parsing detail. |
rate_limited | Wait a few seconds and retry once. If it fails again, surface and stop. |
network | Retry the call once. If it fails again, surface and stop. |
| anything else | Surface code + message and stop. |
For deeper detail on tool I/O, the .primer/document.json schema, format selection, the 10 MB inline limit, and what Primer strips from uploaded HTML, see reference.md.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub 0xpolygon/primer --plugin primer