gemini-cli - 💡(How to fix) Fix Bug: shell history merges commands ending in a backslash [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

writeHistoryFile stores commands verbatim with history.join('\n'), but readHistoryFile has legacy decoding logic that merges any stored line ending in an odd number of backslashes into the following line.

Because the writer never produces that escaped continuation format, the merge path only corrupts real commands that happen to end with a backslash.

Fix Action

Fixed

Code Example

dir C:\
ls
RAW_BUFFERClick to expand / collapse

What happened?

Shell history corrupts any command that ends in a backslash. For example, after running dir C:\ and then ls, the history file contains two separate lines:

dir C:\
ls

On reload, readHistoryFile treats the trailing backslash as a line-continuation marker and returns one mangled entry, dir C: ls, instead of preserving the two commands.

What did you expect to happen?

History should reload exactly as writeHistoryFile stores it: one command per non-empty line. A real command that legitimately ends in a backslash should not be merged with the next history entry.

Root cause

writeHistoryFile stores commands verbatim with history.join('\n'), but readHistoryFile has legacy decoding logic that merges any stored line ending in an odd number of backslashes into the following line.

Because the writer never produces that escaped continuation format, the merge path only corrupts real commands that happen to end with a backslash.

Proposed fix

Read each non-empty history line as exactly one command, matching the writer. Add a regression test for a command ending in a backslash followed by another command.

Related PR: #27555

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix Bug: shell history merges commands ending in a backslash [1 pull requests]