If a copy & pasted prompt contains an exclamation mark anywhere (!) it will trigger shell mode ?!
What happened?
For example:
Hello World ! How are you doing ?
This will enter the first part as a prompt perhaps:
"Hello World !"
And then it enters shell mode and shows:
"How are you doing ?"
To me it seems like this is cutting of the prompt ?
Maybe not if I press enter ?!
But it's weird ?!
Maybe shell mode should only be activated if the first character is a exclamation mark ?: !
What did you expect to happen?
The entire prompt should be fed into the AI model and ! anywhere else in the message should not trigger shell mode ?!
Client information
$ gemini /about
skipping it.
Login information
No response
Anything else we need to know?
No response
@DelphinityLabs Hi there! Thank you so much for this report. I can't actually reproduce this issue - we might need more information, such as your environment (MacOS, windows, linux) and your keyboard settings (EN-US)?
Gemini CLI: Multi-Line Paste Unexpectedly Triggers Shell Mode
Hello everyone,
After some targeted testing, I wanted to share a subtle but important issue I've come across when using the Gemini CLI. It's not about parsing errors, but rather about how the CLI handles pasted multi-line input specifically when lines begin with an exclamation mark.
Problem Description
When a user pastes text that contains newline characters just before a !, the CLI splits it into separate lines. If any of those lines begins with !, the shell mode is activated even if that wasn’t the user's intention.
This behavior is technically correct (as ! invokes shell commands), but unexpected in the context of pasted input.
Root Cause
Gemini CLI interprets each pasted line independently. So if you paste something like:
Hello World\r\n! This is a test
It is handled as two separate lines:
Hello World
! This is a test
The first is submitted as a prompt. The second, starting with !, is immediately executed as a shell command.
Reproduction Steps (Windows)
To reproduce this reliably on Windows:
- Run:
python -c "import sys; sys.stdout.write('Hello World\r\n! This is a test')" | clip - Paste into the Gemini CLI.
- You'll see:
Hello Worldis submitted as a prompt.- The CLI executes
! This is a testas a shell command.
Why It Matters
This issue can cause confusion or even unintended behavior. Newlines copied from web sources, editors, or Markdown often include hidden characters that trigger this behavior silently. That makes the bug feel random when it's not.
Suggested Fixes
To improve user experience, one or more of the following could help:
- Sanitize pasted input: Replace
\n,\r, or\r\nwith a space before parsing. - Prompt the user: Ask for confirmation when multi-line input is detected.
- Disable shell execution on paste (via config or flag).
Conclusion
This isn't a parsing bug, but rather a usability edge case. Still, it’s a friction point that can be smoothed out. If helpful, I’m happy to assist with testing a patch or drafting a PR.
Thanks for reading!
This issue has been automatically marked as stale due to 60 days of inactivity. It will be closed in 14 days if no further activity occurs.
@secprobe I think this issue is likely unrelated to newline characters. I am experiencing the same problem on Windows 11, using the Git Bash profile within Windows Terminal.
Through debugging, I've determined that when pasting text, for some reason the \x1b[200~ sequence (which indicates the start of a bracketed paste) is not being recognized. Consequently, key.paste is not set to true. This causes the input handling flow to proceed to the code that toggles shell mode.
As a result, any string before the ! is lost, and only the string after the ! remains in the prompt after shell mode is unintentionally activated.
Since this issue does not occur when using the WSL profile within Windows Terminal, it seems this is not an issue with Windows Terminal itself, but rather with how the Git Bash profile handles paste events.
I attempted to fix this myself but was unable to resolve it, so I am reporting my findings here.
This seems to be a windows specific bug.
Hello! As part of our effort to keep our backlog manageable and focus on the most active issues, we are tidying up older reports.
It looks like this issue hasn't been active for a while, so we are closing it for now. However, if you are still experiencing this bug on the latest stable build, please feel free to comment on this issue or create a new one with updated details.
Thank you for your contribution!
I have confirmed the behavior also occurs in linux in https://github.com/google-gemini/gemini-cli/issues/16348