Skip to main content
ClaudeWave
Skill0 repo starsupdated today

xhost

>-

Install in Claude Code
Copy
git clone --depth 1 https://github.com/yairl/xhost-sdk /tmp/xhost && cp -r /tmp/xhost/plugins/xhost/skills/xhost ~/.claude/skills/xhost
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# xhost — Hosting Platform

xhost is a hosting platform for static sites and dynamic applications. You push code to a git remote, then trigger a deploy via the API. Every app gets a production HTTPS URL, and you can create preview URLs for branches.

## Current Context

- Working directory: !`pwd`
- Git remotes: !`git remote -v`
- Current branch: !`git branch --show-current`
- Latest commit: !`git log --oneline -1`

## Prerequisites

**Check for xhost MCP tools first.** This plugin bundles the xhost MCP server, so tools like `list_apps`, `create_app`, `commit_files`, and `deploy` (tool names contain `xhost`) are usually available directly. If they are:

- **Prefer the MCP tools for all API operations** — no token setup needed. Auth is handled by OAuth: if a tool call reports it's unauthenticated, tell the user to run `/mcp`, select the **xhost** server, and choose **Authenticate** (a browser opens for Google sign-in and a one-click approval; on first sign-in they pick a username).
- A token (`XHOST_TOKEN`) is only needed for the **fallback paths**: pushing to the git remote directly or calling the raw HTTP API with curl.

If MCP tools are NOT available, fall back to the raw HTTP API. Two environment variables control raw-API access:

- **XHOST_TOKEN** — Your API token (starts with `xh_`). Required for all raw-API operations and for the git remote.
- **XHOST_API_URL** — The API base URL. Defaults to `https://api.xhostd.com`.

Check if they are set:
```bash
[ -n "$XHOST_TOKEN" ] && echo "Token is set" || echo "Token not set"
echo "API URL: ${XHOST_API_URL:-https://api.xhostd.com}"
```

If the token is not set, guide the user through signup or login (see the Signup and Login sections below).

---

## Signup — Create a New Account

Account creation happens in a browser because Google sign-in is required.

- **MCP path (preferred):** tell the user to run `/mcp` → **xhost** → **Authenticate**. The browser flow covers signup too: Google sign-in, username selection on first sign-in, then a one-click approval. No token to copy.
- **Token path (for git pushes / raw curl):**
  1. Send the user to <https://xhostd.com> and tell them to click **Sign in with Google**.
  2. On first sign-in they pick a username (lowercase, digits, hyphens, 1–40 chars).
  3. Then send them to <https://xhostd.com/tokens?label=claude-code> and tell them to click **Create token** and copy the `xh_...` plaintext that's shown once.
  4. They give you the token; tell them:
     - `export XHOST_TOKEN=xh_...` (session)
     - Add to shell profile for persistence

If any raw API call later returns 401, the token is dead. Send the user to the same URL — <https://xhostd.com/tokens?label=claude-code> — to mint a new one, and have them paste it back. (For MCP tools, a 401 just means re-running `/mcp` → Authenticate.)

---

## Login — Configure an Existing Token

The user already has an xhost account and wants to use the raw API or git remote. (If they only need MCP tools, `/mcp` → Authenticate is enough — skip this.)

1. Ask the user for their `xh_*` token.
2. Validate by calling:
   ```
   curl -sf -H "Authorization: Bearer <token>" ${XHOST_API_URL:-https://api.xhostd.com}/apps
   ```
3. If invalid, tell the user. If valid, tell them to:
   - `export XHOST_TOKEN=xh_...` (session)
   - Add to shell profile for persistence

---

## Init — Create an App and Connect This Project

> **MCP shortcut:** if the xhost MCP tools are available, use `create_app` → `commit_files` → `deploy` instead of the raw-API steps below — no token or git remote required. The steps below are the raw-API/git fallback.

Set up a new xhost app linked to the current git repository.

1. **Check XHOST_TOKEN** — if not set, guide the user through signup or login first.
2. **Check XHOST_API_URL** — default to `https://api.xhostd.com`.
3. **Derive app name** from the current directory name. Slugify to DNS label rules (lowercase, replace non-alphanumeric with hyphens, trim, max 40 chars). Reserved prefixes: `git`, `api`, `www`, `admin`, `preview`, `staging`. Ask the user to confirm.
4. **Detect template and generate scripts** — follow this detection order:
   a. **launch.sh exists** — use `template: "app"`, do not overwrite. Tell user: "Found existing launch.sh."
   b. **Node.js project** — if `package.json` exists with `scripts.start`:
      - Generate `install.sh`:
        ```sh
        #!/bin/sh
        set -e
        if [ -f package-lock.json ]; then npm ci; else npm install; fi
        ```
      - Generate `launch.sh`:
        ```sh
        #!/bin/sh
        set -e
        if node -e "process.exit(require('./package.json').scripts?.build?0:1)" 2>/dev/null; then
            npm run build
        fi
        exec npm start
        ```
      - Tell user: "Detected Node.js project. Created install.sh and launch.sh."
      - Template: `"app"`.
   c. **Python project** — if `requirements.txt` exists:
      - Generate `install.sh`:
        ```sh
        #!/bin/sh
        set -e
        uv pip install --system --no-cache -r requirements.txt
        ```
      - Detect entry point: check for `app.py`, `main.py`, `manage.py` in order.
      - Generate `launch.sh`:
        ```sh
        #!/bin/sh
        set -e
        exec python <entry_point>
        ```
      - Template: `"app"`.
   d. **Otherwise** — template `"static"`. No scripts needed.
5. **Create the app**:
   ```
   curl -sf -X POST "${XHOST_API_URL:-https://api.xhostd.com}/apps" \
     -H "Authorization: Bearer $XHOST_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"name":"<app_name>","template":"<template>"}'
   ```
6. Parse the response — it returns `id`, `repo_url`, `template`, and `channels` (with the prod channel's `hostname`).
7. **Add the git remote** — insert the token before the hostname in `repo_url`:
   ```
   git remote add xhost "https://${XHOST_TOKEN}@git.xhostd.com/<username>/<app>.git"
   ```
8. If no commits exist, stage everything and create an initial commit. If generated scripts ar