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 documentation for installation instructions, or run:
npm install -g @anthropic-ai/claude-code
Do NOT use sudo npm install -g as this can lead to permission issues and security risks. If you encounter permission errors, see the Claude Code setup guide for recommended solutions.
For detailed setup instructions, see the Claude Code setup guide.
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.):
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:
{
"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.