> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leanmcp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Route Claude Code through LeanMCP AI Gateway for full observability — every prompt, token count, and tool call logged.

# Claude Code

Route Claude Code through LeanMCP AI Gateway. Every request gets logged — prompts, responses, token usage — visible in your dashboard in real time.

**Takes 2 minutes to set up.**

***

## Before you start

You need two things:

<Steps>
  <Step title="A LeanMCP account with credits">
    Go to [app.leanmcp.com/billing](https://app.leanmcp.com/billing) to top up credits. Credits are required before the gateway will accept requests.
  </Step>

  <Step title="An API key">
    Go to [app.leanmcp.com/api-keys](https://app.leanmcp.com/api-keys) → **Create API Key** → select **SDK** permissions → copy the key immediately (shown once only).

    Your key format: `leanmcp_859fc75e...`
  </Step>
</Steps>

<Note>
  Already have a key and credits? Skip straight to [Configuration](#configuration) below.
</Note>

***

## Configuration

Claude Code reads environment variables from `~/.claude/settings.json`. You're pointing it at the LeanMCP gateway instead of Anthropic directly.

<Steps>
  <Step title="Find your settings file">
    | OS            | Path                                        |
    | ------------- | ------------------------------------------- |
    | macOS / Linux | `~/.claude/settings.json`                   |
    | Windows       | `C:\Users\<username>\.claude\settings.json` |

    If the file doesn't exist, create it.
  </Step>

  <Step title="Add the gateway config">
    Add (or merge) the `env` block into your `settings.json`:

    ```json settings.json theme={null}
    {
      "autoUpdatesChannel": "latest",
      "env": {
        "ANTHROPIC_BASE_URL": "https://aigateway.leanmcp.com/v1/anthropic",
        "ANTHROPIC_AUTH_TOKEN": "leanmcp_your_api_key_here",
        "ANTHROPIC_API_KEY": ""
      }
    }
    ```

    <Warning>
      Set `ANTHROPIC_API_KEY` to an empty string `""`. If both keys are present, they conflict and requests will fail.
    </Warning>
  </Step>

  <Step title="Verify it works">
    Run any Claude Code command as normal:

    ```bash theme={null}
    claude "say hello"
    ```

    Then open your dashboard at [app.leanmcp.com/observability](https://app.leanmcp.com/observability). You should see the request appear within a few seconds.

    If you see the log entry: you're done. ✓
  </Step>
</Steps>

***

## What you'll see in the dashboard

Once configured, go to [app.leanmcp.com/observability](https://app.leanmcp.com/observability). Every Claude Code request is tracked:

| Field         | What it shows                         |
| ------------- | ------------------------------------- |
| Request Body  | Full content sent to the AI           |
| Response Body | Complete response received            |
| Model         | Which model was used                  |
| Tokens        | Input, output, and total token counts |
| Latency       | Response time in milliseconds         |
| Status        | Success or error                      |
| Timestamp     | When the request was made             |

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Requests aren't showing in the dashboard">
    1. Double-check `ANTHROPIC_BASE_URL` is exactly `https://aigateway.leanmcp.com/v1/anthropic` with no trailing slash
    2. Confirm `ANTHROPIC_API_KEY` is set to `""` — a leftover value will bypass the gateway
    3. Confirm your account has credits at [app.leanmcp.com/billing](https://app.leanmcp.com/billing) — zero credits means requests are rejected
  </Accordion>

  <Accordion title="Authentication error / 401">
    Your `ANTHROPIC_AUTH_TOKEN` is wrong or the key was deleted. Go to [app.leanmcp.com/api-keys](https://app.leanmcp.com/api-keys), create a new key, and update `settings.json`.
  </Accordion>

  <Accordion title="How do I switch back to Anthropic direct?">
    Remove the `env` block from `settings.json` and restore your `ANTHROPIC_API_KEY`. The gateway is a proxy — removing it has no side effects.

    You can also set env vars in your shell profile as an alternative to `settings.json`:

    ```bash theme={null}
    export ANTHROPIC_BASE_URL="https://aigateway.leanmcp.com/v1/anthropic"
    export ANTHROPIC_AUTH_TOKEN="leanmcp_your_api_key_here"
    export ANTHROPIC_API_KEY=""
    ```
  </Accordion>
</AccordionGroup>

***

## Next steps

<CardGroup cols={2}>
  <Card title="View your logs" icon="chart-line" href="https://app.leanmcp.com/observability">
    Open the dashboard to see your Claude Code sessions.
  </Card>

  <Card title="Observability features" icon="eye" href="/ai-gateway/observability">
    What gets logged, sensitive data detection, export options, and alerts.
  </Card>

  <Card title="Use with other tools" icon="grid-2" href="/ai-gateway/for-personal-users">
    Also using Cursor, Windsurf, or Cline? Connect them all to the same gateway.
  </Card>

  <Card title="For teams" icon="users" href="/ai-gateway/for-developers">
    Route your whole team through a shared gateway.
  </Card>
</CardGroup>
