A single az sign-in shares one current subscription across every terminal, which is painful when you work for several tenants. Jaliya Udagedara shows how to give each account its own AZURE_CONFIG_DIR folder, sign in once per tenant and switch profiles automatically from the PowerShell prompt.
Key points
- AZURE_CONFIG_DIR moves every piece of az state: azureProfile.json, the token cache, az config settings and extensions.
- One folder per tenant makes each terminal sign in separately, so az account set no longer leaks across terminals.
- A PowerShell LocationChangedAction hook switches the profile automatically when you enter a client repo root.
- Pointing AZURE_EXTENSION_DIR at the primary profile's cliextensions installs an extension once for every profile.
- AzureCliCredential and DefaultAzureCredential inherit the variable, so an app started with dotnet run authenticates as that tenant.
- Azure PowerShell, azd (which uses AZD_CONFIG_DIR) and IDEs opened outside the terminal ignore AZURE_CONFIG_DIR entirely.
Why it matters
Anyone who touches more than one tenant from the same machine has probably already sent a command to the wrong subscription, and the fix here costs nothing beyond an environment variable. The interesting part is the PowerShell hook: tying the config folder to a repo root turns tenant selection into something that follows your cd instead of your memory, and it correctly only clears a value the hook itself set. Before adopting it, note the edges — Azure PowerShell and azd keep their own contexts, and apps launched from Visual Studio or the Start menu never see the variable. Delegating the extension folder is safe, but the Bicep CLI stays per profile, so keep an eye on disk and versions.
Real-world use
- A consultant with separate Contoso and Fabrikam code roots keeps two terminals signed into different tenants at once.
- A locally started app inherits the tenant identity through AzureCliCredential, so dotnet run reads that client's resources without switching accounts.
- Concurrent scripts each get their own config folder to avoid write conflicts on the shared token cache.
- A client pinned to a preview build of the containerapp extension keeps a private extensions folder by not sharing AZURE_EXTENSION_DIR.
This summary was generated by the agent from the original post on Jaliya Udagedara. The full text and all rights belong to its author and publisher. Go to original