clear-host — Clear the terminal scrollback — clear / cls equivalent across all 5 shells
Equivalents in every shell
clearExternal tool (`/usr/bin/clear`) from `ncurses-bin`. Sends the terminal-specific clear sequence read from `terminfo`. The keyboard shortcut `Ctrl+L` does the same thing without forking. For a hard reset (including weird terminal state), `reset` is the heavier hammer.
clearSame external `clear`. Zsh adds `clear-screen` as a ZLE widget bound to `Ctrl+L` by default — same effect, faster (no fork). To remap to another key: `bindkey "^X" clear-screen`.
clearSame external `clear`. Fish binds `Ctrl+L` to the `clear-screen` function by default; `bind \ck clear-screen` to also map `Ctrl+K`. `clear` in fish 3.4+ is an alias for the external binary.
Clear-HostAliased as `cls`, `clear`. Implemented as a function (not a cmdlet) that calls `$Host.UI.RawUI.Clear()` if available, otherwise falls back to a sequence of `Write-Host` newlines. Visible behaviour matches `clear` / `cls` on every terminal.
clsBuilt-in. Clears the visible buffer; on Windows Terminal it also resets the scrollback (older Win10 conhost preserves the scrollback off-screen). No options. The PowerShell `cls` alias works in pwsh, not in cmd — they happen to share the name.
Worked examples
Clear the screen interactively
clearclearClear-HostclsClear inside a script
printf "\033[H\033[2J"[Console]::Clear()Bind a custom hotkey to clear
bindkey "^X" clear-screenSet-PSReadLineKeyHandler -Chord Ctrl+x -Function ClearScreenGotchas
- `Clear-Host` is a FUNCTION, not a cmdlet — you can `Get-Content Function:Clear-Host` to see the body. On terminals that don't support the necessary RawUI methods (some redirected or null hosts), it silently does nothing instead of erroring.
- Clearing does NOT wipe the scrollback by default — historical content is just scrolled above the visible top. To also clear the scrollback in pwsh, use `[Console]::Clear()` (calls .NET directly) or send the ANSI sequence `Write-Host "`e[3J"` (`ESC[3J`). Windows Terminal honours `e[3J`; older conhost ignores it.
- Inside `Invoke-Command` or remote sessions, `Clear-Host` clears the LOCAL host's view, not the remote — it has no remote effect. Use `Invoke-Command -ScriptBlock { Clear-Host }` to clear on the remote side, but this is rarely useful because remote output is collected and displayed all-at-once locally.
- `cls` is a pwsh ALIAS pointing to `Clear-Host` — it does NOT invoke the cmd-builtin `cls.exe` (no such binary exists). The cmd `cls` only works inside cmd.exe. Cross-shell muscle memory works because the aliases align, not because the underlying mechanism is the same.
- `clear` and `cls` aliases are present on every pwsh platform — but on Linux/macOS pwsh, `& clear` (forced external resolution) reaches `/usr/bin/clear` which uses terminfo for terminal-specific sequences. The cmdlet form via `$Host.UI` is usually fine; the external form is safer if you're running inside an emulator with non-standard escape handling.