Skip to content

Add support for cli completion in git bash for windows #34150

Open

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

  1. yonzhan commented on Sep 30, 2026

    @yonzhan
    Collaborator

    Thank you for opening this issue, we will look into it.

  2. x-engineering-agent commented on Oct 20, 2026

    @x-engineering-agent
    Contributor

    X Engineering Agent Bug Analysis

    Below is my analysis of this issue:

    Summary

    On Windows Git Bash, sourcing the repository az.completion and setting ARGCOMPLETE_USE_TEMPFILES=1 still leaves az Tab completion showing filesystem paths instead of CLI commands. The reporter reproduced it with the Windows MSI and Azure CLI 2.90.0 and supplied a working tempfile-aware Bash function. This is a completion-shell integration problem, not an az command failure.

    Likely root cause

    The Bash wrapper in az.completion collects results only through the "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null file-descriptor path (lines 7-14). It neither sets _ARGCOMPLETE_STDOUT_FILENAME nor reads that file when ARGCOMPLETE_USE_TEMPFILES=1, so completion data written to a tempfile cannot reach COMPREPLY in Git Bash, whose file-descriptor behavior differs from Linux Bash.

    Affected code
    • az.completion › _az_python_argcomplete (line 1)
    • src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py › ArgcompleteScenarioTest.test_top_level_completion (line 68)
    Ruled out
    • Configuration: The reporter explicitly enabled ARGCOMPLETE_USE_TEMPFILES and showed that the same CLI 2.90.0 produces completions with a wrapper that sets and reads the tempfile; the current wrapper cannot consume that setting.
    • Environment: Windows Git Bash and MSI determine where the mismatch appears, but the missing tempfile branch is visible in the shared completion script; the reporter identifies this environment and a working alternative.
    • Intended behavior: An older discussion notes Git Bash is not supported by this Bash file because Windows file descriptors differ. That explains current behavior, not why the requested opt-in tempfile support cannot be added; retain the existing Bash path for other environments.
    Proposed change

    Update the handwritten root az.completion _az_python_argcomplete to use a secure temporary file, pass _ARGCOMPLETE_STDOUT_FILENAME, read completion results and clean up on every exit when ARGCOMPLETE_USE_TEMPFILES=1; retain the descriptor-based path when unset, preserving COMPREPLY, exit status and nospace semantics. Document Git Bash setup if needed so Windows MSI users source the correct script.

    Technical details

    Evidence

    • az.completion:7-14 redirects descriptors and uses command-substitution output; there is no tempfile branch or _ARGCOMPLETE_STDOUT_FILENAME reference in this 21-line script.
    • src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py:14-22 and 68-84 test the CLI tempfile output for az , but skip this test on win32; they do not exercise the Bash wrapper.
    • [bash completion] _az_python_argcomplete generates empty output in Git Bash #26051 documents the same Git Bash descriptor limitation; this report adds a tested tempfile-aware shell workaround with CLI 2.90.0.

    Reproduction

    The fixed ARM-command sandbox cannot simulate interactive Git Bash on Windows; this is a source-backed analysis of the reported behavior, not a verified live reproduction.

    Test plan

    Add a shell-level regression test invoking the root az.completion function with a stub completion command that writes to _ARGCOMPLETE_STDOUT_FILENAME; assert az command candidates, cleanup, error handling and spacing, plus unchanged descriptor behavior when tempfiles are disabled. Cover Git Bash on Windows where available; keep the existing Python tempfile-output tests, which do not cover the shell wrapper. This interactive Git Bash/Windows flow cannot be exercised by the Azure ARM ReproSpec sandbox.

    Generated code: Handwritten code. az.completion is a checked-in, 21-line handwritten Bash function; it is not under aaz/ or an AutoRest-generated path.

    Live reproduction (BAMI sandbox) — Inconclusive

    Verdict: Inconclusive: the sandbox could not run the reproduction to the end.
    Reason: the problem cannot be expressed as allowed sandbox commands.
    The analysis above is based on reading the code only, so its confidence is capped at low.

    Commands ran in an isolated Azure sandbox subscription from a validated ReproSpec; output is redacted.

    Posted by x-engineering-agent (Fixer)

  3. x-engineering-agent commented on Oct 20, 2026

    @x-engineering-agent
    Contributor

    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:

    • Changing root az.completion would address the verified cause directly, but this file is excluded by the host publication allowlist.
    • Adding a replacement function in documentation is permitted by the source allowlist but does not implement the requested checked-in wrapper fix; no workaround documentation was …
    • Changing src/azure-cli/az.completion.sh would affect the register-python-argcomplete integration rather than the root wrapper sourced in the reported reproduction, so it would not resolve the specified failure.

    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)

  4. a0x1ab commented on Oct 20, 2026

    @a0x1ab
    Member

    Approved: update the root az.completion to support ARGCOMPLETE_USE_TEMPFILES=1 as proposed, keeping the existing descriptor path when it's unset.

  5. added
    agent: reproducingThe Agent is reproducing this issue in a sandbox
    and removed
    agent: reproducingThe Agent is reproducing this issue in a sandbox
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Service AttentionThis issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions