The prompt for the Command Line Interface (or CLI) for SQLite has been enhanced beginning in version 3.54.0 (pending) to provide more state information using escape-codes in the prompt strings. This document describes those escape-codes as well as other enhancements to prompts in the 3.54.0 release.
The CLI has two different prompt strings, SQLITE_PS1 and SQLITE_PS2. The SQLITE_PS1 prompt string is the ordinary prompt used for most inputs. However, if the CLI detects that an input is incomplete (for example because the semicolon is missing from the end) then it uses the SQLITE_PS2 prompt string for continued input.
The prompt strings can be controlled at run-time, start-time, or at compile-time.
For run-time control, use the ".prompt" dot-command giving it two arguments, which are the PS1 and PS2 strings, respectively. With just a single argument, only the PS1 string is changed. For example:
SQLite-3.54 memory-> .prompt "Main prompt->> " " continue... " Main prompt->>
Use the ".prompt --show" command to see the current prompt strings. The ".prompt --reset" command resets the prompt to the start-time default. The ".prompt --hard-reset" resets the prompt to the compile-time default.
The special option flag of just "--" (two minus-signs followed by no option name) disables subsequent option processing, which enables you to enter PS1 and/or PS2 prompt strings that begin with "--". Ex:
SQLite-3.54 memory-> .prompt -- "--Main prompt->>" "--continue..>>" --Main prompt->>
At startup, the CLI initializes its prompt to the value of the SQLITE_PS1 and SQLITE_PS2 environment variables, if those variables exist. Compile-time default values are used for either of these variables if they do not exist.
The ".prompt --hard-reset" works by unsetting both environment variables for the running process → NB: the running process only - not your default environment.
The SQLITE_PS1 and SQLITE_PS2 C-preprocessor variables can be set to configure the default prompt strings at compile-time. There are, of course, default values used if no alternatives are specified.
The default prompt strings use ANSI X3.64 escapes to provide color and italicized text. Users who do not want that feature can disable it in any of these ways:
Compile with the -DSQLITE_NO_COLOR option.
Set the NO_COLOR environment variable to 1 (or any other non-empty value).
Run the ".prompt --no-color" command.
The prompt string may contain "escape sequences" which expand to other text. The escape character for the CLI is a forward-slash ("/" - U+002f). Yes, you read that right, a forward-slash not a backslash. The forward slash was chosen as the escape character since it is less likely to collide with escape sequences in system shells (ex: bash or CMD.EXE) and thus less likely to lead inordinately complex multi-level escape sequences when setting the SQLITE_PS1 and/or SQLITE_PS2 environment variables or passing values for SQLITE_PS1 and/or SQLITE_PS2 C-preprocessor macros into compilers and Makefiles.
The following are the CLI prompt escape sequences currently recognized:
//
Two forward-slashes in a row resolve to a single forward-slash. This is shorthand for /057.
/NNN
A forward-slash followed by one, two, or three octal digits (NNN) is replaced by a single byte which is the value of those octal digits. Thus, for example, another way to specify a literal forward slash is "/57" or "/057". An ordinary space is "/40" or "/040". And so forth.
/e
The /e escape resolves to the ASCII "ESC" character. This is shorthand for /033. The /e is useful for coding ANSI X3.64 font control escapes.
/m
Text that follows /m, up to the next /; or /: is only displayed if the database is an in-memory database.
/r
Text that follows /r, up to the next /; or /: is only displayed if the database is read-only.
/x
Text that follows /x, up to the next /; or /: is only displayed if a transaction is open.
/:
This is like an "else" - if used at some point after a boolean like /m, /r, or /x it inverts the sense of the test for text that follows up until the next /;.
/;
This is like an "endif" - if used at some point after a boolean like /m, /r, or /x it terminates the condition and causes all subsequent text to always be displayed.
/f, /F, and /~
These escapes expand to the name of the database file. The /f form shows just the tail of the filename and omits all path information. The /F form shows the complete path of the database file going back to root. The /~ form also shows the complete pathname unless the pathname begins with $HOME, in which case that prefix is shortened to just "~". If SQLite is open on an in-memory database, then all of these escapes expand to "memory".
/C
The /C escape only works for continuation prompts. It expands to a minimal sequence of characters needed to close the current command and bring you back to the main prompt. So, for example, if only a semicolon is needed to close the current command, then /C expands to just ";".
/B
The /B escape only works for continuation prompts. It expands to zero or more spaces. The number of spaces in the expansion is the number needed to make the continuation prompt exactly the same length as the main prompt. If the continuation prompt is longer than the main prompt, /B becomes an empty string.
/A
The /A escape expands to the application name: "SQLite". It is provided as an escape sequence because the application name can be modified using a compile-time option.
/v and /V
The /v and /V escapes resolve to version number of SQLite. The /V is the full version number with the patch level (ex: 3.54.0) where as /v is just the major and minor version numbers (ex: 3.54).
/h and /H
The /h and /H escapes resolve to the hostname or computername for the machine running the CLI. The /H form gives the full hostname. The /h form stops at the first "." in the hostname.
/u
The /u escape resolves to the username. This information is taken from environment varibles and can be forged, so should not be relied upon for security.
... othersize ...
Another use of / in the prompt string expands to an error string of similar to like: UNKNOWN("/?"). Thus every forward-slash character in the prompt string needs to be a valid escape sequence. This restriction means that we can add new escape sequences in the future without backwards compatibility concerns.
The default prompt strings (as of this writing, 2026-04-30) are equivalent to:
export SQLITE_PS1='/e[1;32m/A-/v/40/e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m->/40' export SQLITE_PS2='/B/e[1;/x33/:36/;m/C/e[0m->/40'
The default is the application name and "major.minor" version number shown in green, followed by the tail of the database file name, or "memory" in italic, shown in either cyan or yellow, depending on if a transaction is active (yellow) or not (cyan), followed by the prompt string "->" in the default prompt color (usually white) and a space. The continuation prompt shows only the set of characters needed to close the statement, in either cyan or yellow, followed by the default color prompt.
The following chart shows the ANSI X3.64 escape codes used by the default SQLITE_PS1 and SQLITE_PS2 prompt strings, to help you in decyphering those strings. Do a web search for "ansi x3.64" to find a complete listing of all ANSI X3.64 excape codes.
/e[1;32m Font color Green /e[1;33m Font color Yellow /e[1;36m Font color Cyan /e[3m Font style Italic /e[0m Restore the default font
To demonstrate how the default prompt string works, where is some typical interaction:
user@host:~$ sqlite3 t1.db SQLite-3.54 t1.db-> BEGIN; SQLite-3.54 t1.db-> INSERT INTO t1 VALUES(5); SQLite-3.54 t1.db-> COMMIT; SQLite-3.54 t1.db-> .open SQLite-3.54 memory-> SELECT 1+(2*3) AS c1 ;-> ; ╭────╮ │ c1 │ ╞════╡ │ 7 │ ╰────╯ SQLite-3.54 memory-> .quit user@host:~$
Key features of the default prompt include:
Note that the CLI will automatically insert the \001 and \002 "non-printing text" delimiters around ANSI X3.64 escapes when it is linked against a command-line editing library that requires them (editline). So you should omit those non-printing text delimiter bytes from your prompt strings.
The next example causes the main prompt to be just the tilda-abbreviated pathname for the database file. The color is cyan normally, but changes to yellow inside of a transaction. The "SQLite" product name and version is not shown, nor is a "memory" database filename show in italic:
export SQLITE_PS1='/e[1;/x33/:36/;m/~>/e[0m/40' export SQLITE_PS2='/B/e[1;/x33/:36/;m/C>/e[0m/40'
The following session demonstrates:
user@host:~$ sqlite3 t1.db ~/demo/t1.db> BEGIN; ~/demo/t1.db> INSERT INTO t1 VALUES(5); ~/demo/t1.db> COMMIT; ~/demo/t1.db> .open memory>-> SELECT 1+(2*3) AS c1 ;> ; ╭────╮ │ c1 │ ╞════╡ │ 7 │ ╰────╯ memory> .quit user@host:~$
Here is an example that does not use any coloration. Instead, it shows "SQLite" at the beginning of the prompt followed by a space and the tail of the database filename. An extra "*" character is inserted before the ">" if inside of a transaction:
export SQLITE_PS1='SQLite/40/f/x*/;>/40' export SQLITE_PS2='/B/C>/40'
This is how the colorless prompt example looks:
user@host:~$ sqlite3 t1.db SQLite t1.db> BEGIN; SQLite t1.db*> INSERT INTO t1 VALUES(5); SQLite t1.db*> COMMIT; SQLite t1.db> .open SQLite memory> SELECT 1+(2*3) AS c1 ;> ; ╭────╮ │ c1 │ ╞════╡ │ 7 │ ╰────╯ SQLite memory> .quit user@host:~$
Do you prefer the legacy (pre-3.54.0) prompts? This is how you set your environment to achieve that:
export SQLITE_PS1='sqlite>/40' export SQLITE_PS2=' ...>/40'
The examples above use /40 to encode a space. This is for human readablity, since spaces at the end of a string can be difficult to discern, but the CLI does not actually care and you can use literal spaces instead of /40 if you prefer.