Skip to content

"Run in terminal" on a code block truncates commands over 1024 bytes when it opens a new terminal #46881

Done

Description

@Edinburgher

What happened

When a chat code block's "Run in terminal" button opens a new terminal, any command longer than 1024 bytes gets cut off and doesn't run. Running the same block again right away doesn't help: it is appended to the truncated line, whose quote is still open, so zsh waits at a quote> prompt. Only after Ctrl+C clears the truncated line does running the block again in the now-running terminal work.

Expected: the full command is pasted and runs.

Actual: the zsh input line holds exactly the first 1024 bytes (the text ends at "0204-0"). The rest of the command and the final newline are missing, so nothing runs. Before the prompt appeared, only the first 710 bytes had been echoed to the screen.

Diagnosis

In v0.1.13 the "Run in terminal" button calls runShellCommand (apps/web/src/components/chat/useChatTerminalActions.ts:327), which goes through runProjectScript with shellHistory: "preserve". When the thread has no running terminal, runProjectScript launches one, waits only for the open to resolve, and then immediately calls writeToTerminal with ${command}\r in a single write (line 285).

At that point zsh has not started its line editor yet, so the pty is still in canonical mode. macOS keeps at most MAX_CANON = 1024 bytes of pending canonical input and drops the rest. When ZLE starts, it reads exactly those 1024 bytes; the remainder and the trailing \r are gone, so the command sits unexecuted at the prompt. In an already-running terminal ZLE is in raw mode, so the same write arrives intact.

Neither useChatTerminalActions.ts nor packages/client-runtime/src/state/terminal.ts has changed on main since v0.1.13, so this is not fixed in a release or nightly yet.

Possible fixes: wait until the shell is ready (for example the first prompt, bracketed paste turning on, or a shell-integration marker) before writing, or use bracketed paste once the shell is up, or split the write into chunks after the line editor is active. #36352 (afterShellStartup, holding writes until bracketed paste is on) would likely cover this path, but it has not been tested with input over 1024 bytes.

Steps to reproduce

  1. macOS, zsh as login shell, T3 Code desktop app.
  2. In a thread with no terminal open, get a chat reply containing a single-line bash block longer than 1024 bytes, for example x='0001-0002-...-0221'; echo "${#x}" (about 1150 bytes).
  3. Press the code block's "Run in terminal" button.
  4. The terminal opens; the prompt shows only the first 1024 bytes of the command and nothing runs.
  5. Press "Run in terminal" on the same block again: the text is appended to the truncated line, the quotes mismatch and zsh shows a quote> prompt.
  6. Press Ctrl+C in the terminal, then press "Run in terminal" again: the full command runs.

Version

0.1.13 stable desktop app (also seen on earlier stable builds)

Environment

macOS 26 (Darwin 25.4.0) arm64, zsh, desktop app against its local server

Evidence

Terminal log of the new terminal (prompt redacted). After the pre-ZLE echo, ZLE redraws the input line, which ends at byte 1024:

x='0001-0002-...-0202-0203-0204-0\r ... <prompt> % \e[?2004h x='0001-0002-...-0203-0204-0

Running the block again without Ctrl+C ends in zsh's quote> continuation prompt:

...-0221'; echo "T1100 got=${#x} want=1104 last=${x: -4}"\e[?2004l ... quote> 

After Ctrl+C, the same block run in the running terminal arrives complete and executes:

x='0001-...-0220-0221'; echo "T1100 got=${#x} want=1104 last=${x: -4}"\e[?2004l

Related issues

#6337 / #36352: same write-before-shell-ready race for project actions; #6337 is a command stuck above the prompt regardless of length, this is a 1024-byte cut from the code block "Run in terminal" button

Fix applied or workaround

Open the thread terminal first, then use "Run in terminal". If the command was already truncated, press Ctrl+C in the terminal before running it again.

Filed by

Claude Code (Claude Opus 5.5) via t3 triage

Activity

  1. added
    via-triage
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions