The 3J ANSI escape code does not clear the terminal. #23406

Closed
opened 2026-01-31 08:41:19 +00:00 by claunia · 2 comments
Owner

Originally created by @axololly on GitHub (Jun 30, 2025).

Windows Terminal version

1.22.11751.0

Windows build number

10.0.26100.0

Other Software

No response

Steps to reproduce

I tried to print the following in Python: "\x1b[3J".

Expected Behavior

I wanted the equivalent of Clear-Host to be executed in my terminal.

I distinctly remember this working beforehand, and then all of a sudden, it stopped. I even went through a Windows Update to see if that would solve the issue, but it still persisted.

Actual Behavior

This outputs as a literal invisible character and nothing happens to the terminal.

Originally created by @axololly on GitHub (Jun 30, 2025). ### Windows Terminal version 1.22.11751.0 ### Windows build number 10.0.26100.0 ### Other Software _No response_ ### Steps to reproduce I tried to print the following in Python: `"\x1b[3J"`. ### Expected Behavior I wanted the equivalent of `Clear-Host` to be executed in my terminal. I distinctly remember this working beforehand, and then all of a sudden, it stopped. I even went through a Windows Update to see if that would solve the issue, but it still persisted. ### Actual Behavior This outputs as a literal invisible character and nothing happens to the terminal.
claunia added the Resolution-By-DesignNeeds-TriageIssue-Bug labels 2026-01-31 08:41:20 +00:00
Author
Owner

@axololly commented on GitHub (Jun 30, 2025):

It seems to be an issue across both the Windows Terminal and also the old console host on my system.

I have the issue "solved" by simply outputting ESC[2J then ESC[3J then ESC[H, but is this really how it's supposed to function on Windows? I could've sworn it wasn't.

@axololly commented on GitHub (Jun 30, 2025): It seems to be an issue across both the Windows Terminal and also the old console host on my system. I have the issue "solved" by simply outputting `ESC[2J` then `ESC[3J` then `ESC[H`, but is this really how it's supposed to function on Windows? I could've sworn it wasn't.
Author
Owner

@DHowett commented on GitHub (Jun 30, 2025):

Recycling bits from another comment... :)

So! You've stumbled onto one of the great things that terminal emulators (and their authors!) disagree on!

Some of them, like gnome-terminal (libvte), Apple Terminal, and Windows Terminal implement CSI 2 J (ED Erase in Display All) as "push the contents of the viewport into scrollback". There is some disagreement on whether it should be only the actual used lines or the whole viewport.

Others (xterm, rxvt) implement it as (I believe) "destroy the current screenful of content."

There's been some other discussion about this: #7894 (summary here: #7894 (comment)) #2832 (comment)

Consensus among application authors is that they should just clear the scrollback on those terminals which require it. If you look at the output of clear, for example, on gnome-terminal: \e[H\e[2J\e[3J.

This is likely why clear also sports an argument to "try not to clear the scrollback", -x.

Image

The most common behavior we've seen among terminal emulators is this:

ED 3 only clears the scrollback.

ED 2 only clears the viewport.

@DHowett commented on GitHub (Jun 30, 2025): Recycling bits from another comment... :) > So! You've stumbled onto one of the great things that terminal emulators (and their authors!) disagree on! > > Some of them, like gnome-terminal (libvte), Apple Terminal, and Windows Terminal implement `CSI 2 J` (ED Erase in Display All) as "push the contents of the viewport into scrollback". There is some disagreement on whether it should be only the actual used lines or the whole viewport. > > Others (xterm, rxvt) implement it as (I believe) "destroy the current screenful of content." > > There's been some other discussion about this: [#7894](https://github.com/microsoft/terminal/issues/7894) (summary here: [#7894 (comment)](https://github.com/microsoft/terminal/issues/7894#issuecomment-714854915)) [#2832 (comment)](https://github.com/microsoft/terminal/issues/2832#issuecomment-533779605) > > Consensus among application authors is that they should just clear the scrollback on those terminals which require it. If you look at the output of `clear`, for example, on gnome-terminal: `\e[H\e[2J\e[3J`. > > This is likely why `clear` also sports an argument to "try not to clear the scrollback", `-x`. > > ![Image](https://github.com/user-attachments/assets/a00811f9-f6f7-45ec-b8d4-972b600c3756) The most common behavior we've seen among terminal emulators is this: ED 3 _only clears the scrollback._ ED 2 _only clears the viewport._
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23406