Command Prompt in Windows does not save command history permanently by default, so once you close the window, the history is lost unless you explicitly enable it or use a workaround. To retrieve or preserve history after closing, you must either have previously enabled history logging or use backup methods like PowerShell or third-party tools—this guide covers the most reliable, built-in approach.

What You'll Need

  • A Windows PC (Windows 7 or later; steps verified on Windows 10 and 11)
  • Administrative rights to modify registry settings (if enabling history persistence)
  • Basic familiarity with Command Prompt and Registry Editor

Step-by-Step

  1. Check if history was previously saved to a file—if you ran doskey /listsize=1000 in a previous session and redirected output, or used external logging, locate any text files you may have created (e.g., history.txt). Open Command Prompt, type type C:\path\to\history.txt (replace with your file path), and press Enter. This only works if you manually saved output earlier.
  2. Enable persistent command history (for future sessions) by modifying the registry:
    1. Press Win + R, type regedit, and press Enter to open Registry Editor.
    2. Navigate to: HKEY_CURRENT_USER\Software\Microsoft\Command Processor
    3. In the right pane, right-click a blank area > New > DWORD (32-bit) Value.
    4. Name it SaveHistory.
    5. Double-click SaveHistory, set Base to Decimal, enter 1 as the value data, then click OK.
    6. Still in the same folder, right-click again > New > String Value.
    7. Name it HistoryBufferSize.
    8. Double-click HistoryBufferSize, set Base to Decimal, enter 500 (or any number up to 999), then click OK.
    9. Close Registry Editor.
  3. Restart Command Prompt and run at least one new command (e.g., dir). Close and reopen Command Prompt to confirm the setting applies.
  4. View the saved history file:
    1. Open Command Prompt.
    2. Type doskey /history > %TEMP%\cmd_history.txt and press Enter.
    3. Open File Explorer and navigate to %TEMP% (paste this into the address bar and press Enter).
    4. Locate cmd_history.txt and open it in Notepad to review your recent commands.
  5. Use PowerShell for more robust history access (recommended for modern Windows):
    1. Open PowerShell as Administrator.
    2. Run Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'Start_SearchFiles' -Value 1 (optional, for compatibility).
    3. Run Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\PowerShell\Console\1' -Name 'HistorySavePath' -Value "$env:USERPROFILE\Documents\PowerShell_History.xml" to set a custom history file path.
    4. Run Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\PowerShell\Console\1' -Name 'HistoryCount' -Value 500 to increase stored history.
    5. Close PowerShell, then reopen it and run commands.
    6. To view history: Get-Content $env:USERPROFILE\Documents\PowerShell_History.xml or use Get-History in a new session.

Common Mistakes

  • Assuming history persists automatically—without enabling SaveHistory or using PowerShell, Command Prompt discards history on close by design.
  • Typos in registry key names (e.g., SvaeHistory instead of SaveHistory), which cause the setting to fail silently.
  • Editing the wrong registry hive—ensure you are in HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE.
  • Expecting old commands (from before enabling history) to appear—only new sessions after enabling will be saved.
  • Confusing Command Prompt history with PowerShell history—they are separate systems with different storage mechanisms.

Tips

  • Use PowerShell instead of Command Prompt for better built-in history management—it saves history to XML by default and supports Get-History and Export-Clixml for backups.
  • Set up a shortcut to open Command Prompt with a custom history size: right-click the shortcut > Properties > Options > set History Buffer Size to 500 or higher.
  • Automate history export: create a batch file save_history.bat containing doskey /history > %USERPROFILE%\Documents\cmd_history_$(date /t).txt and run it at the end of each session.
  • For advanced users, consider enabling F7 key support by adding a KeyHistory DWORD (value 1) under Command Processor to show history via the F7 key in future sessions.
  • Always back up the registry before editing (File > Export in Registry Editor).

Troubleshooting

  • No history appears after enabling SaveHistory—ensure you closed and reopened Command Prompt at least once. The registry change only applies to new sessions, not the current one.
  • Registry settings reset after reboot—check if Group Policy is enforced (run gpedit.msc > Computer Configuration > Administrative Templates > System > Don’t run specified Windows applications; verify Command Prompt isn’t restricted). Also, verify no third-party security software is modifying registry keys.
  • History file is empty or missing—confirm you ran at least one command after enabling history. If using doskey /history, ensure the > redirection is not blocked (e.g., by antivirus temporarily locking the TEMP folder).
  • Command Prompt crashes or behaves oddly after registry edits—restart your PC. If issues persist, delete the SaveHistory and HistoryBufferSize registry values and restart.
  • PowerShell history not saving—run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser first, then retry the Set-ItemProperty commands. Also, ensure the target folder (e.g., Documents) exists and is writable.
  • History appears garbled or corrupted—this may occur if multiple Command Prompt windows were open simultaneously. Use PowerShell instead, as it handles concurrent sessions better and stores history in structured XML format.

Frequently Asked Questions

Does Windows Command Prompt save history by default?

No—by default, Command Prompt only stores the current session’s history in memory, which is erased when the window closes.

Can I recover history from a closed Command Prompt window?

Only if you previously enabled history persistence via registry or used PowerShell. Otherwise, the history is unrecoverable.

Is there a way to see history from before enabling SaveHistory?

No—history before enabling the registry setting is permanently lost. The setting only affects new sessions.

Does enabling SaveHistory affect performance?

No—it has a negligible impact, as it only writes to disk when the session ends or when you manually export.

Can I use PowerShell to view old Command Prompt history?

Not directly—Command Prompt and PowerShell maintain separate histories. However, you can export Command Prompt history to a file and import it into PowerShell for analysis.

Is editing the registry safe?

Yes—if you follow the steps exactly and avoid changing or deleting other keys. Always back up the registry before making changes.