Skip to content
CLI tool · Cloud & deploy

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.

azby MicrosoftOfficial MCP option
What it is

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

Install Azure CLI

The install commands from the official docs. Check it worked with az version.

macOS (Homebrew)
brew update && brew install azure-cli
Windows (WinGet)
winget install --exact --id Microsoft.AzureCLI
Debian or Ubuntu (Microsoft script)
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Auth

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.

Check the sign-in (read-only)
az account show
Interactive sign-in (human)
az login
Pick the subscription
az account set --subscription "My Subscription"
Common agent tasks

What agents use Azure CLI for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Show the active subscription

    az
    az account show
  2. List resource groups

    az
    az group list --output table
  3. List resources in a group

    az
    az resource list --resource-group my-rg --output table
  4. Preview a Bicep deployment

    az
    az deployment group what-if --resource-group my-rg --template-file main.bicep
  5. Stream App Service logs

    az
    az webapp log tail --name my-app --resource-group my-rg

    Streams until stopped. Run it with a timeout.

Safety

Safety rules for agents

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 first

  • 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.
Agent instructions

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.

AGENTS.md
## 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.
CLI or MCP server?

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.

Same category
All Cloud & deploy tools
FAQ

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.