Skip to content

Shell Tool Trailing Newline Trimming #20755

Description

@gitenstuff

What happened?

Description

The run_shell_command tool erroneously trims trailing newlines from command
strings before execution. This results in syntax errors for shell constructs
that require a trailing newline as a delimiter, most notably Bash heredocs.

Bash expects heredoc delimiters to be followed by a newline to signal the end of the input block.
Without it, the shell encounters an unexpected EOF while still looking for the delimiter.

Examples

Heredoc Syntax Error (Triggered by Newline Trimming)

Command Sent:

$  cat <<EOF
test
EOF
 bash: warning: here-document delimited by end-of-file (wanted `EOF')
 bash: syntax error: unexpected end of file

Heredoc Workaround (The ":" Fix)

Adding a command on a subsequent line preserves the newline after the heredoc
delimiter.

$  cat <<EOF
test
EOF
:
test

Non-Heredoc Syntax Error (Single Comment)

A command string containing only a comment fails when the newline is trimmed
because the shell identifies the input as empty or truncated in certain
execution contexts.

$  # comment
bash: syntax error: unexpected end of file

[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.

What did you expect to happen?

run_shell_tool should not trim trailing newlines

Client information

  • CLI Version: 0.31.0
  • Git Commit: 72c6533
  • Session ID: b119e6e0-a35b-488a-8978-38d2df50c7ec
  • Operating System: linux v25.6.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: oauth-personal
  • Memory Usage: 533.8 MB
  • Terminal Name: Unknown
  • Terminal Background: #002b36
  • Kitty Keyboard Protocol: Unsupported

Login information

Oauth

Anything else we need to know?

No response

Metadata

Metadata

Assignees

Labels

area/coreIssues related to User Interface, OS Support, Core Functionalityhelp wantedWe will accept PRs from all issues marked as "help wanted". Thanks for your support!priority/p2Important but can be addressed in a future release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions