Title: Enter-PSSession - Clear-Host on non-Windows target fails · Issue #28118 · PowerShell/PowerShell · GitHub
Open Graph Title: Enter-PSSession - Clear-Host on non-Windows target fails · Issue #28118 · PowerShell/PowerShell
X Title: Enter-PSSession - Clear-Host on non-Windows target fails · Issue #28118 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/28118
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enter-PSSession - Clear-Host on non-Windows target fails","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nWhen connecting to a non-Windows target (Linux, macOS), the `clear` command resolves to the `/usr/bin/clear` command and `Clear-Host` is a thin wrapper around calling `/usr/bin/clear` and writing those values to the console.\n\n```powershell\n${function:Clear-Host}\n\n[Console]::Write((\n & (Get-Command -CommandType Application clear | Select-Object -First 1).Definition\n))\n# .Link\n# https://go.microsoft.com/fwlink/?LinkID=2096480\n# .ExternalHelp System.Management.Automation.dll-help.xml\n```\n\nThis has two problems:\n\n1. SSH subsystems strip the `TERM` env var needed for `/usr/bin/clear` to work\n\n\u003cimg width=\"654\" height=\"205\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/f6c7e030-f692-4e3c-984d-6cddd9d96fc0\" />\n\n3. Direct console calls are a no-op due to the console stdout being used for PSRP messages\n\n\u003cimg width=\"857\" height=\"205\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/9fb74fea-c828-48b5-8f5e-784b732129de\" />\n\nThe only way to get this working is to explicitly set `$env:TERM = '...'` but this cannot be set generically as it must match up with the `TERM` you are using locally. You probably can just set it to `xterm` and it'll match your terminal locally but there's no guarantee that you actually use an `xterm` compatible terminal. In my case I do and setting it will work.\n\nhttps://github.com/user-attachments/assets/c085c8a8-a328-46e7-837e-c738fdc882bb\n\nThere is a slight side effect in that the console cursor is one line down due to the sequence of processing the new prompt after running a command but that is more cosmetic.\n\nRunning `Clear-Host` rather than `clear` fails because of the `[Console]::Write(clear)` doing to `/dev/null` even with `$env:TERM` explicitly set.\n\nhttps://github.com/user-attachments/assets/1d629a40-8119-4153-b818-918659e71b65\n\nWhat I really think should be happening to fix this is for a remote PSSession on non-Windows to act more like how a Windows target works in that:\n\n+ It defines an alias for `clear` to point to `Clear-Host`\n+ Has `Clear-Host` run the following (like on Windows)\n+ Both of these only apply when connecting to a PSRemoting endpoint, normal PowerShell sessions keep the existing clear/Clear-Host behaviour\n\n```powershell\n# ${function:Clear-Host}\n\n$RawUI = $Host.UI.RawUI\n$RawUI.CursorPosition = @{X=0;Y=0}\n$RawUI.SetBufferContents(\n @{Top = -1; Bottom = -1; Right = -1; Left = -1},\n @{Character = ' '; ForegroundColor = $rawui.ForegroundColor; BackgroundColor = $rawui.BackgroundColor})\n# .Link\n# https://go.microsoft.com/fwlink/?LinkID=2096480\n# .ExternalHelp System.Management.Automation.dll-help.xml\n```\n\nThis means the clear operation goes to the actual PSRemoting host call method with known values and this is interpreted locally to call `Console.Clear()` or `/usr/bin/clear` if desired. The remote side continues to stay agnostic of the `TERM` setting and has the local client handle all that as it is better suited to managing the terminal which is actually local.\n\nPlease note this is different to https://github.com/PowerShell/PowerShell/issues/28115 which is specifically around connecting to a Windows target from a non-Windows client. This is about connecting to a non-Windows target from any client.\n\n### Expected behavior\n\n```console\nThe console is cleared\n```\n\n### Actual behavior\n\n```console\n`/usr/bin/clear` outputs `TERM environment not set.` and nothing is cleared.\n```\n\n### Error details\n\n```console\nNo error, the output is from `/usr/bin/term`\n```\n\n### Environment data\n\n```powershell\nNot applicable, present on all PowerShell 7.x versions on non-Windows targets\n```\n\n### Visuals\n\nSee steps to reproduce.","author":{"url":"https://github.com/jborean93","@type":"Person","name":"jborean93"},"datePublished":"2026-09-28T18:50:08Z","url":"https://github.com/PowerShell/PowerShell/issues/28118"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a5441bb1-9af1-ff8d-eefc-e01ba5258411 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E752:2258C3:22DBF2:2F6451:6AFD51EE |
| html-safe-nonce | 89ee8d2ac4464d83c74b8fb16615a08f0e8cc66488b62bfd9f188fbfa4f520a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzUyOjIyNThDMzoyMkRCRjI6MkY2NDUxOjZBRkQ1MUVFIiwidmlzaXRvcl9pZCI6IjMxMDEyNDI5NDI0NTExNzU5MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 42792550985c0f01af25cf331ad6ace82f6d6267e9e69e13bd748e4a651b2f16 |
| hovercard-subject-tag | issue:5619591314 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/28118/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5549c5817a6adaec3f498d18531b6d809f27867e98463b38cc9ee5bf0306795d/PowerShell/PowerShell/issues/28118 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5549c5817a6adaec3f498d18531b6d809f27867e98463b38cc9ee5bf0306795d/PowerShell/PowerShell/issues/28118 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jborean93 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width