Skip to main content
Microsoftbeginner

How to Reopen a Closed PowerShell Window on Windows (and Recover Your Commands)

Closed a PowerShell or Windows Terminal window by accident? There's no one-key 'undo', but you can restore Windows Terminal tabs on relaunch, recover every command from PSReadLine history, and resume long-running CLI tools. Step-by-step for Windows 10/11.

7 min readUpdated June 2026

Want us to handle this for you?

Get expert help →

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

GoalHow
Recover commands from a closed windowNew window → Ctrl+R reverse search, or open ConsoleHost_history.txt
Find the history file path(Get-PSReadLineOption).HistorySavePath
Restore Windows Terminal tabs on launchSettings → Startup → restore previous session
Keep a job alive across closesRun it as a background job or a service, not in the foreground
Resume a tool's saved stateUse 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-History and 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:

  1. Open Settings (Ctrl+,).

  2. Go to Startup.

  3. Set "When Terminal starts" to restore the previous session. In the JSON this is:

    "firstWindowPreference": "persistedWindowLayout"
    
  4. 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 with Get-Content (Get-PSReadLineOption).HistorySavePath or 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.

Frequently Asked Questions

Find answers to common questions

There is no single universal 'reopen closed window' shortcut for PowerShell. Windows Terminal can restore your previous tabs and panes when it relaunches if you enable the 'restore' startup setting, but the classic conhost PowerShell window has no restore feature. What is always recoverable is your command history: PSReadLine saves every command you typed to a file (ConsoleHost_history.txt), so you can get your work back even from a window that was force-closed.

PSReadLine — the module that powers PowerShell's command line — persists history to a text file across all sessions. The default path is %APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt. Run (Get-PSReadLineOption).HistorySavePath to see the exact location. Open it in Notepad or run Get-Content (Get-PSReadLineOption).HistorySavePath to read every command from past windows, including the one you just closed.

Get-History (and the up arrow within one session) only shows commands from the current window's session and is lost when that window closes. PSReadLine's history file persists across every window and survives closing the terminal — that's the one that recovers commands from a closed window. Press Ctrl+R in any new PowerShell window to reverse-search the persistent PSReadLine history.

Open Windows Terminal Settings (Ctrl+,), go to Startup, and set 'When Terminal starts' to restore the previous session (in JSON this is firstWindowPreference: persistedWindowLayout). After that, closing and reopening Windows Terminal brings back your tabs and panes. This does not restore a single tab you closed with Ctrl+Shift+W while the window stays open.

Closing the window terminates the foreground process in that shell unless it was started as a background job or a Windows service. But the commands you ran are in PSReadLine history, and any tool that saves its own state to disk — such as Claude Code, which stores conversation transcripts under your home .claude folder — can be resumed after you reopen a terminal.

Need help shipping something?

Productized MVP development for founders. 9 SaaS apps shipped — yours could be next, in 6 weeks.