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

# Claude Code

> Configure the Claude Code CLI to route Anthropic Claude Opus and Sonnet requests through Venice for private, usage-based coding agent inference.

[Claude Code](https://docs.anthropic.com/en/docs/claude-code) is Anthropic's CLI tool for agentic coding. This guide shows you how to run it through Venice AI for pay-per-token access to Claude Opus 4.5/4.6 and Sonnet 4.5/4.6.

<CardGroup cols={3}>
  <Card title="Pay Per Token" icon="coins">
    No subscription. Pay only for what you use
  </Card>

  <Card title="Claude Models" icon="microchip">
    Access Opus 4.5/4.6 and Sonnet 4.5/4.6 through Venice
  </Card>

  <Card title="Prompt Caching" icon="bolt">
    Venice caching works alongside Claude Code
  </Card>
</CardGroup>

## Why You Need a Router

Claude Code connects directly to Anthropic's API by default. To use it with Venice, you need [claude-code-router](https://github.com/musistudio/claude-code-router), an open-source local proxy that:

<Steps>
  <Step title="Intercepts" icon="hand">
    Catches Claude Code's outgoing requests before they reach Anthropic
  </Step>

  <Step title="Transforms" icon="arrows-rotate">
    Converts request format and maps model IDs (e.g., `claude-opus-4-5`)
  </Step>

  <Step title="Redirects" icon="route">
    Forwards requests to Venice at `api.venice.ai/api/v1/chat/completions`
  </Step>
</Steps>

***

## Prerequisites

<CardGroup cols={3}>
  <Card title="Venice Account" icon="user" href="https://venice.ai/settings/api">
    With API credits
  </Card>

  <Card title="Node.js" icon="node-js" href="https://nodejs.org/">
    v18 or higher
  </Card>

  <Card title="Claude Code" icon="terminal" href="https://docs.anthropic.com/en/docs/claude-code">
    Installed via npm
  </Card>
</CardGroup>

***

## Setup

<Steps>
  <Step title="Install Claude Code">
    If you haven't already, install Anthropic's Claude Code CLI:

    ```bash theme={"system"}
    npm install -g @anthropic-ai/claude-code
    ```
  </Step>

  <Step title="Install the Router">
    ```bash theme={"system"}
    npm install -g @musistudio/claude-code-router
    ```
  </Step>

  <Step title="Get Your API Key">
    Generate a key from [venice.ai/settings/api](https://venice.ai/settings/api). You'll paste it directly in the config file in the next step.
  </Step>

  <Step title="Create Configuration">
    Create the config directory:

    ```bash theme={"system"}
    mkdir -p ~/.claude-code-router
    ```

    Then create `~/.claude-code-router/config.json` with your preferred editor:

    ```bash theme={"system"}
    # Using nano
    nano ~/.claude-code-router/config.json

    # Or using VS Code
    code ~/.claude-code-router/config.json
    ```

    Paste the following configuration:

    ```json theme={"system"}
    {
      "APIKEY": "",
      "LOG": true,
      "LOG_LEVEL": "info",
      "API_TIMEOUT_MS": 600000,
      "HOST": "127.0.0.1",
      "Providers": [
        {
          "name": "venice",
          "api_base_url": "https://api.venice.ai/api/v1/chat/completions",
          "api_key": "your-venice-api-key-here",
          "models": [
            "claude-opus-4-5",
            "claude-sonnet-4-5",
            "claude-opus-4-6",
            "claude-opus-4-6-fast",
            "claude-sonnet-4-6"
          ],
          "transformer": {
            "use": ["anthropic"]
          }
        }
      ],
      "Router": {
        "default": "venice,claude-opus-4-5",
        "think": "venice,claude-opus-4-5",
        "background": "venice,claude-opus-4-5",
        "longContext": "venice,claude-opus-4-5",
        "longContextThreshold": 100000
      }
    }
    ```

    <Note>
      If you modify `config.json` while the router is running, restart it with `ccr restart` to apply changes.
    </Note>
  </Step>

  <Step title="Launch">
    Start the router, then Claude Code:

    ```bash theme={"system"}
    ccr start
    ccr code
    ```

    Or use the activation method:

    ```bash theme={"system"}
    eval "$(ccr activate)" && claude
    ```
  </Step>
</Steps>

***

## Supported Models

| Model                | Venice ID              | Best For                             |
| -------------------- | ---------------------- | ------------------------------------ |
| Claude Opus 4.5      | `claude-opus-4-5`      | Complex reasoning, large refactors   |
| Claude Sonnet 4.5    | `claude-sonnet-4-5`    | Fast iteration, everyday coding      |
| Claude Opus 4.6      | `claude-opus-4-6`      | Complex reasoning, large refactors   |
| Claude Opus 4.6 Fast | `claude-opus-4-6-fast` | Complex reasoning with lower latency |
| Claude Sonnet 4.6    | `claude-sonnet-4-6`    | Fast iteration, everyday coding      |

<Info>
  Claude Code is optimized for Claude models. While other models available through Venice (GPT, DeepSeek, Grok, etc.) may work, we cannot guarantee an equivalent experience since Claude Code relies on Claude-specific features like extended thinking. For other models, consider using Venice's [standard API](/api-reference/endpoint/chat/completions).
</Info>

***

## Router Features

The router provides several useful features beyond basic routing:

<AccordionGroup>
  <Accordion title="Switch models on the fly">
    Use the `/model` command inside Claude Code to switch models without restarting:

    ```
    /model venice,claude-sonnet-4-5
    ```

    Useful when you want Opus for complex tasks and Sonnet for quick iterations.
  </Accordion>

  <Accordion title="Visual configuration with UI mode">
    Prefer a GUI? Launch the web-based config editor:

    ```bash theme={"system"}
    ccr ui
    ```

    This opens a browser interface for editing your `config.json` without touching the file directly.
  </Accordion>

  <Accordion title="Router scenarios explained">
    The `Router` config section controls which model handles different task types:

    | Scenario      | When it's used                                     |
    | ------------- | -------------------------------------------------- |
    | `default`     | General requests                                   |
    | `think`       | Reasoning-heavy tasks (Plan Mode)                  |
    | `background`  | Background operations                              |
    | `longContext` | When context exceeds `longContextThreshold` tokens |

    You can route different scenarios to different models. For example, use Sonnet for background tasks to save costs.
  </Accordion>

  <Accordion title="Debugging with logs">
    If something isn't working, check the logs:

    ```bash theme={"system"}
    # Server logs (HTTP, API calls)
    ~/.claude-code-router/logs/ccr-*.log

    # Application logs (routing decisions)
    ~/.claude-code-router/claude-code-router.log
    ```

    Set `"LOG_LEVEL": "debug"` in your config for more verbose output.
  </Accordion>
</AccordionGroup>

***

## Caching Behavior

Venice [prompt caching](/guides/features/prompt-caching) works alongside Claude Code's native cache markers. Venice automatically detects when Claude Code sends `cache_control` fields and adjusts its caching strategy accordingly.

| Scenario                      | Cache TTL | Who Controls         |
| ----------------------------- | --------- | -------------------- |
| Default (recommended)         | 5 minutes | Claude Code + Venice |
| With `cleancache` transformer | 1 hour    | Venice only          |

<AccordionGroup>
  <Accordion title="When NOT to use cleancache (most users)">
    The default configuration lets both systems cooperate:

    * Claude Code sends its native `cache_control` markers
    * Venice adds caching around them with a 5-minute TTL
    * Both systems share the 4-block cache limit

    This works well for active coding sessions where you're making frequent requests.
  </Accordion>

  <Accordion title="When to use cleancache">
    Add `cleancache` to the transformer if you:

    * Are hitting the 4-block cache limit errors
    * Experience strange caching behavior
    * Prefer Venice's 1-hour TTL for longer sessions

    ```json theme={"system"}
    "transformer": {
      "use": ["anthropic", "cleancache"]
    }
    ```

    This strips Claude Code's cache markers, giving Venice full control with a longer TTL.
  </Accordion>
</AccordionGroup>

***

## Resources

<CardGroup cols={2}>
  <Card title="Venice API Docs" icon="book" href="/api-reference/api-spec">
    Full API reference
  </Card>

  <Card title="claude-code-router" icon="github" href="https://github.com/musistudio/claude-code-router">
    Source code and issues
  </Card>
</CardGroup>
