Terminal viewport snaps to top of scrollback during output in long sessions

Resolved 💬 4 comments Opened Mar 22, 2026 by smshd Closed Apr 19, 2026

Description

In long Claude Code sessions (~150k+ tokens, 60+ tool calls), the terminal viewport snaps to the very top of the scrollback buffer when Claude begins outputting a response. This happens even when the user is already scrolled to the bottom. The snap occurs at the moment the first text begins streaming (Ink's first render cycle), not during prompt submission or the thinking phase.

Reproduction

  • Consistently reproduces in sessions with ~25-30 AI messages, ~60-80 tool calls, ~150-250k tokens
  • Sessions that started with a compaction summary from a prior conversation reproduce more reliably
  • Tested and confirmed in both Windows Terminal and a custom xterm.js-based terminal (Tauri app) — this is not terminal-specific

What we ruled out

We ran extensive isolation tests:

  • Ink-style cursor-up + erase rendering (simulated with a Python script mimicking Ink's exact CSI pattern) — no jitter in fresh terminals
  • Burst output (100 lines, 2s pause, repeat) — scroll anchoring works fine
  • Raw rapid output (5000 lines at max speed) — no jitter
  • Large scrollback buffer alone (filled 5000 lines of content, then started a fresh claude session in the same terminal) — no jitter
  • Short Claude Code sessions — never jitter regardless of output type or volume

Root cause hypothesis

Ink's eraseLines(N) overshoots in long sessions. The component height N appears to be calculated based on accumulated/compressed content history rather than just the current visible response. In a long session, N becomes hundreds or thousands of lines, so the CSI <N> A (cursor up) sequence moves the cursor past the visible viewport to the top of the scrollback buffer, and the terminal viewport follows.

Supporting evidence:

  • The snap occurs precisely when the first text streams (Ink's initial render cycle for a new response)
  • A short "2+2" response triggers the same snap in a long session
  • The affected session self-reported: ~150-250k tokens, compressed earlier messages, multiple large tool results, background agent notifications — all factors that could inflate Ink's internal component height tracking

Environment

  • Windows 11 (build 26200)
  • Claude Code (latest)
  • Tested in: Windows Terminal + custom xterm.js 5.5 terminal (Tauri/WebView2)
  • ConPTY backend

Related issues

This appears to be the same root cause as:

  • #34845
  • #34794
  • #36582
  • #10769
  • #826
  • #9083

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗