Skip to content

Large paste truncated in Claude Code / Copilot sessions — only last lines appear #77

@itai-hania

Description

@itai-hania

Bug Description

When pasting multi-line text (50+ lines) into an active AI session (Claude Code or GitHub Copilot), only the last few lines are pasted. The first lines are silently dropped. Pasting the same content into a new terminal (inside or outside tmax) works fine.

Steps to Reproduce

  1. Open tmax on Windows
  2. Start a Claude Code or GitHub Copilot session
  3. Copy 50 lines of text to the clipboard
  4. Paste into the AI session (Ctrl+V or right-click)
  5. Observe that only the last few lines appear

Expected Behavior

All copied lines should be pasted into the session.

Actual Behavior

The beginning of the pasted text is silently truncated. Only the tail end appears.

What Works

  • Pasting the same content into a new tmax terminal — ✅ works
  • Pasting the same content into a terminal outside tmax — ✅ works
  • Only fails in active AI sessions (Claude Code, Copilot)

Root Cause Analysis

AI sessions (Claude Code, Copilot) enable bracketed paste mode (\x1b[?2004h). When tmax detects this, it wraps the entire pasted text in bracketed paste escape sequences and sends it as a single write:

src/renderer/components/TerminalPanel.tsx (lines 549–559):

if (cursorHideSignalsRef.current.bracketedPaste) {
  text = `\x1b[200~${text}\x1b[201~`;
}
window.terminalAPI.writePty(terminalId, text);

src/main/pty-manager.ts (line ~200):

pty.write(data);  // entire bracketed paste in one shot

The entire payload — escape sequences + 50 lines of text — is sent as a single pty.write() call. Windows ConPTY or the receiving application's input processing truncates the beginning when the payload is too large, keeping only the tail.

New terminals work because they don't have bracketed paste mode enabled, so the shell's default input handling (which is more tolerant of large input) processes the paste.

Suggested Fix

Chunk large writes in PtyManager.write() when the payload exceeds a threshold:

  1. Split writes larger than ~4KB into sequential chunks
  2. Add a small delay between chunks to allow ConPTY / the receiving application to process each one
  3. Keep the bracketed paste wrapper on the first and last chunks respectively (\x1b[200~ on first, \x1b[201~ on last)
  4. Keep single-keystroke writes unchanged for responsiveness

Environment

  • OS: Windows 11
  • tmax version: latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions