# Auto-Publishing with Claude Code Online + MCP

Claude Code on the web can automatically publish your static files every time a session starts — or immediately after a build — using an MCP server and lifecycle hooks.

This guide uses [drpr](https://drpr.host) as the publishing target, but the pattern works with any MCP-based deployment tool.

---

## How it works

Claude Code hooks execute shell commands or MCP tool calls at specific lifecycle points. Combined with an MCP server that wraps a publish API, you can trigger deploys without any manual steps:

```
Session starts → SessionStart hook fires → MCP tool publishes files → live URL ready
```

Or after a build:

```
Claude runs `npm run build` → PostToolBatch hook fires → MCP tool publishes dist/ → live URL ready
```

---

## Step 1: Install the drpr MCP server

Run the `/install-drpr-mcp` skill in your Claude Code session, or register it manually:

```bash
# Build the server
cd mcp-drpr && npm install && npm run build

# Register with Claude Code
claude mcp add drpr node /path/to/mcp-drpr/dist/index.js
```

Then authenticate:

```
drpr_set_api_key   # paste your key from https://drpr.host/dashboard?tab=api-keys
```

This gives you three tools: `drpr_set_api_key`, `drpr_publish`, and `drpr_logout`.

---

## Step 2: Configure auto-publish hooks

Edit `.claude/settings.json` in your project root. Choose one of the patterns below.

### Option A — Publish on session start

Good for: always serving the latest committed build when a web session opens.

```json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "mcp_tool",
            "mcp_tool": "mcp__drpr__drpr_publish",
            "params": {
              "filePath": "./dist"
            }
          }
        ]
      }
    ]
  }
}
```

### Option B — Publish after every build

Good for: preview deploys that update automatically as Claude iterates on code.

```json
{
  "hooks": {
    "PostToolBatch": [
      {
        "matcher": "Bash(npm run build|next build|vite build)",
        "hooks": [
          {
            "type": "mcp_tool",
            "mcp_tool": "mcp__drpr__drpr_publish",
            "params": {
              "filePath": "./dist"
            }
          }
        ]
      }
    ]
  }
}
```

### Option C — Both

Combine both blocks inside the same `settings.json` to get a publish on session start **and** after every build.

---

## Step 3: Test it

Start a new Claude Code web session in the project. You should see the MCP tool fire in the session log and get back a live URL like `https://your-subdomain.drpr.site`.

To force a publish manually at any time, ask Claude:

> "Publish the dist folder to drpr"

---

## How hooks work in web sessions

Claude Code web sessions run in an isolated cloud container. Hooks defined in `.claude/settings.json` are read from the cloned repo and execute inside that container — they behave identically to local sessions.

Key properties:

| Property | Detail |
|---|---|
| `SessionStart` | Fires once when the session container initialises |
| `PostToolBatch` | Fires after each batch of tool calls matching the `matcher` pattern |
| `type: mcp_tool` | Calls an MCP tool directly, no shell required |
| `type: command` | Runs a shell command instead |

Hooks run deterministically. They are not subject to Claude's judgement — they always fire at the specified event.

---

## Combining with other hooks

If you already have a `SessionStart` hook (e.g. for git identity setup), add the MCP publish step alongside it:

```json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/session-start-git-identity.sh"
          },
          {
            "type": "mcp_tool",
            "mcp_tool": "mcp__drpr__drpr_publish",
            "params": {
              "filePath": "./dist"
            }
          }
        ]
      }
    ]
  }
}
```

---

## Further reading

- [Claude Code hooks guide](https://code.claude.com/docs/en/hooks-guide.md)
- [Claude Code on the web](https://code.claude.com/docs/en/claude-code-on-the-web)
- [drpr REST API](https://drpr.host) — for direct curl-based publishing without MCP
- [drpr skill](./drpr/SKILL.md) — the Claude Code skill that powers the `/drpr` command
