> For the complete documentation index, see [llms.txt](https://docs.tensorx.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorx.ai/ai-coding-assistants/claude-code-cli.md).

# Claude Code CLI

Claude Code is Anthropic's terminal-based coding assistant. TensorX provides an Anthropic-compatible endpoint for Claude Code and operates with zero data retention on EU-hosted infrastructure.

## Prerequisites

* Node.js 18 or newer
* A TensorX API key ([get one here](https://app.tensorx.ai))
* Terminal access (macOS, Linux, or Windows with WSL)

## Installation

Install Claude Code globally:

```bash
npm install -g @anthropic-ai/claude-code
```

Verify installation:

```bash
claude --version
```

***

## Quick Start - No Account Required

For quick queries and scripting, use **print mode** which doesn't require any Anthropic account.

Choose a model ID returned by `GET /v1/models`, then export it with the TensorX endpoint and key:

```bash
export TENSORX_MODEL="<MODEL_ID>"
export ANTHROPIC_API_KEY="<YOUR_TENSORX_API_KEY>"
export ANTHROPIC_BASE_URL="https://api.tensorx.ai"
export ANTHROPIC_MODEL="$TENSORX_MODEL"

claude -p "Explain what a REST API is"
```

{% hint style="info" %}
Print mode (`-p`) outputs the response and exits. For interactive development sessions with file editing and bash commands, see **Interactive Mode Setup** below.
{% endhint %}

***

## Interactive Mode Setup

Interactive mode provides the full Claude Code experience with file editing, bash commands, and multi-turn conversations. Requires **one-time** free Anthropic account setup.

### Step 1: Initial Setup (One-Time Only)

Run `claude` and complete the OAuth login:

```bash
claude
```

Select **"Anthropic Console account"** when prompted and follow the browser login. A free Anthropic account works - you won't be charged by Anthropic as all requests route through TensorX.

### Step 2: Configure TensorX

Create or edit `~/.claude/settings.json`:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.tensorx.ai",
    "ANTHROPIC_AUTH_TOKEN": "<YOUR_TENSORX_API_KEY>",
    "ANTHROPIC_MODEL": "<MODEL_ID>",
    "ANTHROPIC_SMALL_FAST_MODEL": "<MODEL_ID>",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "<MODEL_ID>",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "<MODEL_ID>",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "<MODEL_ID>",
    "API_TIMEOUT_MS": "3000000",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}
```

Replace `<MODEL_ID>` with an ID returned by `GET /v1/models`.

### Step 3: Start Using Claude Code

Navigate to your project and run:

```bash
cd /path/to/your/project
claude
```

{% hint style="warning" %}
You may see an authentication-conflict warning. With the environment above, model requests route through TensorX.
{% endhint %}

### Why All Model Variables Are Required

Claude Code uses different models for different internal tasks:

| Variable                         | Purpose                             |
| -------------------------------- | ----------------------------------- |
| `ANTHROPIC_MODEL`                | Main model for conversations        |
| `ANTHROPIC_SMALL_FAST_MODEL`     | Quick background tasks              |
| `ANTHROPIC_DEFAULT_HAIKU_MODEL`  | Token counting and small operations |
| `ANTHROPIC_DEFAULT_SONNET_MODEL` | Standard coding tasks               |
| `ANTHROPIC_DEFAULT_OPUS_MODEL`   | Complex reasoning tasks             |

{% hint style="danger" %}
If these variables are not all set, Claude Code may request Anthropic model IDs that are not returned by TensorX, causing model-not-found errors.
{% endhint %}

***

## Model selection

Call `GET /v1/models` with your TensorX API key and use one of the returned IDs. If the integration depends on a capability or token limit, query `GET /v1/model/info` before selecting the model. See [Models](/api-reference/models.md) for examples.

***

## Switching Models

To switch models, update **all** model variables in `~/.claude/settings.json`:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.tensorx.ai",
    "ANTHROPIC_AUTH_TOKEN": "<YOUR_TENSORX_API_KEY>",
    "ANTHROPIC_MODEL": "<MODEL_ID>",
    "ANTHROPIC_SMALL_FAST_MODEL": "<MODEL_ID>",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "<MODEL_ID>",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "<MODEL_ID>",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "<MODEL_ID>",
    "API_TIMEOUT_MS": "3000000",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}
```

Replace `<MODEL_ID>` with your chosen TensorX model ID.

After editing, **start a new Claude Code session** for changes to take effect.

***

## Troubleshooting

### Anthropic model not found

**Solution:** You haven't set all model aliases. Ensure your `settings.json` includes:

* `ANTHROPIC_DEFAULT_HAIKU_MODEL`
* `ANTHROPIC_DEFAULT_SONNET_MODEL`
* `ANTHROPIC_DEFAULT_OPUS_MODEL`
* `ANTHROPIC_SMALL_FAST_MODEL`

All should be set to your chosen TensorX model.

### Auth conflict warning

**Message:** `Auth conflict: Both a token (ANTHROPIC_AUTH_TOKEN) and an API key...`

**Solution:** This warning is normal and can be ignored. Claude Code is using your `ANTHROPIC_AUTH_TOKEN` from `settings.json` which points to TensorX. Your requests are routing correctly.

### OAuth login still required after configuration

**Solution:** Interactive mode requires a one-time Anthropic OAuth. This is a Claude Code requirement. After completing it once, your `settings.json` config will route all actual API requests through TensorX.

For scripting without OAuth, use print mode: `claude -p "your prompt"`

### Configuration not taking effect

**Solution:**

1. Close all Claude Code sessions
2. Verify `~/.claude/settings.json` has correct JSON syntax
3. Open a new terminal window
4. Run `claude` again

### Timeout errors

**Solution:** Increase `API_TIMEOUT_MS` in your `settings.json`:

```json
{
  "env": {
    "API_TIMEOUT_MS": "6000000"
  }
}
```

***

## FAQ

**Q: Do I need an Anthropic account?**

For interactive mode, yes - a free account for one-time OAuth. For print mode (`-p` flag), no account is needed.

**Q: Will I be charged by Anthropic?**

No. All API requests route through TensorX. The Anthropic OAuth is only for authentication, not billing.

**Q: Why do I need to set all the model variables?**

Claude Code uses different models for different internal tasks (token counting, background operations, etc.). Setting all aliases ensures everything routes to your chosen TensorX model.

**Q: Can I use different models for different tasks?**

Yes. Each variable can reference a different TensorX model ID.

**Q: What's the difference between ANTHROPIC\_API\_KEY and ANTHROPIC\_AUTH\_TOKEN?**

Both work, but `ANTHROPIC_AUTH_TOKEN` is preferred for custom endpoints. Use `ANTHROPIC_AUTH_TOKEN` in `settings.json`.

**Q: Does TensorX support the Anthropic Messages API (`/v1/messages`)?**

Yes. TensorX exposes an Anthropic-compatible `/v1/messages` endpoint at `https://api.tensorx.ai`, which is what Claude Code targets when you set `ANTHROPIC_BASE_URL`. Standard per-key rate limits apply (see [Rate Limits](/api-reference/rate-limits.md)); there is no separate endpoint to enable.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tensorx.ai/ai-coding-assistants/claude-code-cli.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
