@@ -540,11 +540,15 @@ setup_completions() {
540540 local bash_comp_raw=" "
541541 local bash_comp_output=" "
542542 bash_comp_raw=$( timeout 30 claude completions bash < /dev/null 2> /dev/null) || true
543- # Strip ANSI codes then extract from the first valid completion line onwards.
544- # This discards any Node.js warnings or other preamble that precede the script.
543+ # Strip \r (CRLF), ANSI codes, and known Node.js warning lines, then keep
544+ # everything from the first non-blank line onwards. This is more robust than
545+ # anchoring on a specific first character, since the completion format varies
546+ # across Claude Code versions and some wrap the script in an `if` block.
545547 bash_comp_output=$( printf ' %s' " ${bash_comp_raw} " |
548+ tr -d ' \r' |
546549 sed " s/${esc} \[[0-9;]*[a-zA-Z]//g" |
547- sed -n ' /^[_#]/,$p' )
550+ sed ' /^(node:[0-9]/d; /^Use .* --trace-warnings/d' |
551+ sed -n ' /[^ ]/,$p' )
548552 if [[ -n " ${bash_comp_output} " ]]; then
549553 printf ' %s\n' " ${bash_comp_output} " > " ${bash_comp_dir} /claude"
550554 elif [[ -n " ${bash_comp_raw} " ]]; then
@@ -560,10 +564,12 @@ setup_completions() {
560564 local zsh_comp_raw=" "
561565 local zsh_comp_output=" "
562566 zsh_comp_raw=$( timeout 30 claude completions zsh < /dev/null 2> /dev/null) || true
563- # Strip ANSI codes then extract from the first valid completion line onwards .
567+ # Strip \r, ANSI codes, and Node.js warning preamble; keep from first non-blank line .
564568 zsh_comp_output=$( printf ' %s' " ${zsh_comp_raw} " |
569+ tr -d ' \r' |
565570 sed " s/${esc} \[[0-9;]*[a-zA-Z]//g" |
566- sed -n ' /^#compdef/,$p' )
571+ sed ' /^(node:[0-9]/d; /^Use .* --trace-warnings/d' |
572+ sed -n ' /[^ ]/,$p' )
567573 if [[ -n " ${zsh_comp_output} " ]]; then
568574 printf ' %s\n' " ${zsh_comp_output} " > /usr/share/zsh/site-functions/_claude
569575 elif [[ -n " ${zsh_comp_raw} " ]]; then
@@ -585,10 +591,12 @@ setup_completions() {
585591 local fish_comp_raw=" "
586592 local fish_comp_output=" "
587593 fish_comp_raw=$( timeout 30 claude completions fish < /dev/null 2> /dev/null) || true
588- # Strip ANSI codes then extract from the first valid completion line onwards .
594+ # Strip \r, ANSI codes, and Node.js warning preamble; keep from first non-blank line .
589595 fish_comp_output=$( printf ' %s' " ${fish_comp_raw} " |
596+ tr -d ' \r' |
590597 sed " s/${esc} \[[0-9;]*[a-zA-Z]//g" |
591- sed -n ' /^complete/,$p' )
598+ sed ' /^(node:[0-9]/d; /^Use .* --trace-warnings/d' |
599+ sed -n ' /[^ ]/,$p' )
592600 if [[ -n " ${fish_comp_output} " ]]; then
593601 printf ' %s\n' " ${fish_comp_output} " > " ${fish_comp_dir} /claude.fish"
594602 elif [[ -n " ${fish_comp_raw} " ]]; then
0 commit comments