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. added
    customer-reported
    on Sep 30, 2026
  3. added
    Service Attention
    on Sep 30, 2026
  4. added
    Request X Engineering Agent
    on Oct 20, 2026
  5. x-engineering-agent commented on Oct 20, 2026

    @x-engineering-agent
    Contributor

    X Engineering Agent Bug analysis: Root cause analysis

    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
    • Configuration: The reported shell explicitly exports ARGCOMPLETE_USE_TEMPFILES=1 and sources the stock script; core tests establish that both variables are needed for file output. The missing filename/read logic is in the script, not a missing user setting.
    • Environment: Git Bash uses different file descriptor semantics, but this is the supported Windows shell scenario under discussion; the same script fails in a validated Windows Git Bash sandbox on three CLI revisions.
    • Intended behavior: The original descriptor path remains appropriate when tempfile mode is unset; a maintainer approved extending the root script for ARGCOMPLETE_USE_TEMPFILES=1 while preserving that path.
    🛠️ 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
    • Introduced by: 1271aa0 in Packaged release 0.1.7 for Debian & Docker #1808 (2017-01-23), the Debian/Docker packaged-release change introducing the current descriptor-based body; the function was renamed in f6ea6fc / {Misc.} Change name of Bash completion function #23287 (2022-12-01).
    • Original intent: Provide Bash completion by redirecting CLI completion output through the argcomplete descriptor protocol and preserving Bash nospace/error behavior.
    • Does the fix keep that intent: Yes. Add an opt-in tempfile transport for shells needing it, retaining the descriptor invocation and completion formatting for existing Bash users.
    ⏱️ 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.

    Earlier related reports

    💥 Blast radius
    • Other callers: The root az.completion function is registered for az and affects all commands completed by users who source that script; Debian and RPM packaging also consume the root file. The separate src/azure-cli/az.completion.sh uses register-python-argcomplete and is not the target.
    • Visible change for them: Only root-script users opting into ARGCOMPLETE_USE_TEMPFILES=1 use a temporary file; default Bash users continue using the original descriptor transport and completion/nospace behavior.
    • Why not a narrower fix: The missing tempfile handshake is in the shared shell wrapper before command-specific completion; a change to a single command module or to argcomplete parsing would not repair Git Bash for all az commands.
    🔬 Technical details

    Evidence

    • az.completion lines 1-19 contain only the descriptor-based invocation, COMPREPLY assignment, exit-status handling and nospace behavior; there is no tempfile branch.
    • src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py already sets ARGCOMPLETE_USE_TEMPFILES and _ARGCOMPLETE_STDOUT_FILENAME and asserts real az completion output in the file, including top-level account.
    • Windows Git Bash offline reproduction run 39979046193 observed NO_AZ_SUBCOMMAND_COMPLETIONS with the stock script on reported, latest and dev.

    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.

    Version Result Evidence
    2.90.0 (reported) Reproduced exit 0
    2.91.0 (latest) Reproduced exit 0
    dev @ 0fb5754 Reproduced exit 0
    Steps run (redacted)

    2.90.0 (reported)

    repro: bash: if ! command -v az >/dev/null 2>&1 || [[ ! -r "$REPRO_SOURCE_DIR/az.completion" ]]; then echo "REPRO_SETUP_MISSING_CLI_OR_SOURCE" >&2 exit 1 fi export ARGCOMPLETE_USE_TEMPFILES=1 source "$REPRO_SOURCE_DIR/az.completion" COMP_LINE='az ' COMP_POINT=3 COMP_TYPE=9 COMP_WORDS=(az '') COMP...
    

    2.91.0 (latest)

    repro: bash: if ! command -v az >/dev/null 2>&1 || [[ ! -r "$REPRO_SOURCE_DIR/az.completion" ]]; then echo "REPRO_SETUP_MISSING_CLI_OR_SOURCE" >&2 exit 1 fi export ARGCOMPLETE_USE_TEMPFILES=1 source "$REPRO_SOURCE_DIR/az.completion" COMP_LINE='az ' COMP_POINT=3 COMP_TYPE=9 COMP_WORDS=(az '') COMP...
    

    dev @ 0fb5754

    repro: bash: if ! command -v az >/dev/null 2>&1 || [[ ! -r "$REPRO_SOURCE_DIR/az.completion" ]]; then echo "REPRO_SETUP_MISSING_CLI_OR_SOURCE" >&2 exit 1 fi export ARGCOMPLETE_USE_TEMPFILES=1 source "$REPRO_SOURCE_DIR/az.completion" COMP_LINE='az ' COMP_POINT=3 COMP_TYPE=9 COMP_WORDS=(az '') COMP...
    

    Sandbox run

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

    X Engineering Agent · Fixer · react 👍 / 👎 to train the agent

  6. 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)

  7. 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.

  8. added
    Request X Engineering Agent
    and removed
    Request X Engineering Agent
    on Oct 20, 2026
  9. added
    agent: reproducing
    and removed
    agent: reproducing
    Request X Engineering Agent
    on Oct 20, 2026
  10. added
    Request X Engineering Agent
    on Oct 23, 2026
  11. 3 remaining items

  12. removed
    agent: reproducing
    Request X Engineering Agent
    on Oct 23, 2026
  13. added
    Request X Engineering Agent
    on Oct 23, 2026
  14. added
    agent: reproducing
    and removed
    agent: reproducing
    Request X Engineering Agent
    on Oct 23, 2026
  15. added
    Request X Engineering Agent
    on Oct 23, 2026
  16. added
    agent: reproducing
    and removed
    agent: reproducing
    Request X Engineering Agent
    on Oct 23, 2026
  17. added 2 commits that reference this issue on Oct 24, 2026
    e709fb5
    52ebc9e
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 Attentioncustomer-reported

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions