Skip to content

fix: handle heredoc/multiline commands in terminal tool execution#307960

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-288896-heredoc-file-write
Open

fix: handle heredoc/multiline commands in terminal tool execution#307960
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-288896-heredoc-file-write

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

@maruthang maruthang commented Apr 6, 2026

Summary

Fixes #288896

When the Copilot agent sends heredoc or multiline commands to the terminal, normalizeCommandForExecution() collapses all newlines to spaces, destroying the heredoc structure. The shell then receives a single line instead of the multi-line heredoc, causing file write failures.

Changes

  1. sendToTerminalTool.ts: Detect multiline commands (containing \n or \r) and send them with bracketed paste mode enabled, bypassing normalizeCommandForExecution. This preserves newlines so the shell treats the input as a single paste.

  2. Execute strategies (basicExecuteStrategy.ts, noneExecuteStrategy.ts, richExecuteStrategy.ts): Force bracketed paste mode for multiline commands on all platforms (previously only forced on macOS).

How to test

  1. Open Copilot Chat and ask it to create a file using a heredoc, e.g.: "Write a hello world script to /tmp/test.sh using heredoc"
  2. Verify the file is created correctly with proper content
  3. Verify single-line commands still work normally

…crosoft#288896)

Update sendToTerminalTool and execute strategies to properly handle
heredoc statements and multiline commands that were failing during
file write operations.
@maruthang maruthang force-pushed the fix/issue-288896-heredoc-file-write branch from b1e84db to cdbf3cb Compare April 17, 2026 02:44
@meganrogge meganrogge added this to the 1.118.0 milestone Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heredoc statements often do not work / file write issues

3 participants