Contents
How to Remove a Specific Command from PowerShell History in VS Code
If you accidentally typed a password or sensitive command in the VS Code terminal using PowerShell, and you want to remove only that specific command from history, follow these steps:
π Step-by-Step Instructions
- Close the VS Code terminal to prevent file locking.
- Open File Explorer and go to the following path:
%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\\
- Locate and open the file:
ConsoleHost\_history.txt
- Scroll to the bottom of the file and delete the last line (or any specific line) containing the sensitive command.
- Save the file and close the editor.
- Reopen the VS Code terminal β the command is now removed from history.
β Notes
- This applies to PowerShell with PSReadLine, including the one embedded in VS Code.
- PowerShell doesnβt have a built-in command to remove individual history entries from the saved history file β manual editing is the only reliable method.
π Pro Tip
Be cautious when typing passwords or sensitive data directly into terminals. Use environment variables or secret management tools where possible.