Skip to Content
CLI agentsClaude Code CLI

Claude Code CLI

This guide shows how to install and configure Claude Code CLI with Infer.

Claude Code is Anthropic’s terminal coding agent. It reads its endpoint and credentials from environment variables, so pointing it at Infer is just a handful of exports — no patches, wrappers, or forks.

Warning:

For Claude Code, use Claude-family models only (claude-opus-*, claude-sonnet-*, claude-haiku-* from the Models page). Claude Code talks to Infer via the Anthropic Messages API; routing OpenAI- or Gemini-family models through that path may fail or behave unexpectedly. Keep this in mind whenever you set ANTHROPIC_MODEL or any of the role-specific model variables in step 2.

Quick Start

1. Install Claude Code CLI

Run Anthropic's native installer (macOS, Linux, WSL).

bash
curl -fsSL https://claude.ai/install.sh | bash

On Windows PowerShell:

PowerShell installer for Windows.

powershell
irm https://claude.ai/install.ps1 | iex

Or via npm (Node.js 18 or later):

Alternative install via npm — needs Node.js 18 or later.

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

Once the installer finishes, verify the binary is on your PATH:

bash
claude --version

A successful install prints a single line like 1.x.y (Claude Code) (the exact version varies). If you see claude: command not found, re-open your terminal so the new PATH entry is picked up, or follow the installer’s manual PATH instructions.

2. Connect Claude Code CLI to Infer

Claude Code reads its endpoint and credentials from these four environment variables:

  • ANTHROPIC_BASE_URL — the Infer Anthropic-compatible endpoint.
  • ANTHROPIC_AUTH_TOKEN — your Infer API key.
  • ANTHROPIC_API_KEY — must be set to an empty string. If it has any value, Claude Code prefers it over ANTHROPIC_AUTH_TOKEN and falls back to api.anthropic.com.
  • ANTHROPIC_MODEL — the default model. Required because Claude Code’s built-in default may not be served by Infer.

Pick the path that matches what you want

There are four ways to make Claude Code see those four values. Skim the table, then jump to the matching subsection below.

You want…Use this methodScope
A one-shot test (CI, multi-account swap)Inline at launchJust this one claude invocation
The current shell only (kick the tires)Export in current sessionUntil you close this terminal
A specific projectRepo-scoped settings fileInside one project directory
Every Claude Code session, everywhereShell profile or user-scoped settings fileAll terminals, all projects

If you are not sure, start with 2.1 Inline at launch to confirm the connection works, then come back and add the 2.3 shell profile version once you are happy.

2.1 Inline at launch (one-shot)

Prepend the variables to a single claude invocation. Nothing is persisted; close the terminal and the values are gone.

bash
ANTHROPIC_BASE_URL="https://api-agenthub-pre.riema.xyz" ANTHROPIC_AUTH_TOKEN="your_api_key" ANTHROPIC_API_KEY="" ANTHROPIC_MODEL="claude-opus-4-6" claude

2.2 Export in the current shell

Run the exports once in this terminal. Other terminals (and a fresh login) will not see them.

Copy, replace the key, and load it in your shell or shell profile.

bash
export INFER_API_KEY="your_api_key"
export ANTHROPIC_BASE_URL="https://api-agenthub-pre.riema.xyz"
export ANTHROPIC_AUTH_TOKEN="$INFER_API_KEY"
export ANTHROPIC_API_KEY=""  # Important: must be explicitly empty
export ANTHROPIC_MODEL="claude-opus-4-6"

2.3 Shell profile (global, persistent)

Append the same exports to your shell startup file (~/.zshrc for zsh, ~/.bashrc for bash) so every new shell picks them up automatically.

Copy, replace the key, and load it in your shell or shell profile.

bash
export INFER_API_KEY="your_api_key"
export ANTHROPIC_BASE_URL="https://api-agenthub-pre.riema.xyz"
export ANTHROPIC_AUTH_TOKEN="$INFER_API_KEY"
export ANTHROPIC_API_KEY=""  # Important: must be explicitly empty
export ANTHROPIC_MODEL="claude-opus-4-6"

Then reload the profile in this terminal — newly-opened terminals get it for free.

bash
source ~/.zshrc  # or: source ~/.bashrc

2.4 Settings file (Claude-Code-only, per project or per user)

Persist the same values inside a JSON file Claude Code reads on every launch — no shell configuration needed. Two scopes:

  • ~/.claude/settings.json — applies to every Claude Code session for this user.
  • .claude/settings.json inside a project — applies only when Claude Code is launched from that project directory; overrides user-scope.
jsonc
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api-agenthub-pre.riema.xyz",
    "ANTHROPIC_AUTH_TOKEN": "your_api_key",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_MODEL": "claude-opus-4-6"
  }
}
Warning:

Do not add /v1 to ANTHROPIC_BASE_URL. Claude Code appends the Anthropic API path itself. This is the opposite of Codex and OpenCode, which expect the /v1 suffix on OPENAI_BASE_URL.

3. Start your session

Launch Claude Code from a shell where the configuration is in effect.

bash
cd your-project
claude

4. Verify

Send a one-shot prompt from a shell where the four env vars (or the settings file) are in effect:

bash
claude "Reply with 'ok' if you can see this."

You have a working setup if all three of the checks below hold:

  1. Claude Code returns a normal answer. A reply such as ok (or any natural-language sentence) — not an error, not an interactive sign-in prompt — means the request reached Infer and a model responded.
  2. The active model is the Claude-family model you set. Inside an interactive claude session, run /status — the active model line should match your ANTHROPIC_MODEL (for example, claude-opus-4-6). If you see a different model or api.anthropic.com, the env vars did not load (re-check Step 2).
  3. The call shows up in Infer usage. Open the Usage page; the request and its token count should appear within a few seconds, and your available balance on the Billing page should update according to the request cost.

If you only see #1 but not #2 or #3, Claude Code is still talking to Anthropic directly — most often because ANTHROPIC_API_KEY is non-empty and outranking ANTHROPIC_AUTH_TOKEN. Empty it and try again.

How It Works

Claude Code talks to the Anthropic Messages API directly — ${ANTHROPIC_BASE_URL}/v1/messages. Infer is Anthropic-compatible at that endpoint, so Claude Code reaches Infer exactly the way it would reach api.anthropic.com. Usage is billed against your selected team’s balance and shows up in the dashboard. Reminder: use Claude-family models only; see the warning at the top of this page.

Configuring Models (optional, advanced)

You only need ANTHROPIC_MODEL to get started. If you followed step 2, you have already set it and Claude Code will route every request to that single model — you can stop here and skip the rest of this section.

The role-specific variables below are optional advanced settings for users who want different models for different jobs (for example, Opus for planning, Haiku for background work). They sit alongside the same ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN / empty ANTHROPIC_API_KEY setup — they only override which model is used, never how Claude Code authenticates.

VariableRoleRequired?
ANTHROPIC_MODELMain session model.Yes
ANTHROPIC_DEFAULT_OPUS_MODELDefault when Claude Code routes to the Opus tier (/opus, planning).Optional
ANTHROPIC_DEFAULT_SONNET_MODELDefault when Claude Code routes to the Sonnet tier (/sonnet).Optional
ANTHROPIC_DEFAULT_HAIKU_MODELDefault when Claude Code routes to the Haiku tier.Optional
ANTHROPIC_SMALL_FAST_MODELBackground work — message titles, summarization, agent loops.Optional

Optional: assign a specific Infer model to each role Claude Code routes to. The main session uses `ANTHROPIC_MODEL`; subagents and tier-specific commands fall back to the variables below.

bash
# Main session model (required)
export ANTHROPIC_MODEL="claude-opus-4-6"

# Tier-specific defaults (used by /opus, /sonnet, /haiku and similar)
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5-20251001"

# Background work (titles, summarization, agent loops)
export ANTHROPIC_SMALL_FAST_MODEL="claude-haiku-4-5-20251001"

All values must be Claude-family model IDs listed on the Models page (case-sensitive).

Troubleshooting

Troubleshooting

Authentication error (401 Unauthorized)
Confirm `echo $ANTHROPIC_AUTH_TOKEN` returns your Infer key in the shell that launched Claude Code, and `echo $ANTHROPIC_API_KEY` is empty. If `ANTHROPIC_API_KEY` has any value, Claude Code uses it instead of `ANTHROPIC_AUTH_TOKEN` and the request is rejected. If you edited your shell profile but skipped `source ~/.zshrc` (or `~/.bashrc`), the new values are not yet loaded — reload the profile or open a fresh terminal.
Want a different model?
We pin `ANTHROPIC_MODEL` to `claude-opus-4-6` because Claude Code's built-in default may not be served by Infer. To use a different model, set `ANTHROPIC_MODEL` to any Claude-family ID from the Infer Models page (IDs are case-sensitive), or switch models inside Claude Code.
404 on /v1/messages
ANTHROPIC_BASE_URL must NOT include the `/v1` suffix — Claude Code appends it automatically. Copy the URL shown in the Base URL section above.
Last updated on