claude-code - 💡(How to fix) Fix Cursor buried in TUI remnants on exit (no alternate screen buffer) [1 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#47190Fetched 2026-04-13 05:39:04
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

When Claude Code exits, the TUI content is left on screen and the cursor ends up buried within it rather than appearing cleanly at a new prompt. This makes it difficult to find where to type next.

The root cause appears to be that Claude Code doesn't use the terminal alternate screen buffer (smcup/rmcup escape sequences). TUI applications that use the alternate screen restore the original terminal state on exit — cursor position and all. Without it, the TUI output stays on screen and the cursor is left wherever the TUI last rendered it, often mid-block within the output.

Root Cause

The root cause appears to be that Claude Code doesn't use the terminal alternate screen buffer (smcup/rmcup escape sequences). TUI applications that use the alternate screen restore the original terminal state on exit — cursor position and all. Without it, the TUI output stays on screen and the cursor is left wherever the TUI last rendered it, often mid-block within the output.

RAW_BUFFERClick to expand / collapse

Description

When Claude Code exits, the TUI content is left on screen and the cursor ends up buried within it rather than appearing cleanly at a new prompt. This makes it difficult to find where to type next.

The root cause appears to be that Claude Code doesn't use the terminal alternate screen buffer (smcup/rmcup escape sequences). TUI applications that use the alternate screen restore the original terminal state on exit — cursor position and all. Without it, the TUI output stays on screen and the cursor is left wherever the TUI last rendered it, often mid-block within the output.

Steps to Reproduce

  1. Open Claude Code in a terminal (claude)
  2. Have a conversation (any length)
  3. Exit with /exit or Ctrl+C
  4. Observe that the TUI content remains on screen and the cursor is buried within it

Expected Behaviour

Either:

  • Claude Code uses the alternate screen buffer so the terminal is fully restored on exit (preferred — consistent with other TUI apps like vim, htop, lazygit), or
  • The cursor is at minimum moved to a clean position below the output on exit

Actual Behaviour

TUI content remains on screen. Cursor is left buried within the rendered TUI text, making it hard to find the prompt.

Environment

  • OS: Linux (Ubuntu)
  • Terminal: GNOME Terminal
  • Claude Code: CLI

extent analysis

TL;DR

Implementing the terminal alternate screen buffer using smcup and rmcup escape sequences in Claude Code is likely to fix the issue of TUI content remaining on screen after exit.

Guidance

  • Investigate using a library or module that provides an easy way to handle the alternate screen buffer, such as curses or blessings, to simplify the implementation.
  • Test the use of smcup and rmcup escape sequences directly in Claude Code to ensure they correctly restore the terminal state on exit.
  • Consider adding a fallback or alternative method to move the cursor to a clean position below the output if implementing the alternate screen buffer is not feasible.
  • Verify that the solution works across different terminals and operating systems to ensure consistency.

Example

import sys

# Enter alternate screen buffer
sys.stdout.write("\x1b[?1049h")

# ... Claude Code TUI rendering ...

# Exit alternate screen buffer and restore cursor position
sys.stdout.write("\x1b[?1049l")

Notes

This solution assumes that the issue is solely due to the lack of alternate screen buffer handling. Other factors, such as terminal settings or environment variables, may also affect the behavior.

Recommendation

Apply a workaround by implementing the alternate screen buffer using smcup and rmcup escape sequences, as this is a common and widely-supported solution for TUI applications.

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