# h0st.cloud > Push code, get a cloud. Every project gets its own container, git remote and HTTPS URL. An AI agent sets it up, ships each push to main with zero downtime, and proposes a fix when something breaks. This file is for coding agents. The homepage is also available as Markdown at https://h0st.cloud/index.md, or send `Accept: text/markdown` to https://h0st.cloud/. ## Connect 1. Get a token. The person you are helping opens https://t.me/my_cloudhost_bot on Telegram and sends `/token`; their Telegram account is their cloudhost account. Tokens start with `ch_` and grant full access to that person's clouds, so keep the token in the MCP client's config and never commit it. 2. Add the MCP server. It speaks Streamable HTTP, keeps no session, and takes the token as a Bearer header. ```sh claude mcp add -t http -s user cloudhost https://h0st.cloud/mcp -H "Authorization: Bearer ch_…" ``` Any other MCP client: `{ "url": "https://h0st.cloud/mcp", "headers": { "Authorization": "Bearer ch_…" } }` 3. Discovery card: https://h0st.cloud/.well-known/mcp.json Without MCP, the person can create a cloud from the Telegram bot: `/create ` replies with the git remote to push to. ## cloudhost — AI agent hosting platform cloudhost runs your web apps in isolated Docker containers called "clouds". Each cloud has its own git workspace, services, task engine, cron, and self-repair loop. You push code via git, cloudhost builds and runs it. ### Deployment model 1. **Create a cloud** — gives you an isolated container with a git remote. 2. **Set env vars** — API keys, secrets, config (set before first start so the onboarding agent can use them). 3. **Push code** — `git push` to the cloud's git URL. 4. **Start the cloud** — boots the container and triggers the onboarding pipeline. The `cloudhost_deploy` tool does steps 1-2 and returns a git push URL. After you push, the cloud auto-starts and onboards. ### Onboarding pipeline **Every first deployment goes through onboarding.** When a cloud starts for the first time (regardless of how code got there — git push, gitUrl clone, or MCP create), an AI onboarding agent automatically: 1. Reads the project, identifies the tech stack and entry points 2. Adapts the code for the cloudhost runtime (replaces managed-service dependencies with local equivalents like better-sqlite3, adds healthchecks) 3. Writes a `cloudhost.json` manifest declaring the build step and services 4. Runs the build and verifies services are healthy 5. Notifies the owner via Telegram when done (or asks for missing env vars) **You do NOT need to write cloudhost.json yourself.** Just push the code and the onboarding agent handles it. If the project already has a cloudhost.json, the agent is skipped and the manifest is used directly. ### Push semantics: branches vs main After onboarding, the **branch you push to** decides whether the push goes straight to production or to a named preview: - `git push HEAD:main` (or `master`) → **deploys straight to production** with zero downtime: the build runs next to the live version, the new version starts on a spare port (read `PORT` from the env) and takes the traffic once its healthcheck passes. A failed build or a version that never gets healthy leaves the old one serving. No preview, no promote step. - `git push HEAD:` → **creates a named preview**. Code lands in a session worktree, builds in isolation, and is served at `https://-.h0st.cloud` where `` is the branch name in lowercase letters, digits and hyphens (`feature/dark-mode` → `feature-dark-mode`; at most 30 characters, then shortened with a 4-character hash; `-2` if another preview has it). The push response and the Telegram message give the exact URL. The owner promotes to production via Telegram when ready; promote = `git merge --no-ff` of the session branch back into main. Multiple preview branches can coexist — pushing `feature-a` and `feature-b` gives you two independent preview URLs. Re-pushing the same branch replaces that preview in place. Promote of one branch leaves the others alive, and `commitsBehindMain` is reported per session. **Rule of thumb**: push trusted, reviewed work to `main`; push WIP or anything you want a human to eyeball first to a feature branch. ### What to expect after cloudhost_deploy 1. Call `cloudhost_deploy` → get back cloud id + git push URL 2. Run `git push HEAD:main` from the local repo 3. The cloud starts automatically and the onboarding agent begins working 4. The owner gets Telegram notifications about progress 5. Use `cloudhost_list_tasks` to monitor onboarding task status 6. Use `cloudhost_list_services` to check if services came up 7. Once healthy, the cloud is live at `https://.h0st.cloud` The onboarding agent typically takes 2-5 minutes. If it needs env vars (API keys, secrets), it will ask the owner via Telegram. Set known env vars upfront with `cloudhost_set_env` before pushing to avoid delays. ### cloudhost.json manifest If you need to write one manually (rare — the onboarding agent usually handles this), place a `cloudhost.json` at the repo root: ```json { "build": "pnpm install && npm run build", "services": [ { "name": "web", "start": "node dist/server.js", "port": 3000, "healthcheck": "/health" } ], "env_required": ["DATABASE_URL", "API_KEY"], "artifacts": ["output", "uploads", "podcasts"] } ``` #### Fields - **build** (optional) — Shell command run once before services start. Always use `pnpm install` (not npm) — the container has a shared store that makes pnpm near-instant. You can still use `npm run build` for scripts. - **services** (required) — Array of long-running processes: - **name** — Unique identifier (e.g. "web", "worker", "api"). - **start** — Shell command to start the service (e.g. `node dist/server.js`). - **port** (optional) — Port the service listens on. If set, the cloud gets a public URL: `https://.h0st.cloud` routes to this port. - **healthcheck** (optional) — HTTP path (e.g. `/health`). The supervisor polls `http://localhost:` to determine service health. - **restart** (optional) — `on-failure` (default), `always`, or `never`. - **maxRestarts** (optional) — Max restarts in 60s before marking failed (default: 5). Services should listen on `process.env.PORT` (falling back to `port`): each deploy starts the new version on a spare port in `PORT` and swaps it in once its healthcheck passes. - **deploy** (optional) — `{ "strategy": "blue-green" | "handoff" | "restart", "drainSeconds": 30, "readyTimeoutSeconds": 120 }`. Blue/green (default) runs the new version next to the old one and swaps with no downtime. `handoff` is for apps that must only ever be active once (in-memory state, startup recovery, job loops): the new version starts on `PORT`, answers its healthcheck, and takes an exclusive flock on `$CLOUDHOST_LOCK` (held for the life of the process) before opening its database or starting work; once it is healthy the old one gets SIGTERM (SIGKILL after 5s), the new one takes the lock and the traffic, and requests wait at the proxy in between. `restart` stops the old one first, for apps that cannot run twice and don't take the lock (a hard-coded port). - **env_required** (optional) — List of env var names the app needs. The supervisor warns (but still starts) if any are missing. - **artifacts** (optional) — Paths under `/workspace/` that hold generated content produced at runtime (e.g. by cron jobs or agent tasks) and need to be visible to running services immediately — without going through a code promote. Each path gets migrated into `/var/cloudhost/prod/

/` on manifest apply, and `/workspace/

` is replaced with a symlink to the prod copy. Declare this for any directory that a service reads at runtime but a generator writes to (podcast episode outputs, user uploads, generated catalogs, etc.). Paths must be relative, not escape the workspace, and not be git-tracked content. `data/` is always implicitly an artifact — do not declare it. Artifacts are also where **large generated files go instead of git**: upload them with `cloudhost_upload_assets` (see *Large or generated files* below). ### Typical workflows #### Deploy a new project 1. `cloudhost_deploy` with name and env vars → get git push URL 2. Run `git push HEAD:main` from the local repo 3. The cloud starts and onboarding agent runs automatically 4. Monitor with `cloudhost_list_tasks` and `cloudhost_list_services` #### Push updates to an existing cloud 1. `cloudhost_list_clouds` or `cloudhost_get_cloud` → each cloud includes a `gitPushUrl` 2. Add as a git remote: `git remote add cloudhost ` 3. Choose a target branch: - **To production**: `git push cloudhost HEAD:main` — deploys directly, no preview, no promote needed. - **To preview**: `git push cloudhost HEAD:` — builds a preview at `https://-.h0st.cloud` (`` from the branch). Owner promotes via Telegram (which merges the session branch into main). 4. Or use `cloudhost_reload_services` to pick up manifest changes without a push. #### Large or generated files (don't commit them) Never commit big binaries a script regenerates (baked meshes, rendered audio/video, datasets, model weights, `*.br` packs): every regeneration is re-uploaded in full on each `git push` (git can't delta compressed data), so pushes take minutes, can time out, and the repo grows forever. Instead: 1. Pick a directory for them (e.g. `public/mesh`), add it to `cloudhost.json` `"artifacts"` and to your local `.gitignore`, remove the files from git (`git rm -r --cached public/mesh`), push. 2. `cloudhost_upload_assets` with `remoteDir` → returns a shell script; run it from the repo root. It uploads only files whose sha256 changed, retries each upload, and the server verifies every file. Re-run it after each regeneration. 3. A service that reads the path sees new files at once. A build that copies them (an artifact inside Vite's `public/` is copied into `dist/`, and so reaches the static CDN) picks them up on the next deploy — push code or `cloudhost_reload_services`. `cloudhost_list_assets` shows what is there; `cloudhost_delete_asset` removes a file. Declared artifacts are not in the nightly backup (`data/` is), so keep whatever generates them. #### When a push is refused or deploys nothing Read the `remote: cloudhost: …` lines in the `git push` output: they say what happened and what to do. A push always lands over uncommitted changes in the cloud's /workspace (they are set aside in a `git stash`, and the output says so); force pushes are accepted. A push that changed no ref deploys nothing. #### Debug a failing service 1. `cloudhost_list_services` — check status (crashed? failed? unhealthy?). 2. `cloudhost_get_service_logs` — read stdout/stderr for errors. 3. `cloudhost_list_tasks` — find build tasks, check if build failed. 4. `cloudhost_get_task_logs` — read build output for errors. 5. `cloudhost_list_incidents` — see if self-repair detected the issue. 6. Fix code and push, or `cloudhost_restart_service` to retry. #### Manage scheduled jobs Use the cron tools to create jobs with standard cron syntax (e.g. `0 */6 * * *`). Jobs run as tasks inside the cloud. #### Pull a typed SDK for the cloud `cloudhost_pull_types` returns a TypeScript module string describing the cloud's env keys, services, declared artifacts, and public URLs. **Write the returned text to a file in the user's local repo** (conventionally `cloudhost.types.ts`). Importing the file augments `process.env` so reads like `process.env.STRIPE_KEY` get autocomplete and the editor catches typos at compile time. Regenerate after editing `cloudhost.json` or after `cloudhost_set_env` so the typed view doesn't drift. #### Reconcile cron + domains declaratively `cloudhost_apply_config` takes a bundle `{ cron?, domains? }` and reconciles the cloud to match. **Each present field is the full set** — items not in the list get removed. Omitted fields are left alone. Returns the diff (add / update / remove / unchanged) regardless of `dryRun`, so you can preview before applying. This replaces stringing together create + add + delete calls during setup, and gives you a real "make it look like this" verb instead of imperative drift. Env vars (secrets) and the manifest (in `cloudhost.json`) are intentionally not part of this bundle. #### Inspect or query the cloud's SQLite databases Call `cloudhost_db_list` first to see what databases exist under `/workspace/data/` and their per-table row counts — picks the `path` without guessing. Then `cloudhost_db_query` runs one SQL statement: - SELECT / PRAGMA / EXPLAIN: returns `{ kind:"rows", columns, rows, rowCount, truncated }`. Default row cap 1000; paginate with LIMIT/OFFSET when `truncated` is true. - INSERT / UPDATE / DELETE / DDL: require `confirmDangerous: true`. The database is opened read-only otherwise, so a missing flag fails fast instead of corrupting state. Returns `{ kind:"mutation", changes, lastInsertRowid }`. Always use `?` placeholders and pass values in `params` — never interpolate user input into `sql`. #### Measure and improve an app Declare what success means in `cloudhost.json`: ```json { "goals": [ { "id": "signup", "event": "signup" }, { "id": "checkout", "request": "POST /api/checkout" } ], "improve": { "goal": "signup", "constraints": "Keep prices unchanged." } } ``` - An `event` goal is sent from the browser: `navigator.sendBeacon('/__cloudhost/t', JSON.stringify({ event: 'signup' }))` (or `window.__cloudhost.track('signup')` where the feedback widget loads). - A `request` goal is matched by the proxy: `METHOD /path` (a trailing `*` matches a prefix), counted on a 2xx unless `status` says otherwise. - Declaring goals sets a first-party visitor cookie (`__ch_v`); bots and browsers sending GPC/DNT are not tracked. Every cloud gets request, error and latency counts without goals. - `cloudhost_get_metrics` returns the scorecard (visitors, conversion per goal, errors, p95, top pages, daily series, with significance tests) and the improve loop's state. - With `improve`, a read-only agent runs weekly (Mondays 09:00 UTC, or `improve.schedule`), and proposes ONE change backed by the numbers. The owner approves it in Telegram like an incident fix: Implement → preview → Promote. `cloudhost_run_improve` runs it now. It skips without an LLM call below `improve.minVisitors` (default 100 visitors a week) or while a proposal is waiting. - Once an improvement is on a preview, `cloudhost_start_experiment` A/B tests it: the variant runs next to the live version, half of tracked visitors get it, and the primary goal is compared per version (fixed sample, at least 7 days, auto-stopped if the variant errors or slows down). The owner gets the result in Telegram and decides. Any push to main ends a running test. The variant gets `CLOUDHOST_CANARY=1` — apps with background jobs (emails, queues) should skip them when it is set. #### Every cloud is an MCP server (be its admin or a user) Each cloud serves its own remote MCP at `https://.h0st.cloud/__cloudhost/mcp` (standard OAuth 2.1 sign-in, or a Bearer key). `cloudhost_mcp_connect` returns the URL and ready-to-paste setup. - **Admin** (the owner): the cloudhost tools pinned to that one cloud (no cloud id needed) plus the app's own tools. Sign in and approve in Telegram, or send the owner's `ch_` token as Bearer. - **User**: only the app's tools. `cloudhost_mcp_add_user` issues a `cu_…` key (shown once); `cloudhost_mcp_revoke_user` takes it back. - **The app's tools**: its features, declared in cloudhost.json `"tools": [{ "name", "description", "method", "path", "input", "role" }]`, each mapped to one of the app's HTTP routes — no MCP code in the app. Cloudhost calls the route with `X-Cloudhost-Role: admin|user` and `X-Cloudhost-User`, which visitors cannot forge. `role: "admin"` tools are the owner's only. To add tools, create an agent_turn task asking the cloud agent to "expose the app's main features as MCP tools using the remote-mcp skill". #### Destroy a cloud `cloudhost_destroy_cloud` sends a confirmation to the owner via Telegram. The owner must tap "Confirm destroy" for it to proceed. This is a safety measure — destruction cannot be triggered by API alone. #### Rename a cloud `cloudhost_rename_cloud` changes the user-facing name and subdomain of a cloud (e.g. `comprehensible-thai` → `beanstalk`). Like destroy, this sends a confirmation request to the owner via Telegram and returns `{ pending: true }`; the rename only applies when the owner taps "Confirm rename". Rules: - 3-32 chars, lowercase letters / digits / hyphens, must start with a letter. - Must not collide with another owned cloud's name. - Running containers are NOT restarted; `cloud-` (the Docker name) doesn't change. The new subdomain `.h0st.cloud` starts routing on the next request after confirmation, and the old subdomain stops. ### Next steps in results Results that end in a state you can act on carry `nextSteps`: an array of `{ tool, args, why }`. `tool` + `args` is the call to make next, already filled in; `why` says what it addresses. A step without `tool` is a wait or something only the owner can do (answer in Telegram, tap Promote) — tell the user instead of calling anything. For example: a cloud whose container failed to start points at `cloudhost_start_cloud` with the cause, a crashed service points at its logs, and a `proposed` incident lists one `cloudhost_apply_incident` call per fix option. ### Access URLs - Each cloud with a port gets: `https://.h0st.cloud` - Custom domains can be added via `cloudhost_add_domain` (TLS automatic). - Direct proxy: `/v1/clouds//proxy//` (requires Authorization: Bearer header). ## Tools Served at https://h0st.cloud/mcp. Each tool's full description and input schema come from `tools/list`. - `cloudhost_list_clouds`: List all clouds owned by the authenticated user. - `cloudhost_get_cloud`: Fetch a single cloud by id. - `cloudhost_create_cloud`: Create a new cloud (an isolated container with a git workspace). - `cloudhost_start_cloud`: Start a cloud container. - `cloudhost_stop_cloud`: Stop a running cloud. - `cloudhost_destroy_cloud`: Request destruction of a cloud. - `cloudhost_rename_cloud`: Request a rename for a cloud (changes the user-facing name and subdomain). - `cloudhost_list_env_keys`: List the names of env vars configured for a cloud. - `cloudhost_set_env`: Set or update env vars on a cloud. - `cloudhost_unset_env`: Remove a single env var from a cloud. - `cloudhost_get_manifest`: Get the parsed cloudhost.json manifest for a cloud (as published by the supervisor on startup). - `cloudhost_list_services`: List all services declared in the cloud's manifest with their current status (pending|starting|running|unhealthy|crashed|failed|stopped), pid, restart count, and last error. - `cloudhost_get_service`: Get the full state of one service in a cloud, including spec, pid, restart history, and healthcheck status. - `cloudhost_get_service_logs`: Fetch the last N lines of stdout/stderr from a service. - `cloudhost_restart_service`: Stop and respawn a single service without restarting the whole cloud container. - `cloudhost_reload_services`: Re-read cloudhost.json from the workspace and apply changes (start new services, leave existing ones alone). - `cloudhost_list_tasks`: List tasks for a cloud, most recent first. - `cloudhost_create_task`: Spawn a one-shot task inside a cloud (kind: command runs via shell, script runs an executable, agent_turn invokes the cloud's built-in LLM agent). - `cloudhost_get_task`: Get the current state of a task: status (queued|running|succeeded|failed|cancelled|dead), exit code, timestamps. - `cloudhost_get_task_logs`: Fetch the stdout/stderr log for a task as plain text. - `cloudhost_resume_agent_turn`: Re-spawn an interrupted agent_turn task. - `cloudhost_deploy`: Create and configure a new cloud for deployment. - `cloudhost_list_domains`: List custom domains bound to a cloud. - `cloudhost_add_domain`: Bind a custom domain to a cloud. - `cloudhost_remove_domain`: Remove a custom domain from a cloud. - `cloudhost_list_cron_jobs`: List all scheduled cron jobs for a cloud. - `cloudhost_create_cron_job`: Create or update a scheduled cron job. - `cloudhost_delete_cron_job`: Delete a scheduled cron job. - `cloudhost_pause_cron_job`: Pause a scheduled cron job. - `cloudhost_resume_cron_job`: Resume a paused cron job. - `cloudhost_list_incidents`: List incidents for a cloud. - `cloudhost_get_incident`: Get full details of a single incident: status, triage summary, proposed fix options, preview session, and occurrence count. - `cloudhost_apply_incident`: Approve the proposed fix for an incident in status `proposed` (or a proposed improvement from `cloudhost_get_metrics`) — the same as tapping Implement in Telegram. - `cloudhost_resolve_incident`: Manually mark an incident as resolved. - `cloudhost_db_list`: List the cloud's SQLite databases discovered under /workspace/data/. - `cloudhost_db_query`: Execute one SQL statement against a SQLite database in the cloud's /workspace. - `cloudhost_apply_config`: Reconcile a cloud's cron jobs and custom domains against a declared bundle. - `cloudhost_pull_types`: Generate a TypeScript module describing one cloud's runtime contract: declared env keys (with ProcessEnv augmentation for autocomplete + typo detection), services + ports, declared artifacts, and public URLs. - `cloudhost_get_metrics`: How a cloud's app is doing, from what cloudhost's proxy saw: visitors, conversion rate per goal declared in cloudhost.json `goals`, requests, 5xx rate, p95 latency, top pages and a daily series, for the last N days vs the N days before. - `cloudhost_start_experiment`: Start an A/B test: half of tracked visitors get a new version, the other half the live one, and cloudhost compares the primary goal per version with a fixed sample size (at least 7 days), stopping early if the new version errors or slows down. - `cloudhost_get_experiment`: An A/B test's state: status (building, running, completed, stopped, failed, superseded, promoted, discarded), the planned sample per version, per-version visitors, conversions, error rate and p95 so far (`progress`), and once completed the result with the 95% interval and verdict. - `cloudhost_stop_experiment`: Stop a running A/B test without a result: all visitors go back to the live version and the variant stops. - `cloudhost_run_improve`: Run the cloud's improve loop now instead of waiting for its schedule. - `cloudhost_mcp_connect`: Get a cloud's own remote MCP server: its URL, ready-to-paste setup for Claude Code / Claude Desktop, the app features it exposes as tools (manifest `tools`, each mapped to one of the app's HTTP routes; empty until the app declares some), the app's own MCP endpoint if any, and the users holding access keys. - `cloudhost_mcp_add_user`: Issue an access key (cu_…) so a person or agent can use a cloud's MCP as role "user": they get the app's own tools only, and the app sees them as X-Cloudhost-User. - `cloudhost_mcp_revoke_user`: Revoke a user's access key for a cloud's MCP, and every sign-in made with it. - `cloudhost_upload_assets`: Upload large or generated files (baked meshes, rendered media, datasets, model weights) straight into a cloud, WITHOUT committing them to git. - `cloudhost_list_assets`: List files uploaded to a cloud's data/ and declared artifacts (the files cloudhost_upload_assets puts there, and anything the app or a cron job wrote). - `cloudhost_delete_asset`: Delete one file from a cloud's data/ or a declared artifact.