Closing a PowerShell window by accident feels worse than it is. There's no single 'undo close' shortcut for PowerShell, but the two things you actually need back — the commands you ran and the program that was running — are almost always recoverable. PowerShell saves your command history to a file that survives the window, Windows Terminal can restore tabs on relaunch, and well-behaved CLI tools persist their own state. Here's how to get everything back.
Closed a window that had Claude Code running in it? Your conversation is saved on disk and doesn't depend on the terminal at all. See How to recover an accidentally closed Claude Code session, then use this guide to reopen the window itself.
Quick Reference
| Goal | How |
|---|---|
| Recover commands from a closed window | New window → Ctrl+R reverse search, or open ConsoleHost_history.txt |
| Find the history file path | (Get-PSReadLineOption).HistorySavePath |
| Restore Windows Terminal tabs on launch | Settings → Startup → restore previous session |
| Keep a job alive across closes | Run it as a background job or a service, not in the foreground |
| Resume a tool's saved state | Use that tool's resume feature (e.g. Claude Code's claude --continue) |
Recover Your Commands (Works Even After a Force-Close)
This is the part most people want back, and it's the most reliable. PSReadLine, the module behind the PowerShell command line, saves every command you type to a persistent file shared across all sessions — so commands from a window you already closed are still there.
Read the history file
# Show the exact path to the history file
(Get-PSReadLineOption).HistorySavePath
# Print every saved command (from all past windows)
Get-Content (Get-PSReadLineOption).HistorySavePath
# Search it for something specific
Get-Content (Get-PSReadLineOption).HistorySavePath | Select-String "git push"
The default location is:
%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
(For PowerShell 7 it's the same PSReadLine folder under %APPDATA%.) You can also just open that file in Notepad.
Search interactively in a new window
Open any new PowerShell window and:
- Press the Up arrow to step back through history.
- Press Ctrl+R and start typing to reverse-search the persistent history — this includes commands from the window you closed.
- Press F8 to search history matching what you've already typed.
Get-History vs. PSReadLine:
Get-Historyand the up arrow within a session only show that single window's commands, which are lost when it closes. The PSReadLine file is the one that persists across windows — that's what recovers a closed window's commands.
Reopen the Window Itself
Windows Terminal (Windows 11 default)
Windows Terminal can bring back your tabs and panes when it relaunches:
-
Open Settings (Ctrl+,).
-
Go to Startup.
-
Set "When Terminal starts" to restore the previous session. In the JSON this is:
"firstWindowPreference": "persistedWindowLayout" -
Save. Now closing and reopening Windows Terminal restores your tabs.
This restores on relaunch of the app, not on a single tab you closed with Ctrl+Shift+W while the window stays open. There's no per-tab "reopen closed tab" in Windows Terminal the way browsers have one.
Classic console (conhost) PowerShell
The standalone blue/black PowerShell window (conhost, the Windows PowerShell 5.1 default) has no restore feature at all. Recovery here is entirely via the PSReadLine history file above. Press F7 to see a popup of the current session's history — but remember that's only the current window; use the PSReadLine file for the closed one.
Don't Lose the Running Program
Closing the window kills whatever was running in the foreground. To keep work alive next time:
# Run a long task as a background job that survives... the session, at least
Start-Job -ScriptBlock { ./long-task.ps1 }
Get-Job # list jobs
Receive-Job -Id 1 # collect output
For anything that truly must outlive the terminal (servers, schedulers), run it as a Windows service or a Scheduled Task rather than inside an interactive window. And for SSH-into-Linux work, start tmux or screen on the remote side so a dropped window only detaches the session.
Resuming Tools That Save Their Own State
The best case is a tool that persists its own state to disk and doesn't care that the window closed. Claude Code is the clearest example: it writes every conversation to a transcript file under your home folder (%USERPROFILE%\.claude\projects\). The window closing deletes nothing — you open a new terminal, cd back to your project, and run:
claude --continue # resume the most recent conversation in this directory
# or
claude --resume # pick from a list of past sessions
The full walkthrough — how the transcript files are organized and how to resume from any window — is in How to recover an accidentally closed Claude Code session.
Summary
- There's no one-key undo for a closed PowerShell window, but your work is recoverable.
- PSReadLine saves every command to
ConsoleHost_history.txt— read it withGet-Content (Get-PSReadLineOption).HistorySavePathor Ctrl+R in a new window. - Windows Terminal can restore tabs on relaunch via the Startup setting; classic conhost cannot.
- Run long jobs as background jobs / services / scheduled tasks so a closed window doesn't kill them.
- Tools like Claude Code persist their own state — just reopen a terminal and resume.