If you use Copilot inside your IDE (like 'VS Code' or 'Visual Studio 2026'), you may see commands you never typed in your Terminal history. These come from Copilot and IDE integrations that run commands in the terminal for tasks like reading files or reporting status. When you press Ctrl+R to search previous commands, this noise makes reverse search frustrating.

Why this Matters for productivity
Ctrl+R lets you quickly recall previous commands instead of retyping them. Keeping your history clean ensures instant access to the commands you actually use.
Four ways to fix it
There are several ways to fix this issue. Use a separate shell for Copilot by creating a dedicated terminal tab or profile, simple but not very convenient. Or, set $env:PSReadLineHistoryFile to a custom file for Copilot sessions to keep history separate. Third, filter commands from history using Set-PSReadLineOption -AddToHistoryHandler to exclude patterns like 'gh copilot'. Finally, create a wrapper function that runs Copilot while temporarily disabling history.
My choice: Separate history files
I prefer storing PowerShell history in different files based on the environment. For interactive shells (like 'Windows Terminal'), keep a clean history for real typed commands. For IDE shells (such as 'VS Code' or 'Visual Studio'), use a separate history file or disable history entirely.
Copy-Paste the following Script and add it to your ($PROFILE)
# 1) Ensure PSReadLine module is loaded
if (-not (Get-Module -Name PSReadLine)) {
Import-Module PSReadLine -ErrorAction SilentlyContinue
}
$inVSCode = ($env:TERM_PROGRAM -eq 'vscode')
$inVisualStudio = ($env:VisualStudioVersion -ne $null)
# 2) Host detection: split history per host
if ($inVSCode -or $inVisualStudio) {
$historyPath = Join-Path $env:USERPROFILE '.ps_history_ide.txt'
# Optional: uncomment to disable history in IDE
# Set-PSReadLineOption -HistorySaveStyle SaveNothing
} else {
$historyPath = Join-Path $env:USERPROFILE '.ps_history_interactive.txt'
}
# 3) Ensure file exists
if (-not (Test-Path $historyPath)) {
New-Item -ItemType File -Path $historyPath -Force | Out-Null
}
# 4) Configure PSReadLine to use this file and save incrementally
Set-PSReadLineOption -HistorySavePath $historyPath
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Check your profile path:
$PROFILE
Create the file if it doesn’t exist:
if (-not (Test-Path -Path $PROFILE)) {
New-Item -Type File -Path $PROFILE -Force | Out-Null
}
Open your profile in an editor:
notepad $PROFILE
or:
code $PROFILE
Paste the above script and save.
After setup checklist
Reload your $PROFILE and or restart 'VS Code' / 'Visual Studio' and 'Windows Terminal'.
Verify the active history file:
(Get-PSReadLineOption).HistorySavePath
Result
Your interactive PowerShell history stays clean for Ctrl+R, while IDE sessions keep their own history (or none at all). No risk of losing legitimate commands, and no more clutter from Copilot or IDE integrations.