Skip to content

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

@robinsujob

Description

@robinsujob

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 <deb name>

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)
command-issues-bug-report_2026325212146.mp4

Affected version

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:input-keyboardKeyboard shortcuts, keybindings, copy/paste, clipboard, mouse, and text input

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions