github / github/copilot-cli

[Bug]Copying commands from copilot cli includes invisible characters, causing "command not found" in external terminal

Đang mở
#2,285 4 bình luận 11 reaction 0 người được giao Xem trên GitHub
area:input-keyboard
Ngôn ngữ chính
Shell
Star
11.2k
Fork
1.9k
Merge trung bình
14 giờ 16 phút
Pull request đã merge (30 ngày)
6

Mô tả

### Describe the bug

# Bug: Copying commands from code blocks includes invisible characters, causing "command not found" in external terminal

## Description

When copying commands from Copilot CLI's rendered code blocks (using `ctrl+c` or right-click copy) and pasting them into another terminal tab, the pasted text contains invisible/hidden characters. This causes valid system commands like `df` and `du` to fail with "command not found", even though the commands appear visually correct.

Manually deleting the pasted text with Backspace and retyping the exact same command works perfectly.

## Steps to Reproduce

1. Launch Copilot CLI (`copilot`) in a terminal tab (e.g., Windows Terminal + WSL)
2. Ask: "give me a linux command, calc the disk size"
3. Copilot responds with commands including `df -h` and `du -sh .` in code blocks
4. Select and copy `df -h` from the code block (ctrl+c / right-click copy)
5. Switch to a **separate** terminal tab (same WSL instance)
6. Paste the command and press Enter

## Expected Behavior

`df -h` should execute normally and display filesystem disk usage.

## Actual Behavior

```
$ df -h
Command 'df' not found, did you mean:
command 'wdf' from deb wit (3.01a-4.1)
command 'df' from deb coreutils (9.4-3ubuntu6.2)
command 'kdf' from deb kdf (4:23.08.4-0ubuntu1)
command 'sdf' from deb sdf (2.001+1-9)
Try: sudo apt install
```

The same error occurs consistently when pasting. However, **pressing Backspace to delete the entire line and manually retyping `df -h` succeeds immediately**:

```
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdd 1007G 9.3G 947G 1% /
C:\ 952G 196G 757G 21% /mnt/c
...
```

This also reproduces with `du -sh .` and `du -sh /path/to/dir` copied from the code blocks — same "command not found" error on paste, works fine when manually typed.

## Additional Testing

Further manual testing confirms there is exactly **one invisible character prepended** before the visible command text:

1. After pasting `df -h`, move the cursor to the beginning of the line (Home key)
2. Press Right arrow once to move past the first "visible" character `d`
3. Press Backspace once to delete `d`, then retype `d` to restore the command → **still fails**
4. Move cursor to the beginning again, press Backspace **twice** (deleting both the invisible character and `d`), then retype `d` to restore the command → **succeeds**

This proves there is a **single hidden/non-printable character at the very beginning** of the copied text, before the first visible character. Deleting only the visible `d` and retyping it leaves the hidden character intact, so the command still fails. Deleting one extra character removes the hidden prefix, and the command works.

## Root Cause Hypothesis

The copied text from Copilot CLI code blocks contains exactly one invisible Unicode character (e.g., zero-width space U+200B, BOM U+FEFF, or other non-printable character) **prepended before the command text**. This character is part of the terminal rendering but should be stripped when copying to clipboard.

## Environment

- **Copilot CLI version**: 1.0.11
- **OS**: Ubuntu 24.04.4 LTS (WSL2)
- **Kernel**: 6.6.87.2-microsoft-standard-WSL2 (aarch64)
- **Terminal**: Windows Terminal
- **Shell**: Bash

## Video Evidence

A screen recording demonstrating the issue is available. Key observations:
- The bug is **100% reproducible** with paste
- The bug is **100% resolved** by Backspace + manual retype
- Both `df` and `du` are affected (not command-specific)
- Using Up arrow to recall the pasted command from history also fails (invisible characters persist in bash history)

https://github.com/user-attachments/assets/889447ee-0c0e-4647-b8bb-5cdd3a723bed

### Affected version

_No response_

### Steps to reproduce the behavior

_No response_

### Expected behavior

_No response_

### Additional context

_No response_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.