Clear screen in an iex session?

iex> clear
Cannot clear the screen because ANSI escape codes are not enabled on this shell

Question is, how do i enable the escape codes to clear the screen in an iex session.?
I don’t like having to restart the session every time i need a fresh screen.

Hello and welcome,

You could tell us on which OS You are… because it’s not obvious You are running Windows.

Maybe try this

Application.put_env(:elixir, :ansi_enabled, true)

If you’re on windows running from the command prompt here is some info I have kept when I was trying this

To enable ANSI colors in windows command prompt follow the below instructions Add the following registry key:

[HKEY_CURRENT_USER\Console] "VirtualTerminalLevel"=dword:00000001

For more indepth howto:
1 Like

I am actually using windows 10.
However, i don’t switch between my code editor(VS code) and command line.
I use the terminal within the editor, and thats where the error came from

Ok, You can try to type this in iex console…

iex> Application.put_env(:elixir, :ansi_enabled, true)

If it works, You can copy this line to your .iex.exs file


Get Windows Terminal (Preview) from Microsoft Store.
Then Application.put_env(:elixir, :ansi_enabled, true) and clear will work.

1 Like