# Build with Claude Code

> **Security:** BetPlug's official Claude Code plugin (`version: "0.1.0"`) lives in `./claude-plugin` (`"private": true`) and intentionally ships **zero `hooks/`** so it never runs background shell commands without explicit developer approval. Do **not** install lookalike plugins or third-party marketplaces; load the plugin directly from your verified repository checkout.

The official BetPlug Claude Code plugin bundles verified integration skills (`betrail-integrate`, `betrail-embed`, `betrail-verify`), slash commands, and the pinned remote Streamable HTTP MCP endpoint so your coding agent can wire a complete sandbox integration in TypeScript (`./sdk/ts`), Go (`./sdk/go`), Python (`./sdk/python`), or PHP (`./sdk/php`) — matching the reference casinos in `./examples/next-casino`, `./examples/go-casino`, and `./examples/laravel-casino` ([Official SDKs](/docs/sdk)).

## Pinned manifest identity

Verify these exact values before loading the plugin:

| Field | Pinned value | Defined in |
|---|---|---|
| Marketplace name | `betrail` | `claude-plugin/.claude-plugin/marketplace.json` |
| Plugin install identifier | `betrail@betrail` | `claude-plugin/.claude-plugin/marketplace.json` |
| Plugin directory / source | `./claude-plugin` (`source: "./"`) | `claude-plugin/.claude-plugin/marketplace.json` |
| Pinned version | `0.1.0` | `claude-plugin/.claude-plugin/plugin.json` & `marketplace.json` |
| Remote MCP server (`betrail`) | `https://mcp.betrail.example/mcp` (`${BETRAIL_MCP_URL:-https://mcp.betrail.example/mcp}`) | `claude-plugin/.mcp.json` |
| Homepage | `https://betrail.example/docs/claude-code` | `claude-plugin/.claude-plugin/plugin.json` |

## Loading the official plugin locally

Launch Claude Code directly from your verified repository checkout:

```sh
claude --plugin-dir ./claude-plugin
```

Or register the local checkout as a development marketplace inside an interactive Claude Code session:

```text
/plugin marketplace add ./claude-plugin
/plugin install betrail@betrail
```

### Connecting to a local BetPlug stack

When developing against your local BetPlug stack — PostgreSQL/Valkey/Mailpit, `betrail-api`, `betrail-worker`, Operator Console (`http://127.0.0.1:3002`, with `BETRAIL_MCP_JWT_SECRET`), and the local MCP server (`node ./mcp/src/cli.ts` with `BETRAIL_MCP_JWT_SECRET`, `BETRAIL_MCP_CONSOLE_ORIGIN=http://127.0.0.1:3002`, `BETRAIL_MCP_CONSOLE_BFF_URL=http://127.0.0.1:8082`, `BETRAIL_MCP_SERVICE_SECRET`, and `BETRAIL_MCP_API_BASE_URL=http://127.0.0.1:8080`; see [Getting started](/docs/getting-started) and [Remote MCP server](/docs/mcp)) — export `BETRAIL_MCP_URL=http://127.0.0.1:8085/mcp` before launching `claude`.

Claude Code opens `/mcp/authorize` in your browser so you can approve sandbox scopes under your 2FA-enrolled Console session and revoke them anytime from `/security`. When `BETRAIL_MCP_URL` is unset, `.mcp.json` connects exclusively to `https://mcp.betrail.example/mcp` via OAuth 2.1 + PKCE.

## Included slash commands & skills

| Command / skill | Purpose |
|---|---|
| `/betrail-integrate` (`betrail-integrate`) | Wires a full sandbox integration: `.env.example`, `betrail-v1` / `betrail-v1-answer` signing, seamless wallet callbacks, webhook receiver, launch/headless calls, and conformance tests. |
| `/betrail-embed` (`betrail-embed`) | Mounts `<betrail-game>` (with SHA-384 SRI from `manifest.json`) or the isolated play host iframe with strict `betrail:v1` origin locking and CSP headers. |
| `/betrail-verify` (`betrail-verify`) | Audits and replays settled or post-draw `void` rounds across every legacy recipe, `FairRandom`, and live hash chain with redacted dispute exports. |

## End-to-end sandbox workflow with `/betrail-integrate`

Run `/betrail-integrate` inside your project (never pass secrets as command arguments):

```text
/betrail-integrate
```

The `betrail-integrate` skill walks through seven verified stages:

1. **Detect stack & scaffold `.env.example`** with placeholder variables (`BETRAIL_API_BASE_URL`, `BETRAIL_BRAND_ID`, `BETRAIL_API_KEY=btr_test_<key>`, `BETRAIL_SIGNING_SECRET`, `BETRAIL_WALLET_SECRET`, `BETRAIL_WEBHOOK_SECRET`, and optional 24-hour rotation overlap `BETRAIL_WALLET_PREV_SECRET`, `BETRAIL_WEBHOOK_PREV_SECRET`) — obtaining one-time sandbox credentials from Console Onboarding's one-time key vault and never committing secrets.
2. **Implement `betrail-v1` & `betrail-v1-answer` signing** verified against `api/testdata/signing-vectors.json` (plus optional RFC 8032 `ed25519=` wallet answers).
3. **Mount seamless wallet routes** (`POST /balance`, `/debit`, `/credit`, `/rollback`) keyed on `transaction_id`, returning unsigned `401` on bad auth, signed `4xx` refusals on insufficient funds, rollback tombstones, and unconditional `200` on `/credit` (including `"0.00000000"` and blocked players).
4. **Mount webhook receiver** (`round.settled`, `credits.low`, `credits.exhausted`) verifying `betrail-v1` over raw bytes before `JSON.parse` and deduplicating on `Betrail-Webhook-Id`.
5. **Wire launch/embed (`POST /v1/launch`) or headless rounds (`POST /v1/rounds`)** using exact decimal strings (`Amount`) and integer-atom math.
6. **Verify provable fairness** via seed rotation (`POST /v1/players/{player_ref}/seeds/{game}/rotate`) and `GET /v1/rounds/{id}/verify`.
7. **Run automated conformance tests** covering forged signatures, replay nonces, idempotent retries, rollback tombstones, and deterministic round replay.

> **Tip:** Pair `/betrail-integrate` with the remote MCP server's `test_wallet_endpoint` (6-step conformance probe) and `send_test_webhook` tools to verify your local or staging sandbox endpoints before running the Console's 29-check go-live suite.
