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 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-20 19:02:31 +01:00
co-authored by Claude Opus 4.5
parent 612274743f
commit b624bf49b6
+14 -1
View File
@@ -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();