@@ -142,8 +142,9 @@ func runCopilot(opts *CopilotOptions) error {
142142 return nil
143143 }
144144
145- copilotPath := findCopilotBinary ()
146- if copilotPath == "" {
145+ copilotPath := findCopilotBinaryFunc ()
146+ foundInPath := copilotPath != ""
147+ if ! foundInPath {
147148 if opts .IO .CanPrompt () {
148149 confirmed , err := opts .Prompter .Confirm ("GitHub Copilot CLI is not installed. Would you like to install it?" , true )
149150 if err != nil {
@@ -175,12 +176,18 @@ func runCopilot(opts *CopilotOptions) error {
175176 externalCmd .Stderr = opts .IO .ErrOut
176177 externalCmd .Env = append (os .Environ (), "COPILOT_GH=true" )
177178
178- if err := externalCmd . Run ( ); err != nil {
179+ if err := runExternalCmdFunc ( externalCmd ); err != nil {
179180 if exitErr , ok := err .(* exec.ExitError ); ok {
180181 // We terminate with os.Exit here, preserving the exit code from Copilot CLI,
181182 // and also preventing stdio writes by callers up the stack.
182183 os .Exit (exitErr .ExitCode ())
183184 }
185+ if foundInPath {
186+ // We found a `copilot` binary but exec failed, possibly due to
187+ // unusual characters in the path (see https://github.com/cli/cli/issues/13106).
188+ // Suggest running copilot directly as a workaround.
189+ return fmt .Errorf ("%w\n Failed to run '%s', try running `copilot` directly without `gh`." , err , copilotPath )
190+ }
184191 return err
185192 }
186193 return nil
@@ -200,6 +207,14 @@ func copilotBinaryPath() string {
200207 return filepath .Join (copilotInstallDir (), binaryName )
201208}
202209
210+ var runExternalCmdFunc = runExternalCmd
211+
212+ func runExternalCmd (cmd * exec.Cmd ) error {
213+ return cmd .Run ()
214+ }
215+
216+ var findCopilotBinaryFunc = findCopilotBinary
217+
203218// findCopilotBinary returns the path to the Copilot CLI binary, if installed,
204219// with the following order of precedence:
205220// 1. `copilot` in the PATH
0 commit comments