claude-code - 💡(How to fix) Fix TUI input lag in long-running sessions with high context usage [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#53166Fetched 2026-04-26 05:22:42
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

The most likely fix for the input lag issue in Claude Code is to optimize the TUI layer's re-rendering process or implement a more efficient rendering strategy for large internal states.

Guidance

  • Investigate the TUI layer's rendering process to identify potential bottlenecks and optimize it for large internal states.
  • Consider implementing a lazy rendering or incremental rendering strategy to reduce the computational overhead of re-rendering the full component tree on each keystroke.
  • Review the conversation history and context size to determine if there are opportunities to reduce the internal state size, such as by implementing a more aggressive compaction strategy or limiting the conversation history length.
  • Test the hypothesis by creating a minimal reproducible example with a smaller internal state and measuring the input lag to determine if the issue is indeed related to the internal state size.

Example

No code snippet is provided as the issue is related to the internal implementation of Claude Code's TUI layer.

Notes

The issue may be specific to the Opus 4.6 model or the Claude Code version 2.1.119, and upgrading to a newer version may resolve the issue. However, without further information, it is difficult to determine the root cause.

Recommendation

Apply a workaround by regularly compacting the conversation history or limiting the context size to reduce the internal state size and alleviate the input lag, until a more permanent fix can be implemented.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING