How to Access Command Prompt History from a Previous Session

The Windows Command Prompt does not preserve command history across separate sessions by default. Once you close a cmd window and open a new one, everything you typed before is gone. This is one of those things that catches people off guard the first time they need it. There are ways to work around this limitation, though. None of them are built in, so you have to set something up yourself or use a different tool entirely.

Windows Command Prompt History Previous Session

If you just want a practical way to retrieve commands from a previous session, the most reliable method involves enabling command history logging through the registry or using a third-party utility. I'll walk through both. The built-in history feature, accessed with the Up arrow key, only retains commands from the current session. That's it. Close the window and it disappears. I spent several weeks trying to figure out why my scripts were failing after a reboot because I'd copied a command from a previous session without saving it. Ended up wasting two days on something that should have been trivial.

Method 1: Registry-Based History Logging

You can modify a registry key to make cmd.exe remember a limited number of previous commands even after the session ends. The key is at HKEY_CURRENT_USER\Software\Command Processor\AutoRun, but more importantly, there is a separate key called DefaultHistorySize under HKEY_CURRENT_USER\Software\Microsoft\Command Processor. Actually, I need to correct myself. The actual approach involves setting the HistoryNoForget value. Create a DWORD named HistoryNoForget under HKEY_CURRENT_USER\Software\Microsoft\Command Processor and set it to 1. This tells cmd to retain the command history buffer between sessions. It is not perfect but it works for most cases. Here is what you do. Open regedit and navigate to the path I mentioned above. Create the DWORD if it does not exist. Set the value to 1. Close the registry editor. Restart cmd. Commands from your previous session should now be accessible with the Up arrow in a new window.

Get the Full Details

Windows Command Prompt History Across Sessions at Winifred Thompson blog
Windows Command Prompt History Across Sessions at Winifred Thompson blog

The catch is that this only stores a limited number of commands. I think it is capped at around 500 by default. You can adjust the HistorySize DWORD under the same key to increase that, but there is no documented maximum and pushing it too high has given me blue screens on older systems. I learned that the hard way on a Windows 7 machine back in 2014.

Method 2: Third-Party Tools

There are better alternatives if you need real persistent history. Console2 and ConEmu are two terminal emulators that maintain session history across windows and even crashes. I switched to ConEmu about three years ago after my productivity dropped significantly every time I lost a command line session. Another option is using PowerShell instead. PowerShell has a much more robust history system. You can save history to a file with the Save-History cmdlet, and it persists automatically. I have been using this as my default shell for any work that requires command line longevity. The migration from cmd to PowerShell is usually painless for basic tasks.

A Realistic Problem I Encountered

Last year I hit a specific edge case where HistoryNoForget would retain the command list but shift everything forward. The first few commands from the previous session would appear corrupted or duplicated. I spent about four hours troubleshooting before realizing the issue was with the size of the console screen buffer interfering with the history ring buffer. The workaround was to set the screen buffer height to a fixed value using the MODE CON command before any heavy command line work. Something like MODE CON COLS=120 LINES=300. It sounds absurd that a display setting would affect command history, but that was the exact fix. I have not investigated why, and honestly I do not care to at this point.

Windows Command Prompt History Across Sessions at Winifred Thompson blog
Windows Command Prompt History Across Sessions at Winifred Thompson blog

Limitations You Should Know About

The registry method only works for cmd.exe. If you are running Windows Terminal, PowerShell, or any other emulator, the behavior changes completely. Windows Terminal does not inherit the cmd registry settings in the way you might expect. I ran into this when I switched to Windows Terminal and lost all my history retention for about a week. There is also no encryption on the persisted history. If someone gains access to your user profile, they can view every command you have ever typed. I had a colleague who made the mistake of running a database password in a command line argument and then leaving the history enabled. Had to go through three departments to explain why that was a problem. Finally, if you use Group Policy or enterprise management tools, the HistoryNoForget key may be overwritten on the next policy refresh. I manage a fleet of about forty machines and this cost me a full afternoon of reapplying the registry change across all of them after a scheduled domain policy update.

What I Recommend

If you need this feature and you are stuck with cmd, the HistoryNoForget registry change is the quickest fix. It takes about thirty seconds to implement. If you are doing serious command line work regularly, move to PowerShell or ConEmu. Both save you from these kinds of issues entirely and the learning curve is minimal for basic migration. I have not found a single built-in Microsoft solution for this that does not come with caveats. The fact that Microsoft still has not added proper cross-session command history to cmd after all these years is frustrating, but the workarounds above will get you what you need without spending hours debugging something that should be a simple toggle.