# Claude Desktop and Claude Code

<!-- description: Use Herald from Claude Desktop and Claude Code: ask about today's briefing over MCP, and start a Claude Code routine each time a briefing is published. -->

Status: **documented** (follows the official docs; not yet run end to end).

Official docs used:
[Claude Code MCP](https://code.claude.com/docs/en/mcp),
[Claude Code permissions](https://code.claude.com/docs/en/permissions),
[Claude Code routines](https://code.claude.com/docs/en/routines),
[Claude Code channels](https://code.claude.com/docs/en/channels),
[connect local servers (Claude Desktop)](https://modelcontextprotocol.io/docs/develop/connect-local-servers),
[custom remote connectors](https://claude.com/docs/connectors/custom/remote-mcp),
[`mcp-remote`](https://github.com/geelen/mcp-remote).

## What you get

- **Pull (both):** ask Claude about today's briefing, one category of it or past stories, and
  change what you follow.
- **Push (Claude Code):** Herald fires a Claude Code routine through its API trigger when a
  briefing is published; the routine starts a cloud session with the briefing in its input.
  Claude Desktop has no inbound webhook.

## Pull: MCP

### Claude Code

**Same machine (stdio):**

```bash
claude mcp add --transport stdio --env HERALD_CONFIG=/path/to/herald/config.json herald -- /path/to/herald/.venv/bin/herald-mcp
```

Keep an option such as `--transport stdio` between `--env` and the name: `--env` takes several
`KEY=value` pairs and would read the name as another one.

**Another machine (streamable HTTP).** Run `uv run herald-mcp --http` next to Herald (see the
[index](README.md#common-ground)), then:

```bash
claude mcp add --transport http herald https://herald.example.com/mcp --header "Authorization: Bearer $HERALD_MCP_TOKEN"
```

To share the server with a repository instead, use `.mcp.json` in its root (`--scope project`);
Claude Code expands `${HERALD_MCP_TOKEN}` from the environment:

```json
{
  "mcpServers": {
    "herald": {
      "type": "http",
      "url": "https://herald.example.com/mcp",
      "headers": { "Authorization": "Bearer ${HERALD_MCP_TOKEN}" }
    }
  }
}
```

**Tools to allow.** Pre-approve the read-only tools in `.claude/settings.json`; Claude Code still
asks before `herald_follow` / `herald_unfollow`:

```json
{
  "permissions": {
    "allow": [
      "mcp__herald__herald_briefing",
      "mcp__herald__herald_categories",
      "mcp__herald__herald_history_search"
    ]
  }
}
```

### Claude Desktop

Edit `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`, Windows:
`%APPDATA%\Claude\`) and restart Desktop completely.

**Same machine (stdio):**

```json
{
  "mcpServers": {
    "herald": {
      "command": "/path/to/herald/.venv/bin/herald-mcp",
      "env": { "HERALD_CONFIG": "/path/to/herald/config.json" }
    }
  }
}
```

**Another machine.** A custom connector (Settings > Connectors) needs a public HTTPS URL, and
static request headers there are a beta that not every organization has. The portable way is the
`mcp-remote` bridge, which Desktop runs over stdio and which adds the bearer header:

```json
{
  "mcpServers": {
    "herald": {
      "command": "npx",
      "args": ["mcp-remote", "https://herald.example.com/mcp", "--header", "Authorization:${HERALD_AUTH}"],
      "env": { "HERALD_AUTH": "Bearer <HERALD_MCP_TOKEN>" }
    }
  }
}
```

(Writing the header without a space after `:` and keeping `Bearer ...` in the variable avoids an
argument-escaping bug on Windows.) Desktop asks before each tool call; there is no per-tool
allow list in the file.

## Push: webhook (Claude Code routine)

**1. Create the routine** on the web (see [routines](https://code.claude.com/docs/en/routines)),
with a prompt that says to act on the input, for example: "The input is today's Herald briefing.
Pick the five items that matter most for me, one line each, with links." Add an **API trigger**:
it shows the routine's URL (`https://api.anthropic.com/v1/claude_code/routines/trig_.../fire`)
and a token, once. The token belongs to that routine only; it is not your Claude login.

**2. Point Herald at it.** The trigger takes `{"text": ...}` with bearer auth and two Anthropic
headers. In Herald's `.env`: `CLAUDE_ROUTINE_URL` (the `/fire` URL) and `CLAUDE_ROUTINE_TOKEN`.

<!-- herald-config -->
```json
{
  "type": "webhook",
  "enabled": true,
  "name": "claude-routine",
  "languages": ["en"],
  "url": "${CLAUDE_ROUTINE_URL}",
  "auth": { "type": "bearer", "token": "${CLAUDE_ROUTINE_TOKEN}" },
  "headers": {
    "anthropic-beta": "experimental-cc-routine-2026-04-01",
    "anthropic-version": "2023-06-01"
  },
  "events": ["briefing.published"],
  "template": "{\"text\": \"$title ($count stories)\\n\\n$markdown\"}"
}
```

The beta header value comes from the routines docs at the time of writing; if the trigger starts
answering 400, check the docs for the current value. Every delivery starts a new cloud session,
and Herald retries on 5xx and 429, so a retried delivery can start a second session.

**Alternative: channels.** Claude Code channels (a research preview) push events into an open
interactive session through a local MCP server; the docs include a webhook receiver example. It
only works while that session is open, so a routine fits a daily briefing better.

## Troubleshooting

| Symptom | Cause |
|---|---|
| `claude mcp list` shows herald as failed | wrong path to `herald-mcp`, or (HTTP) the server is not running or the URL does not end in `/mcp` |
| 401 from `herald-mcp --http` | the bearer differs from Herald's `HERALD_MCP_TOKEN`; in `.mcp.json` use your own variable name, since Claude Code blanks some credential variables (such as `ANTHROPIC_API_KEY`) in remote headers |
| Desktop shows no Herald tools | config edited but Desktop not fully restarted, or invalid JSON in the file |
| Run report: `webhook:claude-routine HTTP 401` | wrong or regenerated routine token |
| The routine ignores the briefing | the input arrives marked as untrusted; the routine prompt must say to act on it |

## Testing without Claude

```bash
uv run herald dev sink --port 8787 --token "$CLAUDE_ROUTINE_TOKEN" --out herald-sink
# CLAUDE_ROUTINE_URL=http://127.0.0.1:8787/ in .env
uv run herald --data-dir /tmp/herald-try run --hours 6
```

The sink checks the bearer token and saves the `{"text": ...}` body as
`herald-sink/evt_<id>.json`. Replay it to the routine once you are happy with it:

```bash
curl -i -X POST "$CLAUDE_ROUTINE_FIRE_URL" \
  -H "Authorization: Bearer $CLAUDE_ROUTINE_TOKEN" \
  -H "anthropic-beta: experimental-cc-routine-2026-04-01" -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" --data-binary @herald-sink/evt_<id>.json
```
