Setup Claude Intermediate

Use Claude Code with Custom and Local Models

Route Claude Code to Moonshot, AWS Bedrock, or your own local model

2 of 66

Why route Claude Code elsewhere?

Claude Code is hard-coded to talk to Anthropic by default, but it uses the standard Anthropic SDK under the hood. That means you can point it at any provider that speaks the same protocol: third-party APIs, AWS Bedrock, or a local server like LM Studio.

This is useful when:

  • You have credits or quota with another provider
  • You want to keep everything on your machine
  • Your company requires AWS Bedrock for compliance

Moonshot / Kimi setup

Set these environment variables before running claude:

export ANTHROPIC_BASE_URL=https://api.moonshot.ai/anthropic
export ANTHROPIC_AUTH_TOKEN=sk-your-moonshot-key
export ANTHROPIC_MODEL=kimi-k2-thinking-turbo
export ANTHROPIC_DEFAULT_OPUS_MODEL=kimi-k2-thinking-turbo
export ANTHROPIC_DEFAULT_SONNET_MODEL=kimi-k2-thinking-turbo
export ANTHROPIC_DEFAULT_HAIKU_MODEL=kimi-k2-thinking-turbo
export CLAUDE_CODE_SUBAGENT_MODEL=kimi-k2-thinking-turbo
export ENABLE_TOOL_SEARCH=false

ANTHROPIC_AUTH_TOKEN is used instead of ANTHROPIC_API_KEY because Moonshot expects its own bearer token. ENABLE_TOOL_SEARCH=false disables the built-in tool search feature that is not supported on non-Anthropic endpoints.

AWS Bedrock setup

Make sure your machine is configured with AWS credentials:

aws configure

Then tell Claude Code to use Bedrock:

export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL="us.anthropic.claude-sonnet-4-20250514-v1:0"

Costs show up in AWS Cost Explorer, not in the Anthropic console.

Option 2: AWS + token (cross-account or explicit role)

If you need to assume a role or use temporary credentials, set them directly:

export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
export AWS_REGION=us-east-1
export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL="us.anthropic.claude-sonnet-4-20250514-v1:0"

Use the model ARN or Bedrock model ID your account has access to.

Local model with LM Studio

Start LM Studio and enable server mode, usually at:

http://localhost:1234/v1

Then point Claude Code at it:

export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
export ANTHROPIC_MODEL=local-model
export CLAUDE_CODE_SUBAGENT_MODEL=local-model
export ENABLE_TOOL_SEARCH=false

The token can be any non-empty string. LM Studio ignores it.

Make settings persistent

Add the exports for your chosen provider to ~/.zshrc or ~/.bashrc. For per-project switching, create a small alias or a .env file you source before starting Claude Code.

Example helper alias for Moonshot:

alias claude-kimi='export ANTHROPIC_BASE_URL=https://api.moonshot.ai/anthropic && export ANTHROPIC_AUTH_TOKEN=sk-your-moonshot-key && export ANTHROPIC_MODEL=kimi-k2-thinking-turbo && export ENABLE_TOOL_SEARCH=false && claude'

Common issues

IssueFix
401 UnauthorizedCheck that you used ANTHROPIC_AUTH_TOKEN for Moonshot/LM Studio, not ANTHROPIC_API_KEY
404 Not FoundVerify the base URL ends in /anthropic for Moonshot or /v1 for LM Studio
Slow or truncated responsesReduce --max-thinking-tokens or switch to a smaller model
Tool search errorSet ENABLE_TOOL_SEARCH=false for non-Anthropic endpoints
Bedrock AccessDeniedConfirm the model is enabled in Bedrock Console > Model access
Local model returns garbageLower the context length or use a higher quantization

Validate your setup

Run these before trusting the config for real work:

# 1. Confirm which endpoint Claude Code sees
claude config get apiBaseUrl

# 2. Check the model name
claude config get model

# 3. Send a one-off prompt
claude "say hello and tell me which model you are"

# 4. For local models, disconnect Wi-Fi and try step 3 again

If step 4 works offline, your traffic never left the machine.

Working out which model to run this on? See The Codex. Packaging it as a reusable skill? See The Armory.