first commit
This commit is contained in:
242
docs/cli-agents/claude-code.mdx
Normal file
242
docs/cli-agents/claude-code.mdx
Normal file
@@ -0,0 +1,242 @@
|
||||
---
|
||||
title: "Claude Code"
|
||||
description: "Use Claude Code with Bifrost to route through any provider and unlock advanced features like MCP tools and observability."
|
||||
icon: "star-of-life"
|
||||
---
|
||||
|
||||
[Claude Code](https://www.claude.com/product/claude-code) brings AI-powered coding capabilities directly to your terminal.
|
||||
|
||||
<Note>
|
||||
If your Allowed Headers are already set to `*`, you can skip this note. If not and you face issues integrating Bifrost
|
||||
with Claude Code, try switching to `*` or adding the specific headers required by your client. By default, Bifrost
|
||||
whitelists: `Content-Type`, `Authorization`, `X-Requested-With`, `X-Stainless-Timeout`, and `X-Api-Key`.
|
||||
</Note>
|
||||
|
||||
## To install Claude code
|
||||
|
||||
```bash
|
||||
npm install -g @anthropic-ai/claude-code
|
||||
```
|
||||
|
||||
## Configuring Claude Code to work with Bifrost
|
||||
|
||||
Claude Code supports multiple authentication methods. Choose the one that matches your account type.
|
||||
|
||||
1. **Set environment variables**
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_KEY=your-bifrost-virtual-key # or "dummy" if virtual keys are not enabled
|
||||
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic
|
||||
```
|
||||
|
||||
2. **Run Claude Code**
|
||||
|
||||
```bash
|
||||
claude
|
||||
```
|
||||
|
||||
## Setup with the VS Code extension
|
||||
|
||||
If you prefer using Claude Code inside VS Code, install the [Claude Code extension](https://marketplace.visualstudio.com/items?itemName=anthropic.claude-code) and point it to Bifrost using the same environment variables you use for the CLI.
|
||||
|
||||
### 1. Install the extension
|
||||
|
||||
1. Open **Extensions** in VS Code (`Cmd+Shift+X` on macOS)
|
||||
2. Search for **Claude Code**
|
||||
3. Install **Claude Code** by Anthropic
|
||||
|
||||
### 2. Configure Bifrost endpoint
|
||||
|
||||
Add Bifrost variables in your editor settings:
|
||||
|
||||
```json
|
||||
{
|
||||
"claudeCode.disableLoginPrompt": true,
|
||||
"claudeCode.environmentVariables": [
|
||||
{
|
||||
"name": "ANTHROPIC_BASE_URL",
|
||||
"value": "http://localhost:8080/anthropic"
|
||||
},
|
||||
{
|
||||
"name": "ANTHROPIC_DEFAULT_SONNET_MODEL",
|
||||
"value": "vertex/claude-sonnet-4-6"
|
||||
},
|
||||
{
|
||||
"name": "ANTHROPIC_DEFAULT_HAIKU_MODEL",
|
||||
"value": "vertex/claude-haiku-4-5"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
If virtual keys are enabled, also add `ANTHROPIC_API_KEY` in the same list (use your Bifrost virtual key value). If not, set it to `dummy`.
|
||||
|
||||
## Amazon Bedrock via Bifrost
|
||||
|
||||
### Setup
|
||||
|
||||
Configure environment variables
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_KEY=bifrost-virtual-key
|
||||
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic
|
||||
```
|
||||
|
||||
### Pin model versions (recommended)
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_DEFAULT_SONNET_MODEL="bedrock/global.anthropic.claude-sonnet-4-6"
|
||||
export ANTHROPIC_DEFAULT_HAIKU_MODEL="bedrock/global.anthropic.claude-haiku-4-5-20251001-v1:0"
|
||||
```
|
||||
|
||||
If you don't pin using CLI - you can pin these in UI. Go to Dashboard > Models > Model Providers > AWS Bedrock > Key. And add deployments
|
||||
|
||||
<Frame>
|
||||
<img src="/media/cli/claude-bedrock-pinning.png" alt="Claude bedrock pinning" />
|
||||
</Frame>
|
||||
|
||||
### Start Claude Code
|
||||
|
||||
```
|
||||
claude
|
||||
```
|
||||
|
||||
<Warning>
|
||||
Always pin model versions with `ANTHROPIC_DEFAULT_*_MODEL` when using Bedrock. Without pinning, Claude Code aliases
|
||||
resolve to the latest version, which may not be enabled in your Bedrock account.
|
||||
</Warning>
|
||||
|
||||
## Google Vertex AI via Bifrost
|
||||
|
||||
### Setup
|
||||
|
||||
Configure environment variables
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_KEY=bifrost-virtual-key
|
||||
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic
|
||||
```
|
||||
|
||||
### Pin model versions (recommended)
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_DEFAULT_SONNET_MODEL="vertex/claude-sonnet-4-6"
|
||||
export ANTHROPIC_DEFAULT_HAIKU_MODEL="vertex/claude-haiku-4-5"
|
||||
```
|
||||
|
||||
### Start Claude Code
|
||||
|
||||
```
|
||||
claude
|
||||
```
|
||||
|
||||
## Azure via Bifrost
|
||||
|
||||
### Setup
|
||||
|
||||
Configure environment variables
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_KEY=bifrost-virtual-key
|
||||
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic
|
||||
```
|
||||
|
||||
### Pin model versions (recommended)
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_DEFAULT_SONNET_MODEL="azure/claude-sonnet-4-6"
|
||||
export ANTHROPIC_DEFAULT_HAIKU_MODEL="azure/claude-haiku-4-5"
|
||||
```
|
||||
|
||||
You will also have to map these model names to actual deployment names on Bifrost dashboard.
|
||||
|
||||
<Frame>
|
||||
<img src="/media/cli/claude-azure-pinning.png" alt="Claude bedrock pinning" />
|
||||
</Frame>
|
||||
|
||||
### Start Claude Code
|
||||
|
||||
```
|
||||
claude
|
||||
```
|
||||
|
||||
<Warning>
|
||||
Azure-hosted models must support **tool use capabilities** for Claude Code to function properly. Verify tool calling
|
||||
support before configuring Azure models.
|
||||
</Warning>
|
||||
|
||||
## Model Configuration
|
||||
|
||||
Claude Code uses three model tiers: **Sonnet** (default), **Opus** (complex tasks), and **Haiku** (fast, lightweight). With Bifrost, you can override these defaults to use any model from any provider.
|
||||
|
||||
**Override Default Models:**
|
||||
|
||||
Set environment variables to replace Claude Code's default model tiers with any Bifrost-configured model:
|
||||
|
||||
```bash
|
||||
# Replace Sonnet tier with GPT-5
|
||||
export ANTHROPIC_DEFAULT_SONNET_MODEL="openai/gpt-5"
|
||||
|
||||
# Replace Opus tier with Claude Opus 4.5
|
||||
export ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-4-5-20251101"
|
||||
|
||||
# Replace Haiku tier with Azure-hosted Claude
|
||||
export ANTHROPIC_DEFAULT_HAIKU_MODEL="azure/claude-haiku-4-5"
|
||||
```
|
||||
|
||||
<Warning>
|
||||
Alternative models must support **tool use capabilities** for file operations, terminal commands, and code editing to
|
||||
work properly with Claude Code.
|
||||
</Warning>
|
||||
|
||||
**Start with a Specific Model:**
|
||||
|
||||
Launch Claude Code with a specific model using the `--model` flag:
|
||||
|
||||
```bash
|
||||
# Start with Opus
|
||||
claude --model claude-opus-4-5-20251101
|
||||
|
||||
# Start with Haiku for lightweight tasks
|
||||
claude --model claude-haiku-4-5-20251001
|
||||
```
|
||||
|
||||
## Switching Models Mid-Session
|
||||
|
||||
Use the `/model` command to switch models during an active session:
|
||||
|
||||
```bash
|
||||
# Using full model names
|
||||
/model claude-opus-4-5-20251101 # This will be used from anthropic provider
|
||||
/model claude-sonnet-4-5-20250929 # This will be used from anthropic provider
|
||||
|
||||
# Using different providers dynamically via Bifrost
|
||||
/model vertex/claude-haiku-4-5
|
||||
/model azure/claude-sonnet-4-5
|
||||
/model bedrock/claude-sonnet-4-5
|
||||
```
|
||||
|
||||
<Tip>
|
||||
Run `/model` without arguments to check your current model. The switch is instantaneous and Claude Code seamlessly
|
||||
continues your conversation context with the new model.
|
||||
</Tip>
|
||||
|
||||
<Warning>
|
||||
If you use Claude-specific features like **web search**, **computer use**, or **citations**, ensure the model you
|
||||
switch to also supports these capabilities. Non-Claude models or Claude models on certain providers may not support
|
||||
all features.
|
||||
</Warning>
|
||||
|
||||
## Provider Compatibility
|
||||
|
||||
<Warning>
|
||||
**Not all providers work well with Claude Code**. Since Claude Code heavily relies on tool calling for file operations, terminal commands, and code editing, providers must properly support and stream tool call arguments.
|
||||
|
||||
**Known Issues:**
|
||||
|
||||
- **OpenRouter**: Does not stream function call arguments properly. Tool calls return with empty `arguments` fields, causing Claude Code to fail when attempting file operations or other tool-based actions.
|
||||
- **Some proxy providers**: May not fully implement the Anthropic API streaming specification for tool calls.
|
||||
|
||||
If you experience issues with tool calls not executing properly, try switching to a different provider in your Bifrost configuration.
|
||||
|
||||
</Warning>
|
||||
Reference in New Issue
Block a user