From b624bf49b666510ac705a6198a40a526e722525d Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 20 Jan 2026 19:02:31 +0100 Subject: [PATCH] fix: strip leading blank lines from Claude session output Screen attach outputs blank lines that appeared above Claude's banner. Added flag to strip leading newlines from PTY data after buffer clear. Only affects Claude sessions (not shell), matching the reported behavior. Co-Authored-By: Claude Opus 4.5 --- src/session.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/session.ts b/src/session.ts index 2f7ba02a..ec486807 100644 --- a/src/session.ts +++ b/src/session.ts @@ -119,6 +119,7 @@ export class Session extends EventEmitter { private _screenManager: ScreenManager | null = null; private _screenSession: ScreenSession | null = null; private _useScreen: boolean = false; + private _stripLeadingNewlines: boolean = false; // Strip leading newlines after buffer clear // Inner loop tracking (Ralph Wiggum loops and todo lists inside Claude Code) private _innerLoopTracker: InnerLoopTracker; @@ -413,6 +414,7 @@ export class Session extends EventEmitter { if (!isRestoredSession) { setTimeout(() => { this._terminalBuffer = ''; + this._stripLeadingNewlines = true; // Strip leading newlines from Claude's output this.emit('clearTerminal'); }, 100); } @@ -441,9 +443,20 @@ export class Session extends EventEmitter { this.ptyProcess.onData((rawData: string) => { // Filter out focus escape sequences - const data = rawData.replace(FOCUS_ESCAPE_FILTER, ''); + let data = rawData.replace(FOCUS_ESCAPE_FILTER, ''); if (!data) return; // Skip if only focus sequences + // Strip leading newlines after buffer clear (screen attach outputs blank lines) + if (this._stripLeadingNewlines) { + data = data.replace(/^[\r\n]+/, ''); + // Clear flag once we have actual content + if (data.length > 0) { + this._stripLeadingNewlines = false; + } else { + return; // Skip empty data after stripping + } + } + this._terminalBuffer += data; this._lastActivityAt = Date.now();