*** DRAFT ***
The CLI Prompt
Table Of Contents

1. Introduction

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.

2. Controlling The Prompt String

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.

2.1. Run-time control of the prompt strings

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->>

2.2. Start-time control of the prompt strings

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.

2.3. Compile-time control of the prompt strings

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.

2.4. Colorized Prompts

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:

3. CLI Prompt String Escapes Codes

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:

4. Examples

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.