Back to all articles

Configuring Claude Code with Azure AI Foundry: A Practical Step-by-Step Guide

A practical walkthrough to connect Claude Code to Azure AI Foundry using API keys and environment variables, then verify it inside VS Code.

January 10, 20264 min read
Share:

If you prefer running Claude Code against enterprise-managed Azure endpoints instead of a direct Anthropic account flow, Azure AI Foundry is a clean way to do it.

This guide shows a practical setup on Windows so Claude Code can use your Azure-hosted model deployment through environment variables.

This setup uses API-key based auth for speed. For team environments, consider managed identity or secret stores instead of persisting long-lived keys directly in user environment variables.

What You Will Configure#

At a high level, Claude Code will read three values from your environment:

  • ANTHROPIC_API_KEY
  • ANTHROPIC_BASE_URL
  • ANTHROPIC_DEFAULT_MODEL

Once these are set correctly, Claude Code can send requests to the model endpoint you deployed in Azure AI Foundry.

1. Prerequisites#

Before starting, verify:

  • Windows machine with terminal access
  • Node.js and npm installed
  • Access to Azure AI Foundry project and model deployment

Quick checks:

node -v
npm -v

If either command fails, install Node.js first and re-open your terminal.

2. Install Claude Code#

Install the CLI globally:

npm install -g claude-code

Then run:

claude

On first launch, choose your preferred UI theme and exit back to terminal.

3. Deploy or Confirm a Model in Azure AI Foundry#

In Azure AI Foundry:

  1. Open your project.
  2. Deploy the model you want Claude Code to use.
  3. Copy the endpoint base URL and API key.
  4. Note the model name/deployment identifier you plan to set as default.

The exact endpoint format and model identifier can vary by deployment configuration. Use the values shown for your specific deployment in Foundry, not guessed strings.

4. Set Environment Variables (Windows)#

Use setx in Command Prompt or PowerShell (Windows persists these for new shells):

setx ANTHROPIC_API_KEY "<your-foundry-api-key>"
setx ANTHROPIC_BASE_URL "<your-foundry-base-url>"
setx ANTHROPIC_DEFAULT_MODEL "<your-model-name>"

Important details:

  • setx does not update the current shell session.
  • Close and reopen your terminal after setting values.
  • Keep the API key secret and rotate it regularly.

To verify in a new terminal:

$env:ANTHROPIC_API_KEY
$env:ANTHROPIC_BASE_URL
$env:ANTHROPIC_DEFAULT_MODEL

5. Test Claude Code Connection#

Start Claude Code again:

claude

If configuration is correct, Claude Code should use your Azure-backed endpoint without requiring Anthropic subscription login.

Simple test prompt:

Explain in 5 bullets how to structure a Python project for a REST API.

6. Use It from VS Code#

Typical flow:

  1. Open a project folder in VS Code.
  2. Open integrated terminal.
  3. Run claude.
  4. Give a constrained prompt for first validation.

Example:

Generate a single Python file that adds two numbers from user input. Do not create any additional files.

This validates both CLI operation and model response behavior in your coding workflow.

Troubleshooting#

CLI still asks for login#

  • Recheck variable names exactly.
  • Confirm you restarted terminal after setx.
  • Ensure no conflicting variables are overriding values.

Auth or endpoint errors#

  • Verify API key is active.
  • Confirm base URL matches your Foundry deployment endpoint.
  • Confirm the default model identifier exists in your project.

Works in one shell, fails in another#

  • Some terminals inherit different environment scopes.
  • Re-open VS Code after setting global environment variables.

Final Notes#

Using Azure AI Foundry with Claude Code is a strong option when you want centralized deployment governance, consistent endpoint management, and integration with your Azure environment.

After this baseline setup works, the next step is to standardize your team setup using scripts, secret management, and environment profiles per project.

NB

Written by

Niteen Badgujar

AI Engineer specializing in Agentic AI, LLMs, and production-grade machine learning systems on Azure. Writing to make complex AI concepts accessible and actionable.