Skip to content

Console left in raw/VT mode after copilot.exe exits - arrow keys show ^[[A (Windows) #1424

@machish

Description

@machish

Describe the bug

Description:

After copilot.exe exits (normally or abnormally), the Windows console is sometimes left in virtual terminal input mode instead of being restored to the default cooked mode.

Symptoms:

- Pressing Up arrow shows ^[[A instead of navigating command history
- Pressing Down arrow shows ^[[B
- Backspace behaves like Ctrl+Backspace (deletes whole words)
- Other arrow keys show their escape sequences (^[[C, ^[[D)

Workaround:

Running any external executable (e.g., xcopy a a ) restores normal console behavior.

Root Cause (as analyzed by Copilot):

The application enables ENABLE_VIRTUAL_TERMINAL_INPUT via SetConsoleMode() but fails to restore the original console mode on exit. This can happen if:

- The process is terminated unexpectedly
- Signal handlers don't properly clean up
- There's a race condition in the cleanup code

Expected Behaviour:

Console input mode should be saved on startup and restored on exit (including via atexit handlers and signal handlers for SIGINT/SIGTERM).

Environment:

- OS: Windows
- Shell: cmd

Affected version

GitHub Copilot CLI 0.0.407-1.

Steps to reproduce the behavior

  • Leave Copilot running for a while (e.g. overnight)
  • Have it abruptly exit (timeout?)
  • Console is left in a state where cursor keys output Escape sequences (e.g. ^[[A), backspace acts as ctrl+backpace.

Expected behavior

Console should behave normally.

Additional context

- OS: Windows
- Shell: cmd
- Chip: `x86-64`
- Console: Classing windows console (NOT windows terminal)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions