Keep the coding assistant in your terminal, connect it to a Claude deployment through Microsoft Foundry, and verify the setup one layer at a time.
Claude Code + Microsoft Foundry: a local helper, an Azure connection
Imagine asking a coding assistant to explain an unfamiliar repository, trace a bug, or suggest a change without leaving your terminal. Now imagine connecting that experience to a model deployment accessed through your organization's Azure identity and permissions. That is the idea behind using Claude Code with Microsoft Foundry.
The easiest way to understand the setup is to separate the helper from the gate. Claude Code is the helper at your desk: it runs locally and can work with your project. Foundry is the entry point to the Claude deployment: it provides the endpoint and the access boundary for model requests.
The first diagram captures that distinction. You ask the helper a question; the request crosses an identity check before reaching the model. Connecting the two changes where model requests go, not who should remain in control of local files and commands.
The tool stays local; the model and its access rules live in Azure.This is a useful mental model, not a claim that every part of the workflow is isolated automatically. Claude Code can send relevant prompts and project context to the model service, and local tools can have their own network behavior. Use approved repositories and confirm your organization's data-handling and networking requirements before connecting sensitive work.
Understand the four-box architecture
Behind that simple analogy is a request path with four parts: the developer, the Claude Code CLI, the Foundry endpoint, and the Claude deployment. The diagram below puts them in order and marks the boundary between your laptop and Azure.
Two boxes on your laptop, two in Azure. Every problem lives in one box.
You type into Claude Code. The CLI sends a model request to the configured Foundry endpoint. That endpoint directs the request to the deployment, and the model's response returns to your session. The local assistant can then propose its next action, subject to its permissions and your review.
Keeping these four boxes in mind makes troubleshooting less mysterious. A missing CLI command is a local installation problem. A hostname that cannot resolve points toward the endpoint or network. A rejected identity points toward authentication or access. A missing deployment points toward model selection.
Before you begin
You need Claude Code installed, an eligible Azure subscription, a Foundry resource and project, an available Claude deployment, and permission to invoke it. Creating or purchasing the deployment can require additional resource-management and Marketplace permissions. If your team has already provisioned it, ask for the resource and deployment names rather than creating another resource.
For Entra ID authentication, install the Azure CLI as well. On Windows, follow Claude Code's documented Git Bash or WSL requirements. This walkthrough uses PowerShell syntax for the configuration steps.
Confirm the CLI is available before debugging Azure settings:
claude --version
If it is missing, follow the official installation instructions, then open a fresh terminal if the installation changed your PATH.
Start with two exact names
Before changing any terminal settings, collect two values from Foundry: your resource name and your Claude deployment name. They answer different questions. The resource identifies where the request goes; the deployment identifies what should answer it.
In the Foundry portal, look under Manage > Project details for the parent resource. Then open your Claude deployment under Models + endpoints and copy its deployment name. Portal labels can evolve, but the distinction between these two values is the important part.
The two cards below show the common mix-ups: using a URL where a resource name belongs, or using a catalog model identifier where a deployment name belongs.
Most failed setups are a typo or the wrong name in one of these two.Set ANTHROPIC_FOUNDRY_RESOURCE to the name alone, such as <foundry-resource-name>. Do not put https://, a project path, or /anthropic into this variable. Claude Code constructs the resource endpoint from that name.
A URL-based configuration is also supported through the separate ANTHROPIC_FOUNDRY_BASE_URL variable. That does not make a URL valid inside ANTHROPIC_FOUNDRY_RESOURCE. This walkthrough uses the resource-name approach so the two are not mixed.
For the model, copy the deployment name exactly. It may happen to match the model's catalog identifier, but do not assume it does. An incorrect resource name can lead to a DNS error such as ENOTFOUND; an incorrect deployment name can lead to a not-found response.
Authenticate with a badge, not a shared secret
Once you know the destination, decide how to authenticate. Claude Code supports Microsoft Entra ID and a Foundry API key. For an enterprise setup, Entra ID is the recommended starting point because Claude Code can use your Azure CLI credentials without asking you to copy a long-lived API key into a terminal.
The next diagram contrasts the two approaches. On the top path, you sign in and Azure checks what your identity may access. On the bottom path, a key acts as a credential that must be protected and rotated.
Entra ID means no secret in the terminal; your role decides access.Sign in with your Azure identity
az login
az account show
Check that the account, tenant, and subscription are the ones associated with your Foundry resource. If the resource is in another tenant, use az login --tenant <tenant-id>. Claude Code uses the Azure CLI session for this authentication path; you do not sign in with an Anthropic subscription through the client's /login command.
Authentication is not authorization. Successfully signing in proves who you are, not that you may invoke this deployment. The diagram uses Foundry User as an example role; the applicable role and assignment scope must grant the required access on your actual resource. Ask the resource administrator to verify the appropriate data-plane permissions rather than assuming any similarly named role is sufficient.
If you use an API key instead
Obtain the Foundry key through an approved process and supply it through ANTHROPIC_FOUNDRY_API_KEY. Do not confuse it with an Anthropic API key. Keep the value out of source control, screenshots, copied transcripts, and logs. Prefer your organization's approved secret-injection method over typing a literal key into shell history, and do not persist it with setx.
Configure the connection and launch Claude Code
With the names collected and authentication ready, configure Claude Code in the terminal you will use to launch it. The diagram groups the core settings into three switches: enable Foundry, identify the resource, and select the primary model deployment.
Three settings point Claude Code at your deployment; the launch flag removes ambiguity.In PowerShell, replace both placeholders with the values you copied:
$env:CLAUDE_CODE_USE_FOUNDRY = "1"
$env:ANTHROPIC_FOUNDRY_RESOURCE = "<foundry-resource-name>"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "<claude-sonnet-deployment-name>"
claude --model "<claude-sonnet-deployment-name>"
The first variable enables the Foundry integration. The second identifies the resource. The third maps the Sonnet model role to your deployment. Passing the deployment name explicitly with --model makes the intended model for this session clear.
The three-switch diagram describes the core connection, not every model role Claude Code can use. If your workflow uses Haiku for fast operations or Opus for reasoning, ensure the corresponding deployments are available and configure their names too:
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "<claude-haiku-deployment-name>"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "<claude-opus-deployment-name>"
Use names for deployments that actually exist in your resource. Specifying the primary model does not automatically provision deployments for other model roles.
PowerShell's $env: assignments affect the current process and programs launched from it. Set them in the same terminal that launches Claude Code. For future sessions, save non-secret configuration in your shell profile or use setx; changes made with setx apply to new terminals, not the current one.
Check the map, then prove the trip
When Claude Code starts, it is tempting to treat a healthy-looking settings screen as the finish line. It is not. A configuration check tells you how the client is configured; a real model request tells you whether the whole path works.
The diagram below makes that difference explicit: /status checks the map, while a test prompt makes the trip through name resolution, authentication, authorization, deployment selection, and model inference.
Configuration can look perfect and still fail; only a real reply proves it.Inside the Claude Code session, run:
/status
Check the reported provider and model against your intended Foundry configuration. Confirm the resource setting in the launching shell as well. The exact fields shown by /status can vary with the client version, so do not assume every value will appear on that screen.
Next, send a small prompt that does not require repository access or tool execution:
Reply with exactly: Foundry connection successful
A successful model response, together with the expected provider and deployment configuration, is the practical end-to-end check. It demonstrates that this request reached an accessible deployment and received a response. The sentence itself is not independent proof of the provider: another model could produce the same words, which is why the configuration check matters too.
This smoke test does not certify every model role, private-network policy, or future repository action. It proves the path for the request you just made. Model calls also consume quota and may incur charges, so keep the first test small.
Troubleshoot one checkpoint at a time
If the test fails, use the error as a clue rather than changing every setting at once. The diagram maps common errors to the checkpoint worth investigating first. These are starting points for diagnosis, not a guarantee that every error has only one possible cause.
Read the error code, jump to its checkpoint, fix one thing.Where to start when the connection fails
| Symptom | First checks |
|---|---|
| ENOTFOUND | Check that the resource variable contains only the resource name. Look for an unintended base-URL override, then check DNS, VPN, proxy, and any private-endpoint requirements. |
| HTTP 401 | Refresh the Azure CLI sign-in and verify the tenant and account. If using a key, check that it is the correct Foundry key and is supplied correctly. |
| HTTP 403 | Check permissions and their assignment scope. Also consider resource network-access restrictions; signing in successfully does not guarantee access. |
| HTTP 404 | Check the exact deployment name, the selected resource, and the endpoint configuration. Confirm the deployment exists where the client is looking. |
| Wrong provider | Confirm CLAUDE_CODE_USE_FOUNDRY=1 is set in the process that launches Claude Code, then restart the client from that terminal. |
| Missing model role | Check the Sonnet, Haiku, and Opus mappings used by the workflow and verify their corresponding deployments exist. |
| HTTP 429 | Check quota and rate limits in Foundry. Reduce request frequency or size rather than repeatedly retrying the same request. |
Fix the most likely layer, restart the session if its environment changed, and repeat the same small test. That keeps the investigation focused and makes it easier to tell which change actually helped.
Connected? Start read-only.
Once the smoke test works, begin with an approved sample repository and a deliberately limited request:
Analyze this repository and explain its structure.
Do not modify files or run commands.
Treat that instruction as a starting point, not a replacement for tool permissions. Review the actions Claude Code proposes, inspect file changes before accepting them, and keep the developer in the approval loop. A successful connection is not permission to run arbitrary commands.
Claude Code is the helper. Foundry is the gate. Get the names and identity right, then verify with a real request.
The setup becomes much easier when you keep those responsibilities separate. Exact names prevent routing mistakes. Azure identity and permissions control access. A real response checks the connection. Careful review keeps the coding workflow under your control.
Further reading:
Configure Claude Code for Microsoft Foundry;
Deploy and use Claude models in Microsoft Foundry;
Claude Code Quickstart.
Published Nov 27, 2026
Version 1.0SapnaGiddegowda
Microsoft
Joined November 01, 2023
Microsoft Foundry Blog
Follow this blog board to get notified when there's new activity