Fixed: A Deleted Azure CLI Configuration Folder Comes Back with logs/telemetry.log
I signed a second account out of the Azure CLI, deleted its configuration folder, and Test-Path said False. When I looked again, the folder was back, holding only logs/telemetry.log. By default, the Azure CLI starts a separate process after each command to upload usage data, and that process recreates the folder for its log; delete the folder once more after it has run, or turn telemetry off for the last command.
What I Was Doing
I had signed a second account in to the Azure CLI, in a configuration folder of its own, ~/.azure-test-user, next to my own sign-in in the default folder, ~/.azure. The environment variable AZURE_CONFIG_DIR chooses the folder; How to Sign In to Two Accounts at Once in the Azure CLI shows that setup. When I was done, I cleaned up in PowerShell 7.6 on macOS: sign the second account out, then delete its folder.
$env:AZURE_CONFIG_DIR = Join-Path $HOME ".azure-test-user"
az logout
Remove-Item Env:AZURE_CONFIG_DIR
Remove-Item -Recurse -Force (Join-Path $HOME ".azure-test-user")
Test-Path (Join-Path $HOME ".azure-test-user")
az account show --query user.name --output tsv
$env:AZURE_CONFIG_DIR = Join-Path $HOME ".azure-test-user"points the Azure CLI at the second account's folder.Join-Pathcombines a path and child-path into a single path: here, your home folder and.azure-test-user.az logoutsigns that account out. The reference describes it as Log out to remove access to Azure subscriptions.Remove-Item Env:AZURE_CONFIG_DIRremoves the variable, so the nextazcommand uses the default folder again.Remove-Item -Recurse -Forcedeletes the folder.-Recursedeletes the items in the specified locations and in all child items of the locations, and-Forceremoves hidden and read-only files too.Test-Pathchecks the folder. It returns$trueif all elements exist and$falseif any are missing.az account show --query user.name --output tsvprints the account the default folder uses, to check that my own sign-in was untouched.
False
user@example.com
The folder was gone, and my own account was still signed in.
What I Expected
The folder would stay deleted. Test-Path had just said so.
What I Got
When I listed the folder a little later, it was back, with one folder and one file in it:
- bash / zsh
- PowerShell
ls -R ~/.azure-test-user
logs
/Users/you/.azure-test-user/logs:
telemetry.log
Get-ChildItem -Recurse -Name (Join-Path $HOME ".azure-test-user")
logs
logs/telemetry.log
ls -R lists a folder with everything below it; its manual describes -R as Recursively list subdirectories encountered. Get-ChildItem -Recurse -Name does the same in PowerShell, by name only.
Nothing of the sign-in came back: only a logs folder with a telemetry.log file in it.
What I Checked
The log. telemetry.log held two lines. After a process ID and a time, the first said INFO : telemetry.main : Attempt start. Configuration directory [/Users/you/.azure-test-user], followed by a cache directory inside the same folder. The second said INFO : telemetry.client : Accumulated 0 events. Flush the clients. So a part of the Azure CLI called telemetry had started up with my deleted folder as its configuration folder.
The documentation. Microsoft's Azure CLI configuration page explains the folder and the setting involved:
- The default value of
AZURE_CONFIG_DIRis$HOME/.azureon Linux and macOS, and%USERPROFILE%\.azureon Windows. - The
coresection has a setting calledcollect_telemetry: Allow Microsoft to collect anonymous data on the usage of the CLI. - Every setting also has an environment variable: Their corresponding environment variables are set as
AZURE_{section}_{name}, in all caps. Forcollect_telemetry, that'sAZURE_CORE_COLLECT_TELEMETRY. - The log folder,
log_dir, defaults to alogsfolder inside the configuration folder,${AZURE_CONFIG_DIR}/logs.
That explained the logs folder's name, but not why it came back after the delete.
The source code. The Azure CLI is open source, so I read its telemetry code on GitHub, on the dev branch at commit bba3dad. The same files are in the 2.93.0 release I use, apart from the version number. Here is what happens at the end of every az command:
- The Azure CLI's entry point calls
telemetry.conclude()inside itsfinally:block, so it runs after every command. conclude()only does anything when telemetry is on. Its decorator,_user_agrees_to_telemetry, returns early unlessis_telemetry_enabled()is true, and that readscore.collect_telemetrywithfallback=True: on, unless you turn it off. Thenconclude()hands the command's configuration folder tosave().save()writes the command's data to a cache in that folder,telemetry/followed by the date and time, and calls_start()._start()launches the upload as a separate process withsubprocess.Popen, passing it the configuration folder and the cache folder. Theazcommand doesn't wait for it.- The new process runs
main(), whose first step sets up its log withconfig_logging_for_upload(config_dir). The logging code's own comment says: The upload process is an independent process apart from the main CLI process.
The helper that config_logging_for_upload calls first is the one that brings the folder back:
def _ensure_telemetry_log_folder(config_dir):
try:
ret = os.path.join(config_dir, TELEMETRY_LOG_DIR)
if not os.path.isdir(ret):
os.makedirs(ret)
return ret
except (OSError, TypeError):
return None
_ensure_telemetry_log_folder joins the configuration folder and TELEMETRY_LOG_DIR, which const.py sets to 'logs', next to TELEMETRY_LOG_NAME = 'telemetry.log'. If that folder doesn't exist, os.makedirs creates it, and Python's documentation for os.makedirs says it creates a leaf directory and all intermediate ones. So when the configuration folder is gone, it comes back too, with logs inside.
Right after that, main() writes the line I saw first:
logger.info('Attempt start. Configuration directory [%s]. Cache directory [%s].', sys.argv[1], sys.argv[2])
Then it reads the cache. Mine had been deleted along with the folder, so snapshot_and_read() returned at once, and the client logged Accumulated 0 events. Flush the clients.: there was nothing left to send.
In my cleanup, az logout was the last command that used ~/.azure-test-user. It started an upload process for that folder, Remove-Item deleted the folder before the process created its log, and the process then created logs, and the folder with it.
The smallest reproduction. To be sure, I reproduced it in zsh with one harmless az command, with the time zone set to UTC so that the log shows UTC times:
export AZURE_CONFIG_DIR=~/.azure-test-user
az version --output none
rm -rf ~/.azure-test-user
sleep 5
ls -R ~/.azure-test-user
cat ~/.azure-test-user/logs/telemetry.log
export AZURE_CONFIG_DIR=~/.azure-test-userpoints theazcommands that follow at the test folder. In zsh's words,exportmarks a variable for automatic export to the environment of subsequently executed commands.az version --output noneruns one simpleazcommand: it would Show the versions of Azure CLI modules and extensions, and--output noneprints No output other than errors and warnings.rm -rf ~/.azure-test-userdeletes the folder at once:-rremoves the whole folder tree, and-fdoesn't ask first.sleep 5waits five seconds,ls -Rlists what's there, andcatprints the log.
logs
/Users/you/.azure-test-user/logs:
telemetry.log
28935 : 2026-12-03 12:24:14,102 : INFO : telemetry.main : Attempt start. Configuration directory [/Users/you/.azure-test-user]. Cache directory [/Users/you/.azure-test-user/telemetry/20261203122414011].
28935 : 2026-12-03 12:24:14,111 : INFO : telemetry.client : Accumulated 0 events. Flush the clients.

Five seconds after the delete, the folder was back. The cache folder's name, 20261203122414011, is the moment az version saved its data, 12:24:14.011 UTC. The upload process wrote Attempt start 91 milliseconds later, when the folder was already deleted, and found 0 events to send.
Why It Happens
When telemetry is on, which is the default, every az command saves its usage data in its configuration folder and starts a separate upload process before it ends. That process creates a logs folder in the configuration folder for its own log, telemetry.log, and creates any missing folder on the way. Delete the configuration folder right after an az command that used it, and the upload process can still be starting: it then creates the folder again, with only logs/telemetry.log in it.
The Fix
Delete the folder again. When the folder comes back, its cache is already gone, so the upload process has nothing to send and ends right away: in my log, its two lines are 9 milliseconds apart. A second delete then sticks. I checked 10 seconds after deleting it, in both shells:
- bash / zsh
- PowerShell
rm -rf ~/.azure-test-user
sleep 10
ls ~/.azure-test-user
ls: /Users/you/.azure-test-user: No such file or directory
Remove-Item -Recurse -Force (Join-Path $HOME ".azure-test-user")
Start-Sleep -Seconds 10
Test-Path (Join-Path $HOME ".azure-test-user")
False
sleep 10 and Start-Sleep -Seconds 10 wait 10 seconds before the check, so a folder that came back would show up.
Or keep it from coming back. Turn telemetry off for the last az command that uses the folder. conclude() then returns before it saves anything, so no upload process starts:
export AZURE_CONFIG_DIR=~/.azure-test-user
AZURE_CORE_COLLECT_TELEMETRY=false az version --output none
rm -rf ~/.azure-test-user
sleep 5
ls -R ~/.azure-test-user
ls: /Users/you/.azure-test-user: No such file or directory
AZURE_CORE_COLLECT_TELEMETRY=false in front of the command sets the variable for that one command: in zsh, the parameter assignments modify the environment of the command when it is executed. I ran it with az version; in a cleanup, the last command that uses the folder is usually az logout, and the setting goes in front of that. In PowerShell, set it the same way as AZURE_CONFIG_DIR, with $env:AZURE_CORE_COLLECT_TELEMETRY = "false" before the command and Remove-Item Env:AZURE_CORE_COLLECT_TELEMETRY after it. I ran this check in zsh only.
After the Fix
Deleted a second time, the folder stayed deleted:

With telemetry off for the az command, the folder never came back at all:

At the end of these runs, ~/.azure-test-user was still gone.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Deleting the folder right after the last az command that used it | That command's upload process creates logs/telemetry.log again | Delete it once more, or run that command with AZURE_CORE_COLLECT_TELEMETRY=false |
| Trusting a check that runs right after the delete | Test-Path said False, and the folder still came back | Check again a few seconds later |
| Turning telemetry off after the last command | The upload process has already started | Turn it off for the last command itself |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
A deleted configuration folder is back with only logs/telemetry.log | The telemetry upload process of the last az command recreated it | Delete it again |
telemetry.log says Accumulated 0 events | The cache was deleted with the folder before the upload process read it | Nothing: there was nothing left to send |
| The folder comes back after every cleanup | The delete follows right after an az command that uses the folder | Run that command with AZURE_CORE_COLLECT_TELEMETRY=false |
FAQ
Is anything of the signed-out account left in the folder?
Not in mine. It held only logs/telemetry.log, and the log's two lines named the configuration folder and the cache folder, and a count of 0 events.
Does this happen with the default folder, ~/.azure, too?
The telemetry code doesn't treat the default folder differently: conclude() passes it whatever configuration folder the command used. I only saw it with a second folder, which is where deleting the whole folder is part of the cleanup.
Can I turn telemetry off in the configuration file instead?
Not for this. Azure CLI configuration says The configuration file itself is located at $AZURE_CONFIG_DIR/config, so each configuration folder has its own file, and a setting in your default folder's file doesn't apply to commands that use another folder. The environment variable applies to whichever folder the command uses.
Conclusion
A deleted Azure CLI configuration folder that comes back with only logs/telemetry.log was recreated by the Azure CLI's telemetry upload process, which the last az command started before it ended. Delete the folder once more after that process has run, or run the last command with AZURE_CORE_COLLECT_TELEMETRY=false, and the folder stays deleted.
Additional Resources
- Azure CLI configuration —
AZURE_CONFIG_DIR,collect_telemetry, the environment variable names and the log folder. - Tips for using the Azure CLI successfully — giving a script its own configuration folder with
AZURE_CONFIG_DIR. - az logout — signing an account out.
- Azure CLI telemetry,
__init__.py—save(),_start()and the upload process'smain(). - Azure CLI telemetry,
telemetry_logging.py— the code that creates thelogsfolder. - Remove-Item —
-Recurseand-Force.
