Microsoft's own documentation for Claude in Foundry names exactly two agent paths: the Microsoft Agent Framework, and building custom agents with the Claude Agent SDK. This article covers the second — pointing the SDK's agent loop (the same loop that powers Claude Code, with local tools and JSONL session state; see the hosting comparison) at a Claude deployment in your Foundry resource.
The environment variables
Everything is configured through env vars. The switch is CLAUDE_CODE_USE_FOUNDRY=1, plus one of two ways to identify your endpoint:
| Variable | Purpose |
|---|---|
CLAUDE_CODE_USE_FOUNDRY=1 | Route the agent's model calls to Microsoft Foundry |
ANTHROPIC_FOUNDRY_RESOURCE | Your Foundry resource name — the SDK derives the endpoint from it |
ANTHROPIC_FOUNDRY_BASE_URL | Alternative to the resource name: the full endpoint, https://{resource}.services.ai.azure.com/anthropic — also the override point for API gateways and custom routing |
ANTHROPIC_FOUNDRY_API_KEY | API-key auth (optional — see the credential chain below) |
The base-URL form matters for enterprises fronting model traffic with an API management layer: point it at your gateway and the agent's traffic flows through your existing policies, as with ANTHROPIC_BEDROCK_MANTLE_BASE_URL on Bedrock and ANTHROPIC_VERTEX_BASE_URL on Vertex.
Auth: API key or the Azure credential chain
If ANTHROPIC_FOUNDRY_API_KEY is set, it is used. If it is unset, the SDK falls back to the Azure SDK's default credential chain — Microsoft Entra ID identities, including a developer's az login session, managed identities, and the other standard sources. For role assignments, the docs state that the Azure AI User and Cognitive Services User roles suffice. Keyless Entra auth is the better enterprise default: no secret to store or rotate, and access is governed by the same RBAC as everything else on the subscription — see Entra auth for Foundry and Foundry RBAC.
No wizard, no startup check — what that means in practice
Here Foundry genuinely differs from its siblings. On Bedrock and Vertex, Claude Code offers interactive login wizards (/setup-bedrock, /setup-vertex) and startup model checks (Bedrock from v2.1.94, Vertex from v2.1.98) that validate your configuration before work begins. Foundry has neither: there is no interactive setup wizard and no startup model check. Environment variables are the only configuration path, and mistakes surface at request time rather than at launch.
Under the hood the SDK is talking to the same Messages API surface Foundry exposes at https://<resource>.services.ai.azure.com/anthropic/v1/messages (with anthropic-version: 2023-06-01) — useful to know when debugging with curl or reconciling gateway logs.
Which hosting version, and what the agent can use
Foundry offers Claude in two hosting versions: Hosted on Azure (GA — currently Opus 4.8, Sonnet 5, and Haiku 4.5, running end-to-end on Azure infrastructure) and Hosted on Anthropic (a broader model list, running on Anthropic's infrastructure). The Agent SDK works against your deployment either way, since its tools — file operations, bash, its own MCP client — execute in your process, not server-side. Server-side features are where hosting matters: Anthropic's MCP connector and Agent Skills on Foundry require a Hosted-on-Anthropic deployment. The full picture is in Foundry hosting modes.
As on the other platforms, prompt caching is enabled automatically, with DISABLE_PROMPT_CACHING=1 and ENABLE_PROMPT_CACHING_1H=1 (higher-billed 1-hour TTL) as the knobs — significant for agent loops that resend growing history every turn.
Where to go next
Compare the sibling setups on Bedrock and Google Cloud, or start from Foundry resource setup if the Azure side isn't provisioned yet.