AI/agent terminal sessions pollute PSReadLine history
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
Research direction
Start by locating PSReadLine initialization and the AddToHistoryHandler/history persistence path, including the text and SQLite modes mentioned in the issue. Confirm that PSREADLINE_HISTORY_SAVE=0 selects MemoryOnly before history writes, preserves current-session recall, and avoids persistent saves regardless of profile loading.
Written by the indexing model from the issue text.
Description
Summary
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
HistoryNoDuplicatesdoesn'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 pwsh
if ($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 -NoProfilebypass 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 writes
if (Environment.GetEnvironmentVariable("PSREADLINE_HISTORY_SAVE") == "0")
{
Options.AddToHistoryHandler = _ => AddToHistoryOption.MemoryOnly;
}
This way:
- Any agent framework just sets
PSREADLINE_HISTORY_SAVE=0as 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
Environment
- VS Code with GitHub Copilot agent terminals
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 341
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PowerShell/PSReadLine
-
Needs-Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSReadLine#5205 ·
-
Needs-Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
PowerShell/PSReadLine#5195 ·
-
Needs-Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PowerShell/PSReadLine#5121 ·
-
Needs-Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
PowerShell/PSReadLine#5045 ·
-
Area-CommandHelp Issue-Enhancement
Difficulty 1/5 Under an hour Newbie friendliness 68/100
PowerShell/PSReadLine#3470 · 3 reactions ·
All issues in PowerShell/PSReadLine
Similar issues
-
:watch: Not Triaged dotnet-fsharp/svc
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Client customer-reported needs-team-attention question Service Attention WebPubSub
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Azure/azure-sdk-for-net#63292 · 3 comments · 1 reaction ·
-
Issue-Enhancement Needs-Triage
Difficulty 1/5 Under an hour Newbie friendliness 86/100
PowerShell/PowerShell#28061 · 2 reactions ·
-
dependencies needs-team-triage server-Azure.Mcp
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
aspnet-core/svc aspnetcore-signalr/subsvc doc-enhancement Pri2 SignalR
Difficulty 1/5 Under an hour Newbie friendliness 88/100
dotnet/AspNetCore.Docs#37729 ·