Skip to content

Instantly share code, notes, and snippets.

@weltonrodrigo
Created January 6, 2026 14:54
Show Gist options
  • Select an option

  • Save weltonrodrigo/c32145497844b669e83a1d13f7c7e064 to your computer and use it in GitHub Desktop.

Select an option

Save weltonrodrigo/c32145497844b669e83a1d13f7c7e064 to your computer and use it in GitHub Desktop.
How to configure Claude Code CLI with Azure AI Foundry

Configuring Claude Code CLI with Azure AI Foundry

This is from 2026-01. Your mileage may vary.

This guide explains how to configure Claude Code CLI to use Azure AI Foundry as the model provider for Anthropic Claude models.

Prerequisites

  • Claude Code CLI installed (npm install -g @anthropic-ai/claude-code)
  • An Azure AI Foundry resource with Anthropic Claude models deployed
  • Your Azure AI Foundry API key

Setup

Option 1: Environment Variables

Set the following environment variables:

# Required: Enable Foundry mode
export CLAUDE_CODE_USE_FOUNDRY=1

# Required: Your Foundry API key
export ANTHROPIC_FOUNDRY_API_KEY="your-api-key-here"

# Required: Your Azure AI Foundry endpoint
export ANTHROPIC_FOUNDRY_BASE_URL="https://YOUR-RESOURCE-NAME.openai.azure.com/anthropic"

# Optional: Specify model names (defaults shown)
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-5"

# Make sure Vertex is disabled
export CLAUDE_CODE_USE_VERTEX=0

Add these to your shell profile (~/.zshrc, ~/.bashrc, etc.) for persistence.

Option 2: Shell Wrapper Script

Create a wrapper script claude-foundry in your PATH:

#!/bin/bash
ANTHROPIC_FOUNDRY_API_KEY="your-api-key-here" \
CLAUDE_CODE_USE_VERTEX=0 \
CLAUDE_CODE_USE_FOUNDRY=1 \
ANTHROPIC_FOUNDRY_BASE_URL="https://YOUR-RESOURCE-NAME.openai.azure.com/anthropic" \
ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-5" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5" \
ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-5" \
claude "$@"

Make it executable: chmod +x claude-foundry

Key Configuration Notes

Environment Variable Description
CLAUDE_CODE_USE_FOUNDRY Must be 1 to enable Azure AI Foundry mode
CLAUDE_CODE_USE_VERTEX Set to 0 to disable Google Vertex AI
ANTHROPIC_FOUNDRY_API_KEY Your Azure AI Foundry API key
ANTHROPIC_FOUNDRY_BASE_URL Your Azure endpoint with /anthropic suffix
ANTHROPIC_DEFAULT_SONNET_MODEL Claude Sonnet model deployment name
ANTHROPIC_DEFAULT_HAIKU_MODEL Claude Haiku model deployment name
ANTHROPIC_DEFAULT_OPUS_MODEL Claude Opus model deployment name

Finding Your Azure Endpoint

  1. Go to Azure AI Foundry or Azure Portal
  2. Navigate to your Azure AI Foundry resource
  3. Find the endpoint URL (looks like https://YOUR-RESOURCE-NAME.openai.azure.com/)
  4. Append /anthropic to get the base URL for Claude models

Testing

Run a simple test:

claude -p "hello"

You should see a response from Claude without being prompted to log in.

Troubleshooting

Authentication Errors

  • Verify ANTHROPIC_FOUNDRY_API_KEY is set correctly
  • Check that your API key has access to the Claude model deployments

Model Not Found

  • Ensure the model names in ANTHROPIC_DEFAULT_*_MODEL match your Azure deployment names
  • Verify Claude models are deployed in your Azure AI Foundry resource

Still Prompting for Login

  • Make sure CLAUDE_CODE_USE_FOUNDRY=1 is set
  • Verify CLAUDE_CODE_USE_VERTEX=0 to avoid conflicts

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment