Integrate the Martian Code Router With Claude Code
This document describes how to set up Claude Code to route all your LLM requests through Martian.
Ensure you have your Martian API key from the Martian Dashboard before continuing.
Prerequisites
Ensure you have Claude Code installed. See the Claude Code quickstart for more options, or use one of the following:
curl -fsSL https://claude.ai/install.sh | bash
Configuration
Choose one of the following configuration methods:
Option 1: Global Configuration
This configuration applies to all projects using Claude Code.
Step 1: Store Your API Key
Add your Martian API key to your shell profile (~/.zshrc, ~/.bashrc, etc.) or a secure location like a .env file:
# Add to ~/.zshrc, ~/.bashrc, etc.
export MARTIAN_API_KEY="your-martian-api-key"
Replace your-martian-api-key with your actual Martian API key from the Martian Dashboard.
Then reload your shell:
source ~/.zshrc # or source ~/.bashrc etc.
Step 2: Create Global Claude Code Configuration
Create or edit ~/.claude/settings.json with the following content:
You can also add the API key directly in the config file by using "apiKey": "your-martian-api-key" instead of apiKeyHelper. However, using apiKeyHelper with an environment variable is recommended for security.
{
"apiKeyHelper": "echo $MARTIAN_API_KEY",
"env": {
"ANTHROPIC_BASE_URL": "https://api.withmartian.com"
},
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)"
]
}
}
Option 2: Per-Project Configuration
This configuration applies only to a specific project directory.
Step 1: Store Your API Key
Create a .env file in your project root:
echo "MARTIAN_API_KEY=your-martian-api-key" >> .env
echo ".env" >> .gitignore
Replace your-martian-api-key with your actual Martian API key from the Dashboard.
Step 2: Create Project Claude Code Configuration
Create a .claude directory and add the configuration file:
mkdir .claude
Create .claude/settings.local.json with the following content:
{
"apiKeyHelper": "source .env && echo $MARTIAN_API_KEY",
"env": {
"ANTHROPIC_BASE_URL": "https://api.withmartian.com"
},
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)"
]
}
}
Per-project settings override global settings. Use this option if you need different configurations for different projects.
Start Using Claude Code
Navigate to your project directory and start Claude Code:
cd your-project
claude
Claude Code will now route all requests through Martian.