TUI input lag in long-running sessions with high context usage

Resolved 💬 3 comments Opened Apr 25, 2026 by syan-tibco Closed Apr 28, 2026

Description

After running a Claude Code session for an extended period (~58 hours, 809 tool calls, 82% context window, $60+ cost), typing at the prompt becomes noticeably laggy — each keystroke takes 200-500ms to appear on screen.

Environment

  • Claude Code version: 2.1.119
  • Model: Opus 4.6
  • OS: macOS 26.4.1 (Apple Silicon)
  • Terminal: Custom terminal emulator (SwiftTerm-based), but issue is in Claude Code's TUI rendering, not the terminal

Reproduction

  1. Run a Claude Code session with many tool calls (800+) and high context usage (80%+)
  2. Let it run for a long time (hours/days) with active use
  3. Try typing at the prompt — noticeable delay between keypress and character appearing

Debugging performed

  • Profiled both the terminal emulator and the Claude Code process (PID) using macOS sample
  • Terminal emulator main thread: >99% idle, no draw bottleneck
  • Claude Code main thread: ~99.5% idle in kevent64, 0.3-0.4% CPU — no CPU bottleneck visible in sampling
  • System memory: 57% free (64GB machine), no swap
  • Other Claude Code sessions in the same terminal app (lower context %, shorter runtime) respond instantly
  • Key test: Exiting Claude Code (/exit) and starting a fresh session (claude) in the same terminal immediately resolves the lag. This confirms the issue is in Claude Code's internal state, not the terminal emulator.

Hypothesis

The TUI layer (likely ink/React-based renderer) re-renders the full component tree on each keystroke. For sessions with large internal state (high context, many tool calls, long conversation history), this re-render becomes expensive enough to cause perceptible input lag.

Session stats at time of issue

  • Context: 82% (178K input tokens, 439K output tokens)
  • Tool calls: 809
  • Runtime: ~58 hours (3511 minutes)
  • Cost: $60.97
  • Conversation had been compacted (/compact)

🤖 Generated with Claude Code

View original on GitHub ↗

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