CSI ? 2004 h enables bracketed paste: when the user pastes, the terminal wraps the pasted text in ESC [ 2 0 0 ~ ... ESC [ 2 0 1 ~ so the application can tell pasted text from typed keystrokes and avoid executing it. CSI ? 2004 l disables it.
CSI ? 2004 h turns on bracketed paste. While enabled, when the user pastes, the terminal sends ESC [ 200~ before and ESC [ 201~ after the pasted bytes.
reset
Disable (DECRST)
\x1b[?2004l
CSI ? 2004 l turns off bracketed paste; pasted text is then delivered as raw keystrokes with no wrappers.
paste-begin
Paste-begin marker (terminal -> app)
\x1b[200~
When bracketed paste is enabled, the terminal sends this BEFORE pasted content. The application reads it and treats subsequent bytes as literal data, not commands.
paste-end
Paste-end marker (terminal -> app)
\x1b[201~
The terminal sends this AFTER pasted content, signalling the end of the literal paste region.
gotchas
?2004h enables the MODE; the actual wrappers (ESC [ 200~ / ESC [ 201~) are sent by the TERMINAL to the application around real pastes — your program enables the mode, then reads and strips the wrappers.
Security purpose: bracketed paste prevents a pasted blob that contains a newline from auto-executing in the shell, and prevents pasted ANSI/control bytes from being interpreted as commands. Do NOT interpret bytes between 200~ and 201~ as control sequences.
Terminals do not strip control characters inside the paste; the application must decide how to handle embedded ESC/newlines within the bracketed region.
Re-enable the mode after running a child program that may have reset it (e.g. a TUI that did its own raw-mode setup), or paste detection silently stops working.
Reset the mode (?2004l) when your program exits, so the next program/shell isn't left with an unexpected paste mode state.
#summary — https://invisible-island.net/xterm/ctlseqs/ctlseqs.htmlxterm ctlseqs: Ps = 2 0 0 4 -> Set bracketed paste mode. When enabled, pasted text is bracketed with control sequences ESC [ 2 0 0 ~ (start) and ESC [ 2 0 1 ~ (end) so the application can distinguish it from typed input.