You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to programmatically save multiline REPL history with \r (like native Node CLI)? #64508
Linux archlinux 7.0.8-arch1-1 nodejs/help#1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux
Subsystem
repl
Description
Description
When using the native Node.js binary REPL via terminal (node), multiline inputs (like objects, functions, or arrays) are correctly saved into .node_repl_history as a single physical line, where internal line breaks are represented by \r.
However, when creating a REPL instance programmatically using repl.start() and initializing history via repl.setupHistory(), every press of the Enter key triggers a write to the history file immediately. This breaks multiline inputs into separate, independent physical lines separated by \n. This completely breaks history navigation inside the programmatic REPL (pressing the Arrow Up key scrolls lines one by one instead of expanding the whole block).
I tried to reproduce this on both v26.5.0 (official binary) and the current main, and multiline entries are correctly persisted as a single physical line with \r separators (e.g. 2]\r[1,) when using repl.start() + setupHistory() — typed, pasted, and with history navigation.
Multiline history support landed in 4a4aa58 and shipped in v25.0.0, and the behaviour you describe matches what older versions (≤ v24) produce. Could you double-check the actual binary being run (node --version from the same environment)?
While investigating, I did find a related edge case: if lines are evaluated while setupHistory() is still loading the history file asynchronously, the in-memory entries are discarded when the file load completes, leaving the history file empty. I'll send a PR for that shortly.
@mhayk, thanks for the response. I was indeed mistaken, and I apologize for wasting your time.
I confirm that in versions v24.14.1 and v26, the history works correctly with \r.
I probably switched to version 22 and noticed the issue there. And when I was checking on 26, I opened the history file in VS Code, which doesn't display \r. After opening it in nvim, I saw that everything is fine.
I will close this issue since it is no longer relevant.
Activity
psqq commentedon Jul 14, 2026
https://gemini.google.com/share/2049b04d18e2?skid=6dff2ae9-0a8e-4d4f-a868-b6a6072114cd
avivkeller commentedon Jul 14, 2026
Maybe we can allow users to specify a
historyoption with their own file path?mhayk commentedon Jul 15, 2026
I tried to reproduce this on both v26.5.0 (official binary) and the current
main, and multiline entries are correctly persisted as a single physical line with\rseparators (e.g.2]\r[1,) when usingrepl.start()+setupHistory()— typed, pasted, and with history navigation.Multiline history support landed in 4a4aa58 and shipped in v25.0.0, and the behaviour you describe matches what older versions (≤ v24) produce. Could you double-check the actual binary being run (
node --versionfrom the same environment)?While investigating, I did find a related edge case: if lines are evaluated while
setupHistory()is still loading the history file asynchronously, the in-memory entries are discarded when the file load completes, leaving the history file empty. I'll send a PR for that shortly.repl: keep entries added while history file is loading
psqq commentedon Jul 15, 2026
@mhayk, thanks for the response. I was indeed mistaken, and I apologize for wasting your time.
I confirm that in versions v24.14.1 and v26, the history works correctly with \r.
I probably switched to version 22 and noticed the issue there. And when I was checking on 26, I opened the history file in VS Code, which doesn't display \r. After opening it in nvim, I saw that everything is fine.
I will close this issue since it is no longer relevant.
repl: keep entries added while history file is loading
repl: keep entries added while history file is loading
repl: keep entries added while history file is loading
repl: keep entries added while history file is loading
repl: keep entries added while history file is loading
repl: keep entries added while history file is loading