---
title: "Claude Code"
description: "Add Horizon to Claude Code and trade prediction markets from your terminal."
icon: "/images/integrations/claude.svg"
---

Claude Code is Anthropic's CLI for agentic coding. Adding Horizon as an MCP server gives Claude direct access to your trading engine - check positions, place orders, search markets, and manage risk through natural language.

## Setup

<Steps>
  <Step title="Install Horizon with MCP support">
    ```bash
    pip install horizon-sdk[mcp]
    # or
    uv pip install horizon-sdk[mcp]
    ```
  </Step>
  <Step title="Set environment variables">
    ```bash
    export HORIZON_API_KEY="your-key"

    # For paper trading (default), no other vars needed.
    # For live Polymarket:
    export HORIZON_EXCHANGE="polymarket"
    export POLYMARKET_API_KEY="..."
    export POLYMARKET_API_SECRET="..."
    export POLYMARKET_API_PASSPHRASE="..."
    export POLYMARKET_PRIVATE_KEY="0x..."
    ```
  </Step>
  <Step title="Register the MCP server">
    ```bash
    claude mcp add --transport stdio horizon -- python -m horizon.mcp
    ```

    This tells Claude Code to launch the Horizon MCP server as a subprocess using stdio transport.
  </Step>
  <Step title="Verify">
    ```bash
    claude mcp list
    ```

    You should see `horizon` in the list of registered servers.
  </Step>
</Steps>

## Usage

Once registered, just talk to Claude naturally. It will automatically use the Horizon tools when relevant.

### Check your portfolio

```
> What's my current PnL and positions?
```

Claude calls `engine_status` and `list_positions`, then summarizes:

```
Your engine has been running for 45 minutes:
- Realized PnL: +$12.45
- Unrealized PnL: -$3.20
- Daily PnL: +$9.25
- 2 open positions, 3 open orders

Positions:
1. will-btc-hit-100k: 25 YES @ 0.55 (unrealized +$2.50)
2. fed-rate-cut-march: 10 NO @ 0.35 (unrealized -$0.70)
```

### Search for markets

```
> Find bitcoin prediction markets on Polymarket
```

Claude calls `discover_markets(exchange="polymarket", query="bitcoin")`:

```
Found 5 BTC markets on Polymarket:
1. "Will BTC hit $100k by end of 2025?" - active, slug: will-btc-hit-100k
2. "Will BTC hit $150k by end of 2025?" - active, slug: will-btc-hit-150k
...
```

### Size a trade with Kelly

```
> I think there's a 65% chance BTC hits 100k. The market is at 50 cents.
> How much should I buy with a $2000 bankroll?
```

Claude calls `kelly_sizing(prob=0.65, price=0.50, bankroll=2000.0)`:

```
Kelly analysis:
- Edge: +15 cents (your 65% vs market's 50%)
- Quarter Kelly optimal size: 150 contracts
- Full Kelly would be 600, but quarter Kelly is safer

Want me to submit a buy order for 150 contracts at 0.50?
```

### Place an order

```
> Yes, buy 150 contracts of will-btc-hit-100k at 0.50
```

Claude calls `submit_order(market_id="will-btc-hit-100k", side="buy", price=0.50, size=150.0)`:

```
Order submitted:
- Order ID: p1
- Market: will-btc-hit-100k
- Side: buy
- Price: 0.50
- Size: 150 contracts
```

### Emergency stop

```
> Kill switch NOW
```

Claude calls `activate_kill_switch(reason="user requested emergency stop")`:

```
Kill switch activated. All orders have been canceled.
Reason: user requested emergency stop

To resume trading, say "deactivate kill switch".
```

## Tips

- **Paper mode by default**: If you don't set `HORIZON_EXCHANGE`, the engine runs in paper mode. Safe for experimentation.
- **Persistent engine**: The MCP server maintains a singleton engine for the entire session. Positions and orders persist across tool calls.
- **Multiple markets**: You can work with multiple markets in the same session. The engine tracks positions independently per market.
- **Context resources**: Claude can read `horizon://status` and `horizon://positions` as background context for richer responses.

## Removing

```bash
claude mcp remove horizon
```
