Using Codex CLI and Claude Code with Microsoft Foundry Models
If you spend a lot of your day bouncing between local development, cloud workflows, and AI‑assisted coding tools, there comes a moment when you realize: it would be really nice if all of those tools could run on the same infrastructure you already trust. That’s the appeal of plugging both OpenAI’s Codex CLI and Anthropic’s Claude Code into Microsoft Foundry. You get your coding agents, but with enterprise security, private networking, RBAC, and predictable costs. And everything—keys, logs, guardrails—stays inside your Azure boundary.
Here’s how I’ve been setting things up, why it’s worth doing, and the exact config you need (because nothing is worse than a guide that vaguely gestures at “replace with your settings”).
Why bother integrating Codex and Claude Code with Microsoft Foundry?
Three reasons stand out:
It’s basically local‑feeling tools running on cloud‑grade infrastructure.
Part 1: Configure Codex CLI for Microsoft Foundry
First deploy a model in Foundry. Create a Foundry project, open the model catalog, and pick one of the reasoning or Codex‑optimized models such as:
Deploy the model, then grab two things: the endpoint URL and your API key.
Install Codex CLI:
npm install -g @openai/codex codex --version
Then create your config file at ~/.codex/config.toml with the required Azure settings. The important bits are the provider, the Azure subsection, and the fact that env_key must reference an environment variable—not an inline key.
Here’s the exact working config:
model = "gpt-5-codex"
model_provider = "azure"
model_reasoning_effort = "medium"
[model_providers.azure] name = "Azure OpenAI"
base_url = "https://YOUR_RESOURCE_NAME.openai.azure.com/openai/v1"
env_key = "AZURE_OPENAI_API_KEY"
wire_api = "responses"
Now export the environment variable in your terminal:
export AZURE_OPENAI_API_KEY="<YOUR KEY HERE>"
Test it:
codex codex "Initial prompt" codex exec "Initial prompt"
If you also use VS Code, remember to launch it from the same terminal session where the environment variable is set and install the OpenAI Codex extension. Codex will automatically pick up the same config.toml.
Recommended by LinkedIn
Part 2: Configure Claude Code for Microsoft Foundry
Claude Code is even more flexible because it supports both API key auth and full Entra ID credential chains. The Foundry integration is controlled entirely through environment variables.
Start by provisioning a Foundry resource for Claude models, then deploy:
Grab your API key if you're using key‑based auth:
export ANTHROPIC_FOUNDRY_API_KEY=your-azure-api-key
Or skip that variable entirely if you’d rather rely on Entra ID:
az login
Then enable Foundry mode for Claude Code:
export CLAUDE_CODE_USE_FOUNDRY=1
export ANTHROPIC_FOUNDRY_RESOURCE={resource}
If you prefer giving the full URL:
export ANTHROPIC_FOUNDRY_BASE_URL=https://{resource}.services.ai.azure.com
Now set the deployment names for each model:
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'
And that’s it—Claude Code will automatically route all requests to your Foundry deployments.
Why using both tools together is so useful
Codex is fantastic when you need deep integration with your repo: open a pull request, rewrite a file, generate tests, refactor design patterns, etc. Claude Code is great for rapid iterative coding: exploring, rewriting, asking questions, or running coding sessions that feel like pair programming. Running both against your Foundry models keeps them aligned, consistent, and inside the compliance envelope.
In practice, I often use Codex for automation (changelog updates, refactor jobs, CI), and Claude Code for the more human side of coding (debugging, design discussions, quick prototypes).
Everything hits the same Azure resource—just through different agents.
Final thought
Once both tools are wired into Foundry, your workflow tightens up dramatically. Codex becomes your automated engineer; Claude Code becomes your thinking partner; and Azure handles the security, networking, and scaling. It’s the same coding experience you already know—just running in an environment your organization actually approves of.