OmniscioGuidesClaude Code on Microsoft Foundry
Claude Code on Microsoft Foundry
Microsoft Foundry is how an Azure shop runs Claude Code against its own Azure resource, under Azure access control. The trade for that control is configuration: there is no setup wizard, so the connection is entirely a set of environment variables you get right once.
This page walks the five setup steps in Anthropic's order, then covers the roles an Entra ID or bearer-token identity needs, the 1M token context window, and the two errors Anthropic documents.
Sources read on November 22, 2026. By the Omniscio team. Updated .
The five setup steps
Before you start you need an Azure subscription with access to Microsoft Foundry and permission to create Foundry resources and deployments. The Azure CLI is optional, and only if you have no other way to get credentials.
1. Provision the resource and its deployments
In the Microsoft Foundry portal, create a new resource and note its name. Then create a deployment for each model you want — Claude Opus, Claude Sonnet, Claude Haiku — and note the deployment names, because those names become your model variables later.
Each deployment also has a hosting option, which decides whether inference runs on Azure or on Anthropic infrastructure.
2. Choose one credential method
Claude Code supports three authentication methods for Microsoft Foundry. Pick the one that fits your security requirements:
- API key: copy a key from the resource's Endpoints and keys section and set it as
ANTHROPIC_FOUNDRY_API_KEY. - Microsoft Entra ID: leave the API key and token variables unset; Claude Code uses the Azure SDK default credential chain, which on a local machine is an
az loginsession. - Bearer token: set
ANTHROPIC_FOUNDRY_AUTH_TOKENto a token Microsoft Entra ID issued for your resource, when another process has already obtained one.
The bearer token takes precedence over the API key and over the default credential chain. Whichever method you use, the /logout command is unavailable on Microsoft Foundry, because authentication is handled through Azure credentials.
3. Turn the integration on
Set the variables that enable Foundry and name the resource. The resource variable takes the name alone, such as my-resource; a URL or host name is refused when you send a message.
# Enable Microsoft Foundry integration
export CLAUDE_CODE_USE_FOUNDRY=1
# Azure resource name (replace {resource} with your resource name)
export ANTHROPIC_FOUNDRY_RESOURCE={resource}
# Or provide the full base URL in its own variable:
# export ANTHROPIC_FOUNDRY_BASE_URL=https://{resource}.services.ai.azure.com/anthropicThe full URL belongs in ANTHROPIC_FOUNDRY_BASE_URL; ANTHROPIC_FOUNDRY_RESOURCE only ever takes the name.
4. Pin the model versions
This is the step that causes most surprises if it is skipped. Without pinning, an alias such as sonnet or opus resolves to Claude Code's built-in default for Microsoft Foundry. That default can lag the newest release, and it may not exist in your account at all; when your resource has no deployment for it, Claude Code switches to an older model — showing a message that starts Switched to <fallback> because <model> is not available — or the request fails.
Set the model variables to the deployment names you created, exactly as Azure names them: a deployment called team-opus-prod is the value for the Opus variable, and a modelOverrides entry tells Claude Code which model that deployment serves. Anthropic's example, where the deployments are named after the models and the account has newer ones than the defaults:
export ANTHROPIC_DEFAULT_OPUS_MODEL='claude-opus-4-8'
export ANTHROPIC_DEFAULT_SONNET_MODEL='claude-sonnet-5'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='claude-haiku-4-5'Background tasks such as session title generation normally use a small, fast model. On Microsoft Foundry, Claude Code points those at the primary model by default, because not every account has a Haiku deployment; setting the Haiku variable to a deployment you do have puts those tasks back on a Haiku-class model.
When you create the deployments in Azure, choose a specific model version rather than "auto-update to latest". Prompt caching is enabled automatically; to ask for a one-hour cache TTL instead of the five-minute default, set ENABLE_PROMPT_CACHING_1H=1, noting that writes at the longer TTL are billed at a higher rate.
5. Run it and check the provider
With the variables set, start Claude Code from your project directory. It reads CLAUDE_CODE_USE_FOUNDRY and the other variables from the environment and connects to your Azure resource on the first prompt. Unlike Amazon Bedrock and Google Cloud's Agent Platform, Microsoft Foundry has no interactive setup wizard.
To verify, run /status: the API provider line shows Microsoft Foundry, along with the resource name or base URL you configured.
The Azure role your identity needs
If you authenticate with Microsoft Entra ID, or a bearer token it issued, give your identity the Foundry User or Cognitive Services User role on the Foundry resource. Foundry User may still appear under its previous name, Azure AI User. If neither role fits, Microsoft's Foundry RBAC documentation covers custom roles.
The 1M token context window
On Microsoft Foundry, models in Anthropic's newer families — Fable, Sonnet 5 and later, Opus 4.7 and later — run with the 1M token context window by default, with no [1m] suffix needed — as long as Claude Code can tell which model your deployment serves. It reads the model from the deployment name, so name each deployment with its model ID, or map the deployment name to a model with modelOverrides.
If you would rather keep a 200K window, set CLAUDE_CODE_DISABLE_1M_CONTEXT=1. When Claude Code cannot match a deployment name to a model it assumes a 1M window, so set the real window if your deployed model accepts less.
Opus 4.6 and Sonnet 4.6 reach 1M when you append [1m] to the deployment name in the Opus or Sonnet model variable.
The two errors Anthropic documents
Anthropic prints Failed to get token from azureADTokenProvider: ChainedTokenCredential authentication failed with one remedy: configure Entra ID on the environment, or set ANTHROPIC_FOUNDRY_API_KEY.
Repeated connection errors on the first prompt usually mean ANTHROPIC_FOUNDRY_RESOURCE holds a placeholder rather than your real resource name. Claude Code builds the endpoint URL from that value, so a wrong name points at a host that does not exist.
The environment variables guide covers where to set variables so every session picks them up, and the managed settings guide covers pushing the same values to a whole team.
Where these answers come from
- Everything on this page about provisioning, credentials, the environment variables, model pinning, roles, the context window and both errors: Claude Code on Microsoft Foundry, read November 22, 2026.
- The model IDs in the pinning example,
claude-opus-4-8,claude-sonnet-5andclaude-haiku-4-5, are the page's own example values, quoted as they appear.
No Azure resource was provisioned to write this page: every step, variable and error message is Anthropic's own wording from the page named above.
Common questions
How does Claude Code connect to Microsoft Foundry?
Through environment variables. You set CLAUDE_CODE_USE_FOUNDRY=1 and ANTHROPIC_FOUNDRY_RESOURCE to the name of your Foundry resource, and Claude Code connects to that resource on the first prompt. Unlike Amazon Bedrock and Google Cloud's Agent Platform, Microsoft Foundry has no interactive setup wizard.
Which authentication methods does Microsoft Foundry support?
Three: an API key in ANTHROPIC_FOUNDRY_API_KEY, Microsoft Entra ID through the Azure SDK default credential chain such as an az login session, or a bearer token in ANTHROPIC_FOUNDRY_AUTH_TOKEN that another process obtained for you. The bearer token takes precedence over the API key and the credential chain.
Why should I pin model versions on Microsoft Foundry?
Without pinning, aliases such as sonnet and opus resolve to Claude Code's built-in default for Microsoft Foundry, which can lag the newest release and may not be available in your account. If your resource has no deployment for that default, Claude Code switches to an older model or the request fails, so each deployment should name a specific model version.
How do I check that Microsoft Foundry is working?
Run /status inside Claude Code. The API provider line shows Microsoft Foundry, along with the resource name or base URL you configured.