prompt - Customize the Command Prompt

Maintained on
Table of Contents

The prompt command changes the text (the prompt) shown at the start of each line in Command Prompt.

By default, the prompt looks like C:\Users\taro>: the current folder followed by >. With prompt, you can show the time or drive name, move the input area to the next line, and otherwise shape it to suit you.

Basic Syntax of the prompt Command

prompt [<text>]

For <text>, combine ordinary characters with special codes that start with $. If you omit the argument, the prompt returns to its default.

prompt $P$G

$P stands for the current folder and $G for >. This is the same form as the default prompt.

Special Codes

CodeWhat it displays
$PCurrent drive and folder (e.g., C:\Users\taro)
$NCurrent drive (e.g., C:)
$G>
$L<
$C(
$F)
$+One + for each level of the pushd stack
$DCurrent date (format depends on regional settings)
$TCurrent time
$VWindows version
$_Line break
$SSpace
$$$
$Q=
$B| (pipe symbol)
$A&
$EEscape character (ASCII code 27; used to set colors)
$HBackspace (erases the preceding character)
About $M

$M displays the remote name (the connection target) when the current drive is a network drive. For other drives, it displays nothing.

Examples

Move the input area to the next line

With a deep folder hierarchy, the prompt gets long and leaves little room to type. Use $_ to move the input area to the next line.

prompt $P$_$G$S
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\Users\taro\Documents\Projects\sample>prompt $P$_$G$S
C:\Users\taro\Documents\Projects\sample>

After running it, the prompt looks like this.

C:\Users\taro\Documents\Projects\sample
> 

Show the time

prompt $T$S$P$G

Because you can see when each command was run, this is handy for checking how long a process took. The $T output includes fractions of a second, such as 12:34:56.78.

Show the date and time

prompt [$D$S$T]$S$P$G

Add color (ANSI escape sequences)

Combining $E with an ANSI escape sequence lets you color the prompt.

prompt $E[32m$P$E[0m$G
  • $E[32m: turns the following text green
  • $E[0m: resets the color
If colors do not appear

Colors work in environments that support ANSI escape sequences, such as Command Prompt on Windows 10 or later and Windows Terminal. In unsupported environments, characters like ←[32m may be displayed as-is.

The Change Applies Only to the Current Window

A prompt changed with prompt returns to normal when you close that Command Prompt window, because the command rewrites an environment variable called PROMPT. You can check the current setting with the following command.

echo %PROMPT%

Save the setting and use it every time

To get the same prompt in every new Command Prompt window, save the PROMPT environment variable with setx.

setx PROMPT "$P$_$G$S"
setx does not affect the window that is already open

A value saved with setx takes effect in Command Prompt windows opened afterward. To apply it to the current window as well, also run prompt $P$_$G$S.

For details on setx, see the related article.

Restore the default

Running prompt with no argument restores the default prompt.

prompt

To remove a setting saved with setx, delete PROMPT in the environment variable settings screen, or overwrite it with the default ($P$G) as follows.

setx PROMPT "$P$G"

Notes When Using It in a Batch File

If you run prompt inside a batch file, the prompt in the calling window stays changed after the batch file ends. To change it only temporarily, wrap it in setlocal and endlocal.

prompt-test.cmd
@echo off
setlocal

prompt [Testing]$S$P$G
cmd /k

endlocal

Changes made in a batch file are discarded at endlocal (or when the batch file ends). Since the prompt is only visible interactively, the example opens a new screen with cmd /k to show it. Running this batch file opens a new cmd whose prompt is [Testing] C:\...>. When you leave it with exit, the original prompt is unchanged.

cmd /k is also handy for changing only the prompt

cmd /k keeps an interactive Command Prompt open from a batch file. You can also pass a command at startup, as in cmd /k prompt $P$G.

Summary

GoalCommand
Move the input area to a new lineprompt $P$_$G$S
Show the timeprompt $T$S$P$G
Display in greenprompt $E[32m$P$E[0m$G
Check the current settingecho %PROMPT%
Save the settingsetx PROMPT "$P$_$G$S"
Restore the defaultprompt

Practice Questions

Practice Problem

Which special code displays the current time in the prompt?

Choose one answer.

  1. $D
  2. $T
  3. $V

Practice Problem

How do you restore a prompt changed with the prompt command to its default?

Choose one answer.

  1. prompt reset
  2. Run prompt with no argument
  3. Run cls
#Command Prompt #Batch Files #Command Line #Commands #prompt #Customization