AKZN Notes

Archives for My Lazy and Forgetful Mind

How to Remove a Specific Command from PowerShell History in VS Code

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

  1. Close the VS Code terminal to prevent file locking.
  2. Open File Explorer and go to the following path:

%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\\
  1. Locate and open the file:

ConsoleHost\_history.txt
  1. Scroll to the bottom of the file and delete the last line (or any specific line) containing the sensitive command.
  2. Save the file and close the editor.
  3. 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.

Leave a Reply

Your email address will not be published.