Azure CLI for AI agents
The Azure CLI (az) for coding agents: check the subscription, list resources, stream app logs, and preview deployments with what-if before changes.
What Azure CLI does for an agent
The Azure CLI is Microsoft's official cross-platform command-line tool for Azure. The az command manages subscriptions, resource groups, App Service, AKS, storage, and most other Azure services.
For infrastructure changes, az deployment group what-if shows what a Bicep or ARM template would create, change, or delete, which gives an agent a safe preview step.
Install Azure CLI
The install commands from the official docs. Check it worked with az version.
brew update && brew install azure-cli
winget install --exact --id Microsoft.AzureCLI
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Signing in Azure CLI for an agent
A human signs in with az login. In CI, use a service principal or managed identity with the narrowest role that works, such as Reader for investigation.
az account show
az login
az account set --subscription "My Subscription"
What agents use Azure CLI for
Example commands with placeholder names. Swap in your own project, app, or file names.
Show the active subscription
az account show
List resource groups
az group list --output table
List resources in a group
az resource list --resource-group my-rg --output table
Preview a Bicep deployment
az deployment group what-if --resource-group my-rg --template-file main.bicep
Stream App Service logs
az webapp log tail --name my-app --resource-group my-rg
Streams until stopped. Run it with a timeout.
Safety rules for agents
Safe to run without asking
az account showaz group listaz resource listaz <service> show / listaz deployment group what-if
Ask a human first
az deployment group createaz <service> create / update / deleteaz group deleteaz role assignment create
- Check az account show before every session; one sign-in can reach several subscriptions.
- Run what-if before any deployment and show its output for approval.
- Never pass --yes to delete commands on the agent's own initiative; the prompt exists for a reason.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## Azure CLI (az) Use `az` for reading Azure subscriptions and resources and previewing infrastructure deployments. - Check it is installed with `az version`. If it is missing, ask before installing it. - Auth: a human signs az in. Check with `az account show`; if it fails, stop and ask. Never run the login flow yourself, and never print tokens. - Run without asking (read-only): `az account show`, `az group list`, `az resource list`, `az <service> show / list`, `az deployment group what-if`. - Ask a human first (changes or deletes things): `az deployment group create`, `az <service> create / update / delete`, `az group delete`, `az role assignment create`. - Check az account show before every session; one sign-in can reach several subscriptions. - Run what-if before any deployment and show its output for approval. - Never pass --yes to delete commands on the agent's own initiative; the prompt exists for a reason. - Prefer JSON output where the command supports it, and keep output short.
Azure CLI or an MCP server?
An official MCP option exists. Microsoft publishes an official Azure MCP Server that exposes many Azure services as tools. It is a good fit for chat clients; the az CLI gives a shell-based agent the full surface with one binary.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Cloud & deploy tools
Azure CLI questions
How do I install Azure CLI?
macOS (Homebrew): brew update && brew install azure-cli. Other official options: Windows (WinGet), Debian or Ubuntu (Microsoft script). Check the install with az version, and see the Microsoft docs for other platforms.
How does an AI agent authenticate Azure CLI?
A human signs in with az login. In CI, use a service principal or managed identity with the narrowest role that works, such as Reader for investigation. The agent can check the sign-in with az account show and should stop and ask if it fails.
Which Azure CLI commands are safe for an agent to run?
Commands that only read state are safe to run without asking: az account show; az group list; az resource list; az <service> show / list; az deployment group what-if. Ask a human before anything that changes or deletes something: az deployment group create; az <service> create / update / delete; az group delete; az role assignment create.
Is there an MCP server for Azure CLI?
Microsoft publishes an official Azure MCP Server that exposes many Azure services as tools. It is a good fit for chat clients; the az CLI gives a shell-based agent the full surface with one binary.