Skip to main content
Claude Code uses JSON configuration files for settings and API key approvals. Configuration can be at the system level (global) or project level (local).

Configuration Files

System-Level Configuration

Settings File: ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io",
    "ANTHROPIC_API_KEY": "sk-mega-your-api-key-here"
  }
}
API Key Approvals: ~/.claude.json
{
  "customApiKeyResponses": {
    "approved": ["last-20-chars-of-key"],
    "rejected": []
  }
}
The API key approval file stores the last 20 characters of your API key to remember your approval decision when Claude Code prompts you.

Project-Level Configuration

Settings File: ./.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io",
    "ANTHROPIC_API_KEY": "sk-mega-your-api-key-here"
  }
}
Local Settings (Gitignored): ./.claude/settings.local.json
{
  "env": {
    "ANTHROPIC_API_KEY": "sk-mega-your-personal-key"
  }
}
Use settings.local.json to keep your personal API key out of version control while sharing base configuration with your team.

Environment Variables

The CLI sets these environment variables in your shell configuration:
export ANTHROPIC_BASE_URL="https://ai.megallm.io"
export ANTHROPIC_API_KEY="sk-mega-your-api-key-here"
These are added to:
  • ~/.bashrc (bash)
  • ~/.zshrc (zsh)
  • ~/.config/fish/config.fish (fish)
  • PowerShell profile (Windows)

Verify Environment Variables

echo $ANTHROPIC_BASE_URL
# Output: https://ai.megallm.io

echo $ANTHROPIC_API_KEY
# Output: sk-mega-your-api-key-here

Configuration Priority

Claude Code loads configuration in this order (highest to lowest priority):
1

Environment Variables

ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from your shell
2

Project-Level Local Settings

./.claude/settings.local.json in current directory
3

Project-Level Settings

./.claude/settings.json in current directory
4

System-Level Settings

~/.claude/settings.json in home directory

Statusline Configuration (Optional)

Claude Code supports an enhanced statusline for better terminal UI:
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io",
    "ANTHROPIC_API_KEY": "sk-mega-your-api-key-here"
  },
  "statusline": {
    "enabled": true,
    "components": {
      "directory": true,
      "gitBranch": true,
      "model": true,
      "contextUsage": true,
      "cost": true,
      "sessionTimer": true,
      "tokenAnalytics": true
    }
  }
}
The CLI will prompt you to set this up during configuration.

Manual Setup

If you prefer not to use the CLI:

System-Level Manual Setup

# 1. Create directory
mkdir -p ~/.claude

# 2. Create settings file
cat > ~/.claude/settings.json << 'EOF'
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io",
    "ANTHROPIC_API_KEY": "your-api-key"
  }
}
EOF

# 3. Create API key approval file
cat > ~/.claude.json << 'EOF'
{
  "customApiKeyResponses": {
    "approved": ["last-20-chars-of-your-key"],
    "rejected": []
  }
}
EOF

# 4. Add environment variables to shell config
echo 'export ANTHROPIC_BASE_URL="https://ai.megallm.io"' >> ~/.bashrc
echo 'export ANTHROPIC_API_KEY="your-api-key"' >> ~/.bashrc

# 5. Reload shell
source ~/.bashrc

Project-Level Manual Setup

# 1. Navigate to your project
cd ~/projects/my-project

# 2. Create directory
mkdir -p .claude

# 3. Create settings file (without API key for version control)
cat > .claude/settings.json << 'EOF'
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io"
  }
}
EOF

# 4. Create local settings file (with API key, not committed)
cat > .claude/settings.local.json << 'EOF'
{
  "env": {
    "ANTHROPIC_API_KEY": "your-api-key"
  }
}
EOF

# 5. Add to .gitignore
echo ".claude/settings.local.json" >> .gitignore
echo ".claude.json" >> .gitignore

# 6. Commit shared config
git add .claude/settings.json .gitignore
git commit -m "Add MegaLLM configuration for Claude Code"

Team Configuration

For team projects, separate shared config from personal API keys: Shared Configuration (.claude/settings.json - committed to git):
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io"
  },
  "model": "gpt-5",
  "temperature": 0.7,
  "maxTokens": 4096
}
Personal Configuration (.claude/settings.local.json - not committed):
{
  "env": {
    "ANTHROPIC_API_KEY": "sk-mega-personal-key-here"
  }
}
Setup Instructions for Team (.claude/README.md):
# MegaLLM Claude Code Setup

## Prerequisites
1. Get your MegaLLM API key from https://megallm.io/dashboard
2. Install Claude Code: `npm install -g @anthropic-ai/claude-code`

## Setup
1. Create `.claude/settings.local.json`:
   ```json
   {
     "env": {
       "ANTHROPIC_API_KEY": "your-key-here"
     }
   }
  1. Or set environment variable:
    export ANTHROPIC_API_KEY="your-key-here"
    

## Configuration Options

### Available Settings

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io",
    "ANTHROPIC_API_KEY": "sk-mega-...",
    "ANTHROPIC_MODEL": "gpt-5"
  },
  "model": "gpt-5",
  "temperature": 0.7,
  "maxTokens": 4096,
  "streaming": true,
  "contextWindow": 8192,
  "autoSave": true,
  "fileWatcher": true,
  "gitIntegration": true
}

Model Selection

Change the default model:
{
  "env": {
    "ANTHROPIC_MODEL": "claude-opus-4-1-20250805"
  }
}
Or specify in environment variable:
export ANTHROPIC_MODEL="gpt-5"
See Models Catalog for available models.

Verification

Check Configuration Files

# View settings
cat ~/.claude/settings.json | jq .

# View API key approval
cat ~/.claude.json | jq .

# Check project config
cat .claude/settings.json | jq .
cat .claude/settings.local.json | jq .

Test API Connection

# Test API with your credentials
curl -H "Authorization: Bearer $ANTHROPIC_API_KEY" \
     -H "Content-Type: application/json" \
     $ANTHROPIC_BASE_URL/v1/models

# Should return list of available models

Test Claude Code

# Run Claude Code
claude-code

# Or test with a simple prompt
echo "What is 2+2?" | claude-code

Troubleshooting

Check file locations:
ls -la ~/.claude/
ls -la .claude/
Verify JSON syntax:
jq . ~/.claude/settings.json
# Should show formatted JSON, or error if invalid
Check permissions:
ls -la ~/.claude/settings.json
# Should be readable: -rw-r--r--
Verify environment variable:
echo $ANTHROPIC_API_KEY
If empty, reload shell:
source ~/.bashrc  # or ~/.zshrc
Check API key in config:
jq .env.ANTHROPIC_API_KEY ~/.claude/settings.json
Verify API key format:
  • Must start with sk-mega-
  • At least 20 characters long
  • No extra spaces or quotes
Check environment variable:
echo $ANTHROPIC_BASE_URL
# Should be: https://ai.megallm.io
Verify in config:
jq .env.ANTHROPIC_BASE_URL ~/.claude/settings.json
Common mistake - trailing slash:
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.megallm.io"  // ✅ Correct
    // "ANTHROPIC_BASE_URL": "https://ai.megallm.io/"  // ❌ Wrong
  }
}
Check you’re in the right directory:
pwd
ls -la .claude/
Verify config priority:
# Project config should override system
cat .claude/settings.json
cat ~/.claude/settings.json
Check for settings.local.json:
cat .claude/settings.local.json
# This has highest priority

Advanced Configuration

Multiple Profiles

Use different configurations for different use cases:
# Development profile
cat > ~/.claude/settings.dev.json << 'EOF'
{
  "env": {
    "ANTHROPIC_API_KEY": "sk-mega-dev-key"
  },
  "model": "gpt-4o-mini",
  "temperature": 0.9
}
EOF

# Production profile
cat > ~/.claude/settings.prod.json << 'EOF'
{
  "env": {
    "ANTHROPIC_API_KEY": "sk-mega-prod-key"
  },
  "model": "gpt-5",
  "temperature": 0.5
}
EOF

# Switch profiles
cp ~/.claude/settings.dev.json ~/.claude/settings.json

Environment-Specific Configuration

# Set different configs based on environment
if [ "$NODE_ENV" = "production" ]; then
  export ANTHROPIC_API_KEY="$PROD_API_KEY"
else
  export ANTHROPIC_API_KEY="$DEV_API_KEY"
fi

Best Practices

Separate API Keys

Use .gitignore for settings.local.json to keep API keys private

Project-Level for Teams

Use project-level config for team projects with shared settings

Environment Variables

Prefer environment variables in CI/CD environments

Regular Updates

Keep Claude Code updated for latest features and fixes

Next Steps