Skip to main content

Fixed: A Deleted Azure CLI Configuration Folder Comes Back with logs/telemetry.log

· 14 min read
Jagdish Kumawat
Founder @ Dewiride

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.

PowerShell
$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-Path combines a path and child-path into a single path: here, your home folder and .azure-test-user.
  • az logout signs that account out. The reference describes it as Log out to remove access to Azure subscriptions.
  • Remove-Item Env:AZURE_CONFIG_DIR removes the variable, so the next az command uses the default folder again.
  • Remove-Item -Recurse -Force deletes the folder. -Recurse deletes the items in the specified locations and in all child items of the locations, and -Force removes hidden and read-only files too.
  • Test-Path checks the folder. It returns $true if all elements exist and $false if any are missing.
  • az account show --query user.name --output tsv prints the account the default folder uses, to check that my own sign-in was untouched.
Output
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:

Terminal
ls -R ~/.azure-test-user
Output
logs

/Users/you/.azure-test-user/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_DIR is $HOME/.azure on Linux and macOS, and %USERPROFILE%\.azure on Windows.
  • The core section has a setting called collect_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. For collect_telemetry, that's AZURE_CORE_COLLECT_TELEMETRY.
  • The log folder, log_dir, defaults to a logs folder 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:

  1. The Azure CLI's entry point calls telemetry.conclude() inside its finally: block, so it runs after every command.
  2. conclude() only does anything when telemetry is on. Its decorator, _user_agrees_to_telemetry, returns early unless is_telemetry_enabled() is true, and that reads core.collect_telemetry with fallback=True: on, unless you turn it off. Then conclude() hands the command's configuration folder to save().
  3. save() writes the command's data to a cache in that folder, telemetry/ followed by the date and time, and calls _start().
  4. _start() launches the upload as a separate process with subprocess.Popen, passing it the configuration folder and the cache folder. The az command doesn't wait for it.
  5. The new process runs main(), whose first step sets up its log with config_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:

src/azure-cli-telemetry/azure/cli/telemetry/components/telemetry_logging.py
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:

src/azure-cli-telemetry/azure/cli/telemetry/__init__.py
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:

Terminal
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-user points the az commands that follow at the test folder. In zsh's words, export marks a variable for automatic export to the environment of subsequently executed commands.
  • az version --output none runs one simple az command: it would Show the versions of Azure CLI modules and extensions, and --output none prints No output other than errors and warnings.
  • rm -rf ~/.azure-test-user deletes the folder at once: -r removes the whole folder tree, and -f doesn't ask first.
  • sleep 5 waits five seconds, ls -R lists what's there, and cat prints the log.
Output
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.

macOS-style terminal window showing az version run with AZURE_CONFIG_DIR set, the folder deleted with rm -rf, and five seconds later ls -R listing logs/telemetry.log again, with the log's Attempt start and Accumulated 0 events lines.

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:

Terminal
rm -rf ~/.azure-test-user
sleep 10
ls ~/.azure-test-user
Output
ls: /Users/you/.azure-test-user: No such file or directory

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:

Terminal
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
Output
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:

macOS-style terminal window showing rm -rf on the recreated folder, a 10-second sleep, and ls reporting No such file or directory.

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

macOS-style terminal window showing az version run with AZURE_CORE_COLLECT_TELEMETRY=false, the folder deleted with rm -rf, and five seconds later ls -R reporting No such file or directory.

At the end of these runs, ~/.azure-test-user was still gone.

Common Mistakes​

MistakeWhat happensDo this instead
Deleting the folder right after the last az command that used itThat command's upload process creates logs/telemetry.log againDelete it once more, or run that command with AZURE_CORE_COLLECT_TELEMETRY=false
Trusting a check that runs right after the deleteTest-Path said False, and the folder still came backCheck again a few seconds later
Turning telemetry off after the last commandThe upload process has already startedTurn it off for the last command itself

Troubleshooting​

SymptomLikely causeFix
A deleted configuration folder is back with only logs/telemetry.logThe telemetry upload process of the last az command recreated itDelete it again
telemetry.log says Accumulated 0 eventsThe cache was deleted with the folder before the upload process read itNothing: there was nothing left to send
The folder comes back after every cleanupThe delete follows right after an az command that uses the folderRun 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​