# Building for htmlhost.co

This project is deployed to [htmlhost.co](https://htmlhost.co), a static host with built-in form handling. Follow these rules when you build or edit it.

## Ways to use htmlhost

- [Browser editor](https://htmlhost.co/new): upload or paste website files, import a URL, and edit visually, with AI, or in code. [Editor overview](https://htmlhost.co/editor).
- [Dashboard](https://htmlhost.co/dashboard): manage saved sites, domains, analytics, form messages, team access, keys, secure calls and collections. Available features depend on the site's plan and your role.
- [CLI](https://htmlhost.co/docs#cli): use htmlhost-cli from a terminal or coding agent to deploy, save drafts, clone, pull and manage sites.
- [Editor extension](https://htmlhost.co/guides/deploy-html-from-vs-code): install from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=htmlhost.htmlhost) for VS Code, or [Open VSX](https://open-vsx.org/extension/htmlhost/htmlhost) for Cursor, Windsurf, VSCodium, Antigravity. It runs the same CLI from editor commands and buttons.
- [Claude connector](https://claude.ai/directory/htmlhost): connect your htmlhost account to Claude on web and mobile. [Connection guide](https://htmlhost.co/guides/connect-htmlhost-to-claude).
- [Local MCP server](https://htmlhost.co/docs/mcp#clients): connect htmlhost-mcp to a compatible desktop AI or coding tool.
- [REST API](https://htmlhost.co/docs#api): integrate htmlhost into scripts and applications with an API token.
- [Templates](https://htmlhost.co/templates): start with an existing design and customize it in the editor.
- [Browser tools](https://htmlhost.co/tools): utilities for images, colors, CSS, metadata and HTML workflows.
- [File transfer](https://htmlhost.co/transfer) and [Clipboard](https://htmlhost.co/clipboard): companion tools for moving files and text between devices.

Choose the interface that fits the user's workflow. Saved sites can be worked on across the browser, CLI, extension and connected AI tools; save browser edits before switching tools, and pull current changes before editing locally. Publication still requires the user's authorization.

## Hosting model

- **Static files only.** HTML, CSS, JS, images, fonts and media are served as-is. No customer server code runs: there are no user-defined API routes, server-side rendering or environment variables. htmlhost supplies the built-in forms, secure-call and collection endpoints described below. Everything you publish is public, so never put API keys or secrets in client code.
- **No build step runs on the server.** If the project uses a bundler or framework, build it locally and deploy the output folder (for example `htmlhost deploy dist`).
- **Pages map to clean URLs.** `index.html` → `/`, `about.html` → `/about`, `blog/index.html` → `/blog`. Links to `about.html` redirect to `/about`, so either style works. A folder's index page also answers at `/blog/index.html` itself (no redirect), so its relative links resolve inside `blog/`. At `/blog` they resolve from the site root, so a folder's index page should use root-relative paths (`/blog/style.css`) or be linked as `/blog/index.html`. Relative links on other pages work as normal.
- **Sites never expire by default,** on every plan. `--ttl 1d|7d|30d` (MCP/API `ttl`) gives a site a shorter life for a temporary demo; only set one when the user asks. Republishing a site whose lifetime ran out brings it back.
- **Site icon.** The dashboard, the browser tab in the editor and link previews use the home page's `<link rel="icon">` (a file in the project, an absolute URL or an inline `data:` image all work), else a `favicon.ico` at the folder's root. Keep the site's icon when you edit, and add one when you build a new site.
- **The user's data is theirs to take.** Dashboard → the site → Settings → **Export site** downloads every file plus `form-submissions.csv` with all form responses; `htmlhost clone`/`pull` (or MCP `pull_site`) fetch the editable source.
- **Outbound links.** Without a verified, active custom domain connected to the project, outbound HTTP(S) links are served with `rel="nofollow ugc"` on every plan, including Pro. With an active custom domain connected, the author's rel attributes are honoured, including on the project's htmlhost.co address. Pending or expired connections do not qualify. This applies to all published pages and script-created links; stored source and exports keep the author's attributes.
- **Search engine visibility.** Published sites are indexable by default. The owner can turn off **Search engine visibility** in Site Settings → Advanced to serve the site with `X-Robots-Tag: noindex, nofollow` across all its pages.
- **Reserved paths.** Everything under `/__hh/` belongs to the platform. Don't create files or links there, except posting forms to `/__hh/form`.
- **Visit counts are built in and on by default.** When collection is enabled, htmlhost adds a small cookieless script that reports the view to `/__hh/v` for the owner's Analytics tab (views, visitors, pages, sources, countries, devices). The owner can turn collection off or back on in the site's Analytics or Settings tab; turning it off stops new counts and keeps existing reports under the normal retention policy. Owners can export their plan's available analytics from that tab as CSV or a PDF with the site's favicon, name and UTC reporting period. The script isn't in the project's files and needs nothing from you. Only add another analytics tool when the user asks for one.
- **Not deployed:** `node_modules`, `.git`, `.env*`, lock files, editor folders, and agent files such as `AGENTS.md`, `CLAUDE.md` and `.claude/`. Keep secrets out of any other file, because everything else in the folder is published.
- **Redirects:** a `_redirects` file at the folder's root (Netlify style) sets the site's redirects on `htmlhost deploy` (and the MCP `deploy` tool), one per line: `/old-page /new-page`, optionally followed by `301` (the default) or `302`. End the old path with `/*` to cover a folder, and the rest of the path carries over when the new one ends in `/*` too (`/blog/* /news/*`). The new address can be a path or a full URL. An exact old address may name query parameters, which must all be present: `/?p=123 /hello-world` (how a migrated WordPress site keeps its old `?p=` links). Lines starting with `#` are comments. The file itself isn't published. Each deploy with the file replaces the redirects it set before; redirects the owner added in the dashboard stay, and win if both cover the same path. When you rename or remove a page, add a line for its old address so links to it keep working. The home page (except an old link with parameters, like `/?p=123`) and `/__hh/` can't be redirected.

## Pro pricing

Pro costs $12/month or $120/year (USD). Prices in some regions are shown in local currency at checkout. Pro is paid for with one-time passes, with no auto-renewal; additional passes extend existing time. Already purchased time is honoured. Edit-credit packs are separate purchases. Read [current prices and limits](https://htmlhost.co/pricing) before advising a user about a purchase.

## Reliable editing workflow

Use **inspect → stage → validate → repair → commit** when editing an existing site.

1. Pull the current project before editing (use a fresh directory if local work could be overwritten). List its files, read the affected HTML and its CSS/JS dependencies, and inspect the existing page at desktop and mobile widths when browser tools are available. Search and paginate large files; read the complete original before replacing a whole file.
2. Keep pages and assets as separate source files. Make precise changes in a local working copy. Reuse the site's typography, spacing, colours, layout patterns and dependencies when adding a page.
3. Include the site's existing header and footer on new pages using the shared markers below. If they are not shared yet, establish matching markers on the donor and new page; keep intentional variants. Preserve required styles, scripts, body classes and working relative URLs. A similar-looking independent copy is not shared.
4. Validate the complete candidate before publishing: references, shared copies, form wiring and desktop/mobile layout. Check that the requested visible change actually appears. Repair failures and validate again after each change. Keep unrelated files and a recoverable baseline intact; check for concurrent remote edits before updating an existing site.
5. Report changed files and checks performed. If browser tools or interaction checks were unavailable, say what remains unverified. Source inspection or a script-less render does not prove JavaScript behaviour or successful form delivery. A frozen animation frame cannot verify motion; test playback separately when possible, otherwise report it unverified. Do not publish a failed or incomplete attempt as a successful edit.

For a focused element edit, inspect its exact source, parent layout and relevant styles first; avoid repeatedly reading unrelated files. Expand the investigation when needed, and keep the same validation before committing.

The browser editor stages edits and applies a validated turn with one undo; it opens a newly created HTML page and updates its page switcher together. External agents must perform their own checks: the CLI and MCP hosting tools do not run the editor's validation loop.

## Shared header, footer, and cookie consent

A multi-page site can share one header, one footer, and one cookie consent banner across its pages. Each page keeps its own complete copy, wrapped in marker comments:

```html
<!-- hh:shared header active-class="active" -->
<header>
  <nav><a href="/">Home</a> <a href="/about" class="active">About</a></nav>
</header>
<!-- /hh:shared header -->
```

The markers tell the htmlhost editor that the block is shared: when it changes on one page, the editor offers to apply the change to every page. Pages are plain HTML, so nothing else (deploys, hosting, other tools) needs to know about them.

- **Keep the markers.** Never delete, rename or reformat the marker comments or their attributes, and never wrap other content in them. Names in use: `header`, `footer`, `cookie-consent`.
- **Change a shared block on every page.** When you edit inside the markers, make the same edit on every page that has that block. The copies must stay identical, apart from the current page's menu link and relative paths (below). `htmlhost deploy` warns when copies differ.
- **The current page's link is marked per page.** `active-class` lists the classes that mark the link to the page you're on (with `active-on="parent"` they go on its parent element, such as an `<li>`); `aria-current="page"` on the marker means that link also gets `aria-current="page"`. Each page marks its own link and no other.
- **Relative paths differ by folder.** A page in a subfolder (`blog/post.html`) may use root paths (`/about`) where top-level pages use `about.html`. Both are fine; root paths work from every page.
- **A block's own styles and script** live in `/shared/NAME.css` and `/shared/NAME.js`, linked inside its markers (`<link rel="stylesheet" href="/shared/header.css">` first, `<script src="/shared/header.js" defer></script>` last), so every page that shares the block gets them. Put new styles for the block there, not in a page's own CSS, and keep the two references inside the markers.
- **Embedded dependencies:** a block may instead carry its scoped styles, font links and deferred scripts inside the markers. Keep those with the block and edit its embedded styles there, not in a page-local override. Do not strip data-URL script sources or data-hh-shared-icons dependency tags; those load and initialize the shared block's Lucide icons.
- **New pages:** copy the shared blocks from an existing page, markers included, and mark the new page's own menu link as above.
- **Unsharing a page:** removing the markers from a page makes its header or footer its own again. Do this only when the user asks for a page to differ.
- **Cookie consent:** the `cookie-consent` block is either a banner's markup or, when a consent service or plugin draws the banner with a script (CookieYes, Cookiebot, OneTrust…), that script and its set-up. Change a script-drawn banner's wording in that service's settings, not in the page. htmlhost's own banner (`data-hh-cookie-consent`) runs scripts written as `<script type="text/plain" data-hh-consent>` only after the visitor accepts, and any element with `data-hh-cookie-settings` shows it again; use these rather than loading tracking scripts directly. When a WordPress site moves to htmlhost, its consent plugin (it can't remember answers outside WordPress) is replaced by htmlhost's banner with the plugin's wording, and tracking scripts (Google Analytics, Tag Manager, Meta Pixel, Hotjar, Clarity and other analytics or advertising scripts htmlhost recognises) are written as `<script type="text/plain" data-hh-consent>` so they wait for Accept. Keep them held, and add new tracking scripts the same way.

## Publication and drafts

- **Unpublished means private.** Everyone whose role edits the site can keep editing, but making an unpublished site public requires the user's explicit agreement. A request to edit, deploy changes, retry, or restore a version is not enough on its own. Explain that the site will become publicly accessible and obtain confirmation. Never automatically retry a publication refusal with confirmation enabled.
- The server rejects unconfirmed publishing with HTTP 409 and code `PUBLICATION_CONFIRMATION_REQUIRED`. After consent, use CLI `deploy --publish` / `rollback --publish`, or MCP/API `confirmPublish: true`. This permission is for that request, not a saved project preference. `PUBLICATION_CHANGED` means a concurrent change or unpublish cancelled the request; inspect the current state before retrying.
- To keep working privately, use CLI `deploy --draft` or MCP/API `isDraft: true`. Saving a draft never unpublishes a live website. Only the owner can unpublish: `htmlhost unpublish <slug>`, MCP `unpublish_site`, or Site Settings → Publication. Confirm taking the site offline first. Files and history remain available.
- **Publishing on Free is limited to 3 sites per account.** An account with more sites (usually after Pro ends) keeps all of them online and can save drafts on any of them. Publishing to another site is refused with HTTP 403 and code `SITE_PUBLISH_LOCKED`. Don't retry. Tell the user, offer to save the work as a draft, and explain that they can upgrade to Pro or publish the site from the htmlhost editor, where they can choose it in place of one of their other sites.
- Listings expose `isPublished` and `draftVersion`. Pull/clone default to the working copy, including the latest saved draft. Use `--published` on CLI pull/clone or MCP `pull_site(source: "published")` only when deliberately retrieving the last deployed files. The API supports `source=working|draft|published`; never silently substitute older published files when a saved draft is unavailable.

## CLI

- `htmlhost deploy [dir|file]` publishes a folder as a multi-page site, or a single file. The folder is linked to its site through a `.htmlhost` file, so later deploys update the same site. Add `--json` for machine-readable output.
- `htmlhost status` shows what the next deploy would change (new, modified and removed files) and whether the live site changed since the last sync. It writes nothing. Run it before deploying; add `--json` for machine-readable output.
- `htmlhost pull` fetches changes made in the web editor, and writes `_redirects` when the site has redirects from one. Run it before editing a linked project so you don't overwrite someone else's changes (deploy also checks for this).
- `htmlhost login` signs in: it opens an approval page in the user's browser and prints the link and a code; show them both. Without a terminal attached it waits 90 seconds; if they haven't approved by then, run it again once they have.
- `htmlhost clone <slug>` downloads an existing site into a new folder.
- `htmlhost list` lists the user's sites, then the ones shared with them ("Shared with you", with each owner and the user's role on it). What the user's sign-in may do on a shared site follows that role:
  - **Admin**: Edits and publishes, changes site settings, keys and form recipients, reads and deletes form messages, and invites Editors, Contributors and Viewers.
  - **Editor**: Edits the site, publishes it, restores earlier versions, manages redirects and works with records in its collections.
  - **Contributor**: Edits the site and saves drafts. Can't publish: asks an Owner, Admin or Editor to publish the draft.
  - **Viewer**: Sees the site's page, draft preview, version history and analytics. Can't change anything.
  A Contributor's publish is refused (`ROLE_CANNOT_PUBLISH`): save a draft instead (`htmlhost deploy --draft`, or `isDraft: true` with MCP tools) and tell the user to ask the site's Owner, an Admin or an Editor to publish it, or to press Ask to publish in the htmlhost editor. Never delete a shared site (only its owner can), and leave its form recipients to the owner and Admins.
- `htmlhost calls [slug]` lists the site's secure calls; `htmlhost calls set` creates or updates one from a JSON definition (see Secure calls).
- `htmlhost keys [slug]` lists the site's keys (names, kinds, and the values of public keys; see Site keys), its secure calls and its collections. Add `--json` for machine-readable output.
- `htmlhost upload <file>` uploads media and prints a hosted URL.
- `htmlhost recipients [slug]` lists, adds, or removes form-notification recipients for a site (the site's owner and Admins only). Subcommands: `add <email>`, `remove <email|id>`, `resend <email|id>`.
- `htmlhost versions [slug]` lists the site's published versions, newest first. Every deploy and every save in the web editor is a version.
- `htmlhost rollback [slug] [version]` makes an earlier version live again (without a number, the one before the live version). It publishes that version as a new version, so it can be undone the same way. It needs the site owner to be on Pro. Afterwards, run `htmlhost pull` so local files match the site.

### VS Code extension

People who work in VS Code, Cursor, Windsurf, VSCodium or Antigravity can run these commands from buttons instead of a terminal with the free htmlhost extension (`htmlhost.htmlhost`; search "htmlhost" in the editor's Extensions panel): Deploy Site / Redeploy Site, Save as Draft, Show What Deploy Would Change, Pull Latest Changes, Clone a Site, and Add the htmlhost Guide to AGENTS.md. It runs this CLI and uses the same `.htmlhost` link and sign-in, so everything in this guide applies unchanged. As an agent, keep using the CLI or MCP tools yourself; mention the extension when the user asks how to deploy from their editor. Guide: https://htmlhost.co/guides/deploy-html-from-vs-code

## Remote MCP connector (Claude mobile and web)

For Claude setup, send the user to https://claude.ai/directory/htmlhost. Choose Connect, sign in to htmlhost and approve the connection, then enable htmlhost in the chat. Do not ask users to enter a server URL or create a custom connector. Existing connections can keep working without new setup. The underlying endpoint is https://htmlhost.co/mcp (Streamable HTTP with per-user OAuth). The user's account permissions and the project owner's hosting plan still apply. The local stdio server below remains separate.

- For a new project, use `create_project` where it is offered: the home page at `/` plus the other pages and text assets as separate files. It is saved as a private draft; show its preview, and publish only on the user's request. Retry with the same `operationKey`, so a retry never makes a second project. `get_account` names the connected account.
- Start with `list_projects` or `get_project` to identify the saved project and its working revision. Saved drafts are included; unsaved browser edits are unavailable.
- Use `read_file` and `search_files` to inspect bounded, relevant source. Do not repeatedly request the entire project. Keep separate HTML/CSS/JS files and every unrelated page and asset intact.
- `save_draft` applies exact edits against the revision and file hashes you inspected. On a stale revision or failed patch, reread the current files and revise the edit; never force a stale overwrite. Reuse the same idempotency key when retrying an identical write.
- `get_preview` returns a saved draft preview. Inspect the result and report checks you could not perform. These tools do not run a browser or the editor's AI validation loop.
- Use `publish_draft` only after the user requests publication, identifying the saved draft revision. Making an unpublished site public requires explicit consent. Connecting an account or saving a draft is not publication consent.
- Media transfers require the separate `media:write` permission. `import_media` downloads a public HTTP(S) URL into the connected user's Media library and returns its hosted URL. CSS dependencies are copied and rewritten within bounded limits; inspect returned warnings for unresolved dependencies. JavaScript module/runtime dependencies are not automatically rewritten. Update website references separately and report any external dependencies left in place.
- `create_media_upload` returns a one-hour upload-page link and request ID. `prepare_media_upload` returns a raw-byte PUT URL for clients with file/network access. When direct attachment transfer is unavailable, the user selects files on the upload page, returns to Claude and says Done; `get_media_upload` finalizes transfers and retrieves URLs. Do not put base64 file bytes in tool arguments or repeatedly poll while waiting for user input. Upload links are scoped capabilities; never publish them. Media URLs are public to anyone with the link, separate from project drafts and publication. Normal Media type and storage limits apply. No project selection or manual copying of file URLs is required.
- Users disconnect access in Settings → Connected apps. Setup: https://htmlhost.co/docs/mcp#claude-mobile

## Local MCP server

If your tools include htmlhost MCP tools (`deploy`, `deploy_html`, `list_sites`, `get_site`, `pull_site`, `delete_site`, `unpublish_site`, `login`, `whoami`, `list_versions`, `restore_version`), you can use them instead of the CLI. They share the CLI's sign-in; if they say you're not signed in, call `login`: it opens an approval page in the user's browser and returns the link to show them. `list_sites` returns sites shared with the user under `shared`: work on them as the CLI section says. Setup: https://htmlhost.co/docs/mcp

- **Pass the slug to update a site.** The MCP tools don't read the `.htmlhost` link file, so a deploy without `slug` creates a new site. In a linked project, take the slug from `.htmlhost`.
- **Deploy the folder, not a lone file.** Deploying a single HTML file doesn't upload the local CSS, JS or images it links to.
- **Never delete a site unless the user asked for it by name.** Deletion is permanent.
- **Only restore a version when the user asks.** Restoring replaces what visitors see. If a deploy went wrong, offer to restore the previous version rather than doing it unasked.

## Sign-in and access control

For project auth, user sessions or per-user data, explain visitor identity and backend authorization first. Shared project passwords and htmlhost team accounts are separate features, not substitutes for visitor authentication. Answer from these facts:

- When the user asks about auth, user sessions, login or per-user data in a project, address individual visitor identity and authorization first. Do not offer a shared project password or htmlhost team sign-in as a substitute. Discuss the site password when the user wants a shared gate for the whole project.
- Not built in: individual visitor accounts or identity-backed user sessions for projects (registration, login, identifying the current visitor, or per-user permissions). Collections cannot enforce ownership per visitor, and secure calls do not authenticate the visitor. Saving an auth provider's configuration in Keys does not add those capabilities.
- Shared project access: a site password (Pro). The site's owner or an Admin turns it on in the site's Settings, with an optional hint. Every page, file, form, secure call and collection then needs the password, on the site's htmlhost.co address and its custom domains. A visitor who types it stays unlocked for 7 days in that browser; changing the password requires everyone to unlock again. The browser unlock token records access to this shared gate, not an individual user identity. It does not create a visitor account, identify who submitted a record, or grant access to only that visitor's records.
- Native, for the team, not visitors: people who edit a site sign in to htmlhost (email link, Google or GitHub) and get a role on the site (Owner, Admin, Editor, Contributor, Viewer). That controls who can change and publish the site, not who can view it.
- For visitor accounts, a project can integrate an external sign-in service, such as Clerk, Auth0, Firebase Authentication or Supabase Auth. Save its public (publishable) key in the site's Keys tab as Public and load its script from its CDN; in the service's dashboard, add the site's htmlhost.co address and every custom domain as allowed origins and redirect URLs.
- Be clear about the limit: hiding part of a page until someone signs in with such a service doesn't protect the page's files, which anyone with the address can still download. Keep members-only data in a compatible backend that verifies the provider's sessions and enforces access rules (for example Firebase or Supabase security rules). htmlhost Collections and secure calls do not automatically verify external sessions or inherit those permissions. A shared project password is a separate whole-site access control, not a replacement for user-session authentication.
- Never build a sign-in or sign-up form that posts to htmlhost's form handler (/__hh/form): it refuses password fields, to protect visitors from phishing. Secure calls can use the site's own secret keys, but they can't check who a visitor is.

## Site keys

A site's owner can save the keys for the services the site uses (a payment gateway's key, a mailing list's, an analytics ID) in the site's **Keys** tab in the dashboard (`https://htmlhost.co/dashboard/sites/<slug>/keys`; the owner and Admins, when the owner is on Pro). Each key has a name such as `STRIPE_PUBLISHABLE_KEY` and a kind:

- **Public**: For values a service says are safe to show: a payment gateway's public key, an analytics ID, a form address. Every visitor to a page can read what's written into it.
- **Secret**: For values that must stay private: a secret or API key. Once saved it can be replaced but not read back, and it is never written into a page.

You are given every key's name, kind and note, and the value of public keys only: `htmlhost keys` (also written into this project's AGENTS.md by `pull` and `clone`), MCP `get_site` and `pull_site` (`keys`), and the remote connector's `get_project` (`keys`). The user may refer to a key by its name.

- Write a public key into a page by its name as {{key:NAME}}, never its value: htmlhost fills in the current value whenever it shows the page (the live site, the editor preview, an export), so changing the key in the Keys tab updates the live site with no edit or republish. Examples: <script async src="https://www.googletagmanager.com/gtag/js?id={{key:GA_MEASUREMENT_ID}}"></script>, Stripe("{{key:STRIPE_PUBLISHABLE_KEY}}"). Use it in HTML pages only (attributes, text, inline scripts and styles); a separate .js or .css file isn't filled in, so it should read the value from the page, for example from a data- attribute or a variable an inline script sets. When a page already contains a public key's literal value, replace it with the name. A name that isn't a saved public key is filled in as nothing, secret keys included.
- Never write, guess, invent or ask the user to paste a secret key's value into a page, script, stylesheet or any other site file: everything in a site's files can be read by every visitor. Refer to a secret key by its name only.
- Code in a page can't hold a secret key. A step that needs one (verifying a payment, calling a private API, adding a subscriber with an API key) runs through one of the site's secure calls, which htmlhost makes with the key. Without a call for it, create one if your tools can (see the secure call rules), or provide a JSON definition for Keys → Secure calls → Paste a definition → Review call and say which step needs it; never fake the step in the page.
- When a request needs a key the site doesn't have, ask the user for it. Never use a placeholder that looks like a real key.
- When the user gives you a key, save it to the site yourself if your tools can (the set_site_key MCP tool, or `htmlhost keys set NAME` in a terminal); otherwise tell them to add it in the site's Keys tab. Work out whether it's public or secret from the value's format (sk_… secret, pk_… public) or the service's own label, and ask the user only when you can't tell. Never repeat a secret's value back, and never write it into a file.
- Saving keys: `htmlhost keys set NAME [VALUE] [--public|--secret] [--note TEXT]` (in a linked folder, or with `--slug`; a value left out is read from stdin, which keeps it out of shell history), `htmlhost keys remove NAME`, the local MCP tools `set_site_key`/`remove_site_key`, and the remote connector's `set_site_key`/`remove_site_key`. Leave the kind out unless the user said: htmlhost works it out from the value and refuses with `KEY_KIND_UNKNOWN` when it can't, which is when you ask the user. A secret-looking value saved as public is refused with `KEY_LOOKS_SECRET` until the user confirms. Only the site's owner or an Admin can save keys, on Pro; the answer never contains the value.

### Secure calls

**Guide the user by the visible labels.** Open Dashboard → open the site → **Keys** → **Secure calls** (`https://htmlhost.co/dashboard/sites/<slug>/keys`). Prefer doing the setup with your tools after the required confirmation. If the user wants to review and add it in the dashboard, or creation tools are unavailable, offer **Paste a definition** instead of asking them to fill out the technical form.

For that handoff, give one complete JSON object per call, without Markdown code fences when the user asks for paste-ready text. Use saved key names, never secret values. Explain the service, visitor-controlled fields, fixed values and returned fields in plain language. Tell the user: **Paste a definition → Review call → Add call**. **Edit details** adjusts the configuration; **Back to JSON** replaces it. Invalid JSON stays editable. Missing keys can be added above without losing the review, but must exist before this dashboard form saves. An existing call name is not overwritten by paste: reuse it, edit the existing call or choose a new name. Match the page code to the final saved call's name and fields. **Use a template** contains Stripe and Mailchimp presets; **Create manually** opens a blank form.


A page can't hold a secret key, so htmlhost makes the call for it. AI tools can set up **secure calls** after confirmation; the owner can also review and manage them on the Keys tab: each has a name, one fixed address, the key that signs it, what is sent, and the parts of the service's answer that go back. Ready-made ones exist for Stripe (start a checkout, confirm a payment) and Mailchimp; other public HTTPS APIs must fit the supported methods, authentication and request/response limits. You are given each call's name, path, fields and returned parts with the keys (`htmlhost keys`, AGENTS.md, MCP `secureCalls`, the connector's `secureCalls`).

**Reuse a suitable existing call; otherwise create the secure call a request needs yourself**, alongside the page that uses it: `htmlhost calls set --file call.json` (or `--definition`, or the JSON on stdin), the local MCP tool `set_secure_call`, or the remote connector's `set_secure_call` where it is offered. Creating or changing a call that uses a key answers `CALL_NEEDS_CONFIRM`: tell the user which service it goes to and which key it uses, and repeat with `--confirm` (`confirm: true`) only after their yes. The first call that sends a secret key to a service is saved switched off (the answer's `notice`) until the owner switches it on in the Keys tab; calls for Stripe and Mailchimp with their usual key names, and later calls with the same key to the same service, start switched on. A call may name a key the site doesn't have yet; the answer lists it under `missingKeys`, the call still needs any required dashboard activation. The site's owner or an Admin only, on Pro.

- A secure call is the only way page code uses a secret key: htmlhost makes the call and the page never sees the key. Use one with fetch("/__hh/call/<name>", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ …its fields }) }) from a page of the same site; a <form method="post" action="/__hh/call/<name>"> submitted by script works too. Send only the fields the call lists.
- The answer is JSON: { ok, status, data } where ok is whether the service accepted the call, status is the service's status code, and data holds only the parts of its answer the call lists. On a refusal: { ok: false, error }. Always handle ok === false and show the visitor a plain message.
- A call does exactly what its owner set: you can't change its address, amount or anything not listed as a field. Never try to send extra fields, and never treat a value the page controls (an amount the visitor could edit) as trusted: for payments, check the paid amount in the verify call's answer.
- Secure calls work on the published site only (its htmlhost.co address and its custom domains), not in the editor preview or from a file on disk. Say so, and tell the user to test on the live site.
- Reuse a suitable existing call. When a request needs a secret key and the site has no suitable call for it, create the call yourself if your tools can and the user has not requested a dashboard handoff (define_call in the editor, the set_secure_call MCP tool, or `htmlhost calls set` in a terminal), alongside the page that uses it; otherwise write the page as if the call existed, name it, and give the user one complete JSON object per call to paste in the site's Keys tab (Secure calls → Paste a definition → Review call → Add call). Use saved key names, never secret values, and omit Markdown code fences for paste-ready output. A definition is { "name", "method", "url", "auth": { "type": "bearer" | "basic" | "header" | "query" | "none", "key", "username", "name" }, "bodyType": "json" | "form", "body": { … }, "returns": ["data.status"] }. Write a visitor's field (a lowercase name) as "{email:email}", "{amount:number}" or "{note?}" and a site key as "{{KEY_NAME}}"; {UPPER_CASE} text a service fills in itself, such as Stripe's {CHECKOUT_SESSION_ID}, is sent as written. Fix in the definition everything a visitor must not choose, such as the price. Creating or changing a call that uses a key needs the user's confirmation (CALL_NEEDS_CONFIRM): tell them the service it goes to and the key it uses, and confirm only after their yes. Outside the editor, the first call that sends a secret key to a service is saved switched off (the answer says so) until the owner switches it on in the Keys tab; later calls with that key to the same service start switched on. A call may name a key the site doesn't have yet: tell the user to save that key (never ask them to put a secret in a file), and report any remaining activation step. Saving or enabling a call does not mean it was tested.

Report readiness separately from saving: **Needs key** means add the named key; **Off** means select the switch, review the destination and choose **Enable call** in the dashboard. Do not guess why an existing call is off. **Enabled** means switched on, not tested. Never say a feature works solely because its call was saved. Test on the published site only, and request publication separately when it has not been authorized.

```js
// On the thank-you page Stripe returns to (?session_id=…)
const sessionId = new URLSearchParams(location.search).get("session_id");
const res = await fetch("/__hh/call/confirm-payment", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ session_id: sessionId }),
});
const { ok, data, error } = await res.json();
if (ok && data.payment_status === "paid" && data.amount_total === 5000) { /* paid */ } else { /* show error, or that payment wasn't confirmed */ }
```

Guides for people: https://htmlhost.co/guides/accept-payments-on-your-website and https://htmlhost.co/guides/use-api-keys-safely-on-your-website.

Limits: 20 calls a minute from one visitor's connection and 300 a minute per site; the service has 10 seconds to answer. Secure calls are part of Pro.

## Collections

For a manual handoff, say **Dashboard → open the site → Data → Collections** (`https://htmlhost.co/dashboard/sites/<slug>/data`). **Data** is the tab; **Collections** is the section heading. Prefer creating the collection and page together with the available tools; if unavailable, give the user its name, fields and read/add rules to enter there. Do not send collection JSON to **Paste a definition**: that workflow is for secure calls in Keys.

A site can keep its own data in **collections** (a waitlist, a guestbook, products, bookings, orders), set up in the site's **Data** tab (`https://htmlhost.co/dashboard/sites/<slug>/data`) or by AI tools working for its owner or an Admin. Each collection has typed fields (text, longtext, number, boolean, email, url, date; required or optional) and two rules: who can read records (anyone, or only people on the site) and who can add them (anyone from the site's pages, or only people on the site). Changing and deleting records happens only in the dashboard. Free sites get 1 collection of up to 100 records; Pro gets 20 per site, up to 10,000 records each.

You are given each collection's name, address, fields and rules, never its records: `htmlhost keys` and this project's AGENTS.md (written by `pull` and `clone`), MCP `get_site`/`pull_site` (`collections`), and the remote connector's `get_project` (`collections`).

**Create the collections a request needs yourself**, alongside the page that uses them: `htmlhost collections set NAME --field email:email! --field name --read private --add public` (or a JSON definition with `--definition` or on stdin), the local MCP tool `set_collection`, or the remote connector's `set_collection`. The same name updates a collection, replacing its fields. `htmlhost collections` lists them. A definition that would let anyone read personal details (an email or phone field), or open an existing private collection that has records, is refused with `COLLECTION_NEEDS_CONFIRM` until the user agrees. Only the site's owner or an Admin can create collections, within the owner's plan's limits.

- Read a collection whose read rule is public with fetch("/__hh/data/<name>") from a page of the same site. The answer is { ok, records, next }: records newest first (add ?order=oldest), up to 50 (?limit= up to 100), each { id, createdAt, updatedAt, …fields }. When next isn't null, fetch again with ?cursor=<next> for more. Add ?<field>=<value> to match a field exactly.
- Add a record to a collection whose add rule is public with fetch("/__hh/data/<name>", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ …fields }) }); a <form method="post" action="/__hh/data/<name>"> submitted by script works too. The answer is { ok, record } or { ok: false, error }: show the error to the visitor. Send only the collection's fields; others are ignored.
- A collection whose read rule is private can't be read by pages at all, and one whose add rule is private can't be added to from pages: never build a page that depends on that. Changing or deleting records is never possible from pages. If the page needs it, tell the user to change the collection's rules in the site's Data tab.
- Never show private information (emails, phone numbers, orders) from a collection anyone can read. Keep such collections' read rule private.
- Collections work on the published site only (its htmlhost.co address and custom domains), not in the editor preview or from a file on disk. Write the page so an empty or failed read shows a sensible message, and tell the user to test on the live site.
- When a request needs a collection the site doesn't have, or one with fields it lacks, create or update it yourself if your tools can (define_collection in the editor, the set_collection MCP tool, or `htmlhost collections set` in a terminal), alongside the page that uses it; otherwise tell the user what to add in the site's Data tab. A definition is its name, fields (each a snake_case name, a type of text, longtext, number, boolean, email, url or date, and required or not) and two rules: read (public or private) and add (public or private). Keep personal details private to read: a definition that would let anyone read emails or phone numbers, or open an existing private collection's records, needs the user's confirmation. Updating a collection replaces its fields, so include the ones it already has.

```js
// Show the newest guestbook entries
const res = await fetch("/__hh/data/guestbook?limit=20");
const { ok, records, next } = await res.json();

// Add one
const sent = await fetch("/__hh/data/guestbook", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ name, message }),
});
const { ok: saved, error } = await sent.json();
```

Guide for people: https://htmlhost.co/guides/add-a-database-to-your-website.

Limits: 10 additions a minute from one visitor's connection; a password-protected site's collections need its password like its pages.

Collections are managed records, not customer SQL access: no joins, real-time subscriptions, visitor updates/deletes or per-visitor record permissions. Private means authorized team members in the dashboard, not signed-in visitors. External browser sign-in does not change these rules. Booking/order records submitted by visitors are unverified input, not exclusive reservations or proof of payment; secure calls do not automatically save their results to collections.

Removing a field hides its stored values; adding it back restores them. Record contents are exported separately as CSV in the Data tab, not in site-file exports or agent metadata. The collection setup tool returns a record count, not record contents. Keys and collection definition changes take effect immediately, independently of page drafts.

## Forms

Any form can deliver submissions to the site owner, with no backend and no third-party service. Messages appear in the owner's dashboard and are emailed to them.

### Making a form deliver

1. Set `action="/__hh/form"` and `method="post"`. Use exactly this relative path, never an absolute URL.
2. Give every field a descriptive `name`. Fields whose names start with `_` are treated as controls and not stored.
3. Add `<input type="hidden" name="_form" value="Contact">` to name the form. One site can run several forms, and the owner sees messages grouped by this name.
4. Add the honeypot. People never see it, but bots fill it in, and their messages go to the owner's Spam folder. htmlhost adds one when it serves a form that lacks it, but a form your own script builds after the page loads needs it in the markup:

```html
<div aria-hidden="true" style="position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden"><label>Leave this field empty <input type="text" name="_hh_hp" tabindex="-1" autocomplete="off"></label></div>
```

A complete contact form:

```html
<form action="/__hh/form" method="post">
  <input type="hidden" name="_form" value="Contact">
  <label>Name <input name="name" required></label>
  <label>Email <input name="email" type="email" required></label>
  <label>Message <textarea name="message" required></textarea></label>
  <div aria-hidden="true" style="position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden"><label>Leave this field empty <input type="text" name="_hh_hp" tabindex="-1" autocomplete="off"></label></div>
  <button type="submit">Send</button>
</form>
```

The published site injects a small script that sends the form in the background and shows the result under the form. Don't add your own submit handler for these forms. If you do call `preventDefault()` on the submit event, the platform script steps aside and nothing is sent. Without JavaScript the form still works as a normal POST.

**Forms run by the page's own script** (steps, custom buttons): keep every answer inside the `<form>` (a named field, or a named hidden field the script fills before submitting), keep a real `<button type="submit">` inside it, and let htmlhost's form script send it. Don't call `preventDefault` or `stopImmediatePropagation` on submit; if your script must send the form itself, POST `new FormData(form)` to `/__hh/form` with `Accept: application/json` and show success only when the reply has `ok: true`. Forms only send on the published site; test there, then check Site → Messages, which also lists refused sends with their reason. A form marked `data-hh-takeover` (one migrated from WordPress) is sent by htmlhost's script before any other submit handler runs; keep the attribute.

### What visitors see after sending

By default the site owner's settings apply (a confirmation message, or a redirect to one of their pages). Only when the user asks, override this for one form with hidden inputs:

| Input | Effect |
|---|---|
| `<input type="hidden" name="_success" value="…">` | Confirmation message shown under the form (up to 500 characters). The default is "Thanks! Your message has been sent." |
| `<input type="hidden" name="_redirect" value="/thanks">` | Send the visitor to a page **on this site** after a successful send. It must start with `/`. External URLs are ignored |
| `<input type="hidden" name="_error" value="…">` | Message shown instead of the specific reason when sending fails |

If a form sets `_success` or `_redirect`, that form's choice replaces the site default for both. If you add `_redirect`, make sure the target page exists in the project.

### Styling the result

The message appears in a `<p data-hh-form-msg role="status">` appended to the form, with `data-state="success"` or `data-state="error"`. It inherits the page's font and colour. Style it with CSS:

```css
[data-hh-form-msg] { margin-top: 12px; }
[data-hh-form-msg][data-state="error"] { color: #b42318; }
```

### Rules and limits

- **Never collect credentials or card details.** Fields named like passwords, PINs, card numbers, CVV, SSN, seed phrases or one-time codes are rejected, and so are values that look like card numbers. The whole submission fails. Bank details for receiving money (account number, IBAN, sort code, routing number) are fine.
- **File uploads:** add `enctype="multipart/form-data"` to the form and `accept=".jpg,.jpeg,.png,.gif,.webp,.heic,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.csv"` to the file input. Attachments are delivered only on Pro accounts: up to 3 files, 10 MB each and 25 MB in total. Only add a file input if the user asks for one.
- **Volume:** 50 messages a month on Free and 5,000 on Pro, per account. Each visitor can send 5 messages per site every 10 minutes.
- **Only same-site forms send.** Forms on other websites can't post to this site, and on password-protected sites the visitor must unlock the site first.
- **Search forms aren't delivered forms.** Leave `role="search"` and other GET forms alone.
- **Forms don't send from local previews** or from the htmlhost editor preview, only from the published site.
- **Test from a browser.** A message posted by a script or HTTP client (curl, a test runner's request API) instead of a browser goes to the owner's Spam folder, so a test sent that way won't appear in the inbox.

## Keeping these instructions current

These instructions are maintained at https://htmlhost.co/agents.md. Run `htmlhost agents` to refresh them in this project.
