Repository navigation
Description
Request
Please make the Azure CLI Bash completion script honor
ARGCOMPLETE_USE_TEMPFILES by using _ARGCOMPLETE_STDOUT_FILENAME and
reading the completion results from that file. This would allow Git Bash on
Windows to use the completion script without users replacing its completion
function in their .bashrc.
Alternatively, document the Git Bash limitation and this workaround.
Reproduction
On Windows 11 with Git Bash and Azure CLI installed via the Windows MSI,
sourcing the upstream az.completion script and setting
ARGCOMPLETE_USE_TEMPFILES=1 is not sufficient: pressing Tab after az
offers filesystem paths instead of CLI commands.
The tempfile-aware function below works in this environment. I tested it with
Azure CLI 2.90.0. It creates _ARGCOMPLETE_STDOUT_FILENAME, reads the
completion results from the temporary file, and cleans it up.
Related discussion: Azure CLI #26051, which describes the Git Bash file
descriptor limitation.
Environment
- OS: Windows 11
- Shell: Git Bash (
MINGW64) - Azure CLI installation: Windows MSI
- Azure CLI version:
{
"azure-cli": "2.90.0",
"azure-cli-core": "2.90.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"azure-devops": "1.0.8"
}
}
Workaround
Using the stock bash completion file
curl -fsSL https://raw.githubusercontent.com/Azure/azure-cli/dev/az.completion -o ~/.azure/.az.completion
The completion in this scenario needs to use temp files and to get this going you need the completion to also be temp-file aware like this:
if [[ -r "$HOME/.azure/.az.completion" ]]; then
export ARGCOMPLETE_USE_TEMPFILES=1
source "$HOME/.azure/.az.completion"
_az_python_argcomplete() {
local IFS=$'\013'
local SUPPRESS_SPACE=0
local TMPFILE
local STATUS
if compopt +o nospace 2>/dev/null; then
SUPPRESS_SPACE=1
fi
TMPFILE=$(mktemp) || return 1
COMPREPLY=($(
IFS="$IFS" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
COMP_TYPE="$COMP_TYPE" \
_ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" \
_ARGCOMPLETE=1 \
_ARGCOMPLETE_SUPPRESS_SPACE=$SUPPRESS_SPACE \
ARGCOMPLETE_USE_TEMPFILES=1 \
_ARGCOMPLETE_STDOUT_FILENAME="$TMPFILE" \
"$1" 8>&1 9>&2 1>/dev/null 2>/dev/null
STATUS=$?
cat "$TMPFILE"
rm -f "$TMPFILE"
exit "$STATUS"
))
STATUS=$?
if [[ $STATUS != 0 ]]; then
unset COMPREPLY
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY[0]}" =~ [=/:]$ ]]; then
compopt -o nospace
fi
}
fi
Activity
yonzhan commentedon Sep 30, 2026
Thank you for opening this issue, we will look into it.
x-engineering-agent commentedon Oct 20, 2026
Below is my analysis of this issue:
Summary
On Windows Git Bash, sourcing the root az.completion and exporting ARGCOMPLETE_USE_TEMPFILES=1 leaves az subcommand completion empty, so Bash falls back to filesystem paths. The reporter saw this with Azure CLI 2.90.0 and a Windows MSI install. The validated Windows Git Bash sandbox reproduced missing account completions on 2.90.0, 2.91.0 and dev; completion should offer Azure CLI commands while preserving the existing Bash descriptor behavior when the variable is unset.
🔬 Likely root cause
The root az.completion invokes az with descriptor 8/9 redirection and captures stdout in command substitution. In ARGCOMPLETE_USE_TEMPFILES mode argcomplete instead writes results to _ARGCOMPLETE_STDOUT_FILENAME; the function never supplies that filename or reads the file, so COMPREPLY remains empty on Git Bash even when the CLI produces valid completions.
Affected code
az.completion›_az_python_argcomplete(line 1)src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py›ArgcompleteScenarioTest.argcomplete_env(line 14)🚫 Ruled out
🛠️ Proposed change
In root az.completion:_az_python_argcomplete, branch only when ARGCOMPLETE_USE_TEMPFILES=1: create a secure temporary file, pass its path via _ARGCOMPLETE_STDOUT_FILENAME to az, read the completion payload into COMPREPLY using the existing IFS semantics, and remove the file even if az fails. Preserve suppression of completions on nonzero exit and the current nospace handling. Leave the descriptor branch unchanged when tempfile mode is unset; do not alter the independent generated-completion shell entrypoint.
🧬 Origin
⏱️ Why this surfaced now
No new regression was found: Git Bash descriptor incompatibility was reported in 2023, and the root completion function body still dates to 2017; this request brings a tested workaround and explicit approval for an opt-in mode.
pyproject.toml#34144 (2026-10-12); the failure reproduces in both 2.90.0 and current dev, so no recent dependency bump explains it.Earlier related reports
💥 Blast radius
🔬 Technical details
Evidence
Test plan
This is offline Bash completion, not an Azure service command, so no Azure ScenarioTest recording applies. Add a shell-driven regression beside src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py (or an existing shell test location) sourcing root az.completion with an isolated fake az: exercise both tempfile-enabled and descriptor paths, successful and failing invocations, cleanup, multiple candidates and nospace behavior. Also rerun the same validated Windows Git Bash reproduction spec against the PR head with the real MSI az and verify account appears; check the default Bash descriptor mode remains unchanged.
Generated code: Handwritten code. The root az.completion is a handwritten Bash shell function, not AAZ, AutoRest or generated CLI code.
🔁 Live reproduction (BAMI sandbox) — Reproduced
Verdict: Reproduced on the current build.
Steps run (redacted)
2.90.0 (reported)
2.91.0 (latest)
dev @ 0fb5754
Sandbox run
Commands ran in an isolated Azure sandbox subscription from a validated ReproSpec; output is redacted.
x-engineering-agent commentedon Oct 20, 2026
Implementation Result
No pull request was opened because the fix needs a design decision from a maintainer.
Reason (from the job report): az.completion:_az_python_argcomplete only captures completion results from file descriptor 8 and never supplies _ARGCOMPLETE_STDOUT_FILENAME or reads a temporary result file when ARGCOMPLETE_USE_TEMPFILES=1. A focused Bash unit reproduction confirms empty candidates with a tempfile-writing completion stub while descriptor completion succeeds. Implementation is blocked because the execution host's accepted source paths exclude root az.completion, which this task explicitly requires changing. Please authorize that source path before rerunning the fix.
Options considered:
Reproduced: yes · Confidence: 0.97
Next step: A maintainer should choose the intended behavior; the Agent can implement it once that decision is recorded on this issue.
Posted by x-engineering-agent (Fixer)
a0x1ab commentedon Oct 20, 2026
Approved: update the root
az.completionto supportARGCOMPLETE_USE_TEMPFILES=1as proposed, keeping the existing descriptor path when it's unset.3 remaining items
[Core] Fix Azure#34150: `az`: Support tempfile-backed Git Bash comple…
[Core] Fix Azure#34150: `az`: Support tempfile-backed Git Bash comple…