You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AI/agent terminal sessions pollute PSReadLine history #5123
When AI agents (e.g., GitHub Copilot, VS Code terminal agents) execute commands in PowerShell terminals, those commands are saved to PSReadLine history indistinguishably from user-typed commands. This pollutes history recall with commands the user never typed, inflates frequency counts, and degrades the usefulness of history recall.
Problem
AI coding assistants routinely run commands like Get-ChildItem, dotnet build, git status, etc. in integrated terminals. These get recorded to PSReadLine history (both text file and SQLite modes) as if the user typed them. Over time this means:
History recall is noisy — Up arrow surfaces agent commands the user didn't type
Frequency-based ranking is skewed — location-aware recall ranks agent-repeated commands higher than user favorites
HistoryNoDuplicates doesn't help — the commands are real commands, just not user-initiated
Current Workaround
Users can add this to their $PROFILE:
# Requires the agent to set this env var before launching pwshif ($env:PSREADLINE_HISTORY_SAVE-eq'0') {
Set-PSReadLineOption-AddToHistoryHandler { [Microsoft.PowerShell.AddToHistoryOption]::MemoryOnly }
}
But this is fragile because:
The agent must set the env var — requires cooperation from VS Code / Copilot
Agents that use pwsh -NoProfile bypass the check entirely
Users must manually add the snippet
Proposal
Add a built-in environment variable check in PSReadLine's initialization, so that agent-spawned terminals can opt out of persistent history without requiring profile configuration:
// During PSReadLine init, before any history writesif(Environment.GetEnvironmentVariable("PSREADLINE_HISTORY_SAVE")=="0"){Options.AddToHistoryHandler= _ =>AddToHistoryOption.MemoryOnly;}
This way:
Any agent framework just sets PSREADLINE_HISTORY_SAVE=0 as a process environment variable before launching pwsh
Works regardless of -NoProfile
No user configuration needed
Commands still available in the current session's memory (Up arrow works), just not persisted to disk
I think the problem is that we are conflating agent execution on behalf of a user and actual user execution & by current designs we allow for in user session agent execution. Agents should ideally be executing as their own identity, not the current users.
However the current designs for agents has not taken this into account in most cases & well it's possible that may never. But I really think we should push back on the agent execution on behalf of user being able to be done inside a users session as these should really be seperated, especially if you have 1,2 or 10 different agents working away for you. They need to ideally be fully process isolated & perhaps controllable and data retrievable via an extension to how we do Jobs today with ability to register a AgentJob to any User driven process.
That may allow for AgentCommands as a Prediction Source, which would then allow hiding these or short
That's a design point to discuss outside this repo though. I just mention it as I'd rather we looked at (perhaps alongside this) adding an Agent headless mode for users to be able to make use of that starts pwsh but as an agent. This would be user defined and align with JEA/PSSessionCapabilities.
That perhaps is via a -Agent flag on pwsh itself. not that I really like that idea too much tbh
But I'm concerned that adding PSREADLINE_HISTORY_SAVE is the quick fix for now that we'd never be able to move away from, even though I know that would enable some people in different scenarios too.
Activity
kilasuit commentedon Oct 15, 2026
I think the problem is that we are conflating
agent execution on behalf of a userandactual user execution& by current designs we allow for in user session agent execution. Agents should ideally be executing as their own identity, not the current users.However the current designs for agents has not taken this into account in most cases & well it's possible that may never. But I really think we should push back on the
agent execution on behalf of userbeing able to be done inside a users session as these should really be seperated, especially if you have 1,2 or 10 different agents working away for you. They need to ideally be fully process isolated & perhaps controllable and data retrievable via an extension to how we do Jobs today with ability to register a AgentJob to any User driven process.That may allow for
AgentCommandsas a Prediction Source, which would then allow hiding these or shortThat's a design point to discuss outside this repo though. I just mention it as I'd rather we looked at (perhaps alongside this) adding an Agent headless mode for users to be able to make use of that starts pwsh but as an agent. This would be user defined and align with JEA/PSSessionCapabilities.
That perhaps is via a -Agent flag on pwsh itself. not that I really like that idea too much tbh
But I'm concerned that adding
PSREADLINE_HISTORY_SAVEis the quick fix for now that we'd never be able to move away from, even though I know that would enable some people in different scenarios too.