Claude Code (API Key Integration)

Powering Claude Code with XAI

Tip: If you prefer official account integration (instead of API keys), see:
Claude Code via official account
OpenAI Codex via official account

Claude Code is a powerful coding assistant from Anthropic. It runs directly in your terminal to help you write, explain, and refactor code.

By default, using Claude Code requires logging into an official Claude account and purchasing a subscription. Fortunately, it supports configuration of a custom API endpoint, which allows us to use a third-party API router and your own API key to make calls.

System Requirements

Operating Systems:

  • macOS 10.15+
  • Ubuntu 20.04+/Debian 10+
  • Windows 10+ (with WSL 1, WSL 2, or Git for Windows)

Hardware:

  • 4GB+ RAM minimum
  • Internet connection for authentication and AI processing
  • Compatible shells: Bash, Zsh, or Fish

Install Claude Code

Official recommended native binary installation with no Node.js dependency and built-in auto-update functionality.

macOS/Linux via Homebrew:

brew install --cask claude-code

macOS/Linux/WSL via Installation Script:

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

Windows PowerShell:

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

Windows CMD:

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

Install Specific Version

# Install stable (default)
curl -fsSL https://claude.ai/install.sh | bash

# Install latest
curl -fsSL https://claude.ai/install.sh | bash -s latest

# Install specific version (e.g., 1.0.58)
curl -fsSL https://claude.ai/install.sh | bash -s 1.0.58

Verify Installation

After installation, run the following command to verify:

claude doctor

This will check your installation type and version information.

Configure API Key and Endpoint

Using Environment Variables:

export ANTHROPIC_BASE_URL=https://api.xaicontrol.com
export ANTHROPIC_API_KEY=sk-Xvsq8CfsL3JLgptWYdkRJimo2Wmsgd829q50GVBhk12LxYmf

Update Claude Code

Auto-Updates:

  • Claude Code checks for updates on startup and periodically
  • Updates download and install automatically in the background
  • Takes effect on next launch

Disable Auto-Updates:

export DISABLE_AUTOUPDATER=1

Manual Update:

claude update

Usage Guide

Once configured, you can directly use the claude command in your terminal to interact with the AI.

Example 1: Writing Code

You can directly make a coding request to Claude Code, and it will return the result in a streaming fashion.

claude "write a python flask app with a single endpoint that returns hello world"

Claude Code will immediately start generating the code and related explanations, which you can see directly in your terminal's output.

Example 2: Explaining Code

If you have a piece of code you don't understand, you can pass it to Claude Code for an explanation using a pipe.

cat my_script.js | claude "explain this javascript code"

Example 3: Interactive Session

Running the claude command by itself will start an interactive session where you can have a multi-turn conversation.

claude
> How can I help you today?
> write a git command to show the commit history of a specific file

For more information or help, please refer to the following online resources: