Skip to content

fix(terminal): resolve blank terminals after project switch#1836

Open
AndyMik90 wants to merge 1 commit intodevelopfrom
fix/terminal-blank-project-switch
Open

fix(terminal): resolve blank terminals after project switch#1836
AndyMik90 wants to merge 1 commit intodevelopfrom
fix/terminal-blank-project-switch

Conversation

@AndyMik90
Copy link
Owner

@AndyMik90 AndyMik90 commented Feb 14, 2026

Summary

  • Force SIGWINCH on same-dimension resize by cycling through a temporary smaller size first, ensuring TUI apps (Claude Code) redraw after project switch
  • Skip stale buffer replay for Claude-mode terminals on project switch remount to prevent garbled display from concatenated serialized state and raw PTY output
  • Preserve buffer replay for initial session restore to maintain loading preview while claude --continue starts

Problem

When switching between projects, terminals appeared completely blank (black screen) even though Claude Code was running in the background. Two compounding root causes:

  1. No SIGWINCH on same-dimension resize: On macOS/Linux, ioctl(TIOCSWINSZ) only sends SIGWINCH when dimensions actually change. After project switch, the PTY persists with old dimensions and the terminal remounts at the same size, so TUI apps never receive SIGWINCH and never redraw.

  2. Stale buffer replay: The serialized xterm buffer was concatenated with raw PTY output accumulated during the unmount period, producing garbled display instead of a clean terminal.

Test plan

  • Switch between projects with active Claude Code terminals — terminals should redraw properly
  • Restore app with saved Claude sessions — initial buffer replay should still show loading preview
  • Regular (non-Claude) terminals should continue to replay buffers normally on project switch
  • Verify no regressions with terminal resize behavior

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced terminal window resize handling to properly trigger refresh signals in edge cases where dimensions remain unchanged
    • Refined buffered terminal output replay behavior in Claude mode to prevent unnecessary content duplication

Force SIGWINCH on same-dimension resize and skip stale buffer replay
for Claude-mode terminals during project switch remount.

Two compounding issues caused blank terminals when switching projects:

1. On macOS/Linux, ioctl(TIOCSWINSZ) only sends SIGWINCH when dimensions
   actually change. After project switch, PTY persists with old dimensions
   and the terminal remounts at the same size, so TUI apps never get
   SIGWINCH and never redraw. Fix: resize to (cols-1, rows) first, then
   to (cols, rows) to force the signal.

2. Buffer replay concatenated serialized xterm state with raw PTY output
   accumulated during the unmount period, producing garbled display. Fix:
   skip buffer replay for Claude-mode terminals on project switch remount
   (the forced SIGWINCH makes Claude Code redraw its full TUI). Initial
   restore still replays the buffer as a loading preview.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @AndyMik90, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves critical issues where terminals, especially those running Claude Code, appeared blank or displayed garbled content after switching projects. The changes ensure that terminal applications correctly redraw by forcing a SIGWINCH signal even when dimensions don't change, and prevent display corruption by selectively skipping stale buffer replays for Claude-mode terminals during project remounts, while maintaining replay for initial session restores.

Highlights

  • Forced SIGWINCH on same-dimension resize: Implemented a mechanism to cycle through a temporary smaller size when a terminal is resized to the same dimensions, ensuring TUI applications like Claude Code redraw correctly after a project switch.
  • Skipped stale buffer replay for Claude-mode terminals: Modified the buffer replay logic to skip replaying stale buffers for Claude-mode terminals during project switch remounts, preventing garbled displays caused by concatenated serialized state and raw PTY output.
  • Preserved buffer replay for initial session restore: Ensured that buffer replay still occurs for initial session restores, allowing users to see a loading preview while claude --continue starts.
Changelog
  • apps/frontend/src/main/terminal/pty-manager.ts
    • Removed a redundant comment regarding dimension validation.
    • Added logic to detect same-dimension resizes and force a SIGWINCH signal by temporarily resizing the PTY to a slightly smaller size before restoring the original dimensions.
  • apps/frontend/src/renderer/components/terminal/useXterm.ts
    • Imported useTerminalStore to access terminal state.
    • Modified the bufferedOutput replay logic to conditionally skip replay for Claude-mode terminals during project switch remounts, while preserving it for initial session restores.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

These changes address terminal behavior issues: forcing SIGWINCH signals when PTY resize dimensions remain unchanged, and conditionally skipping buffered output replay when terminals operate in Claude mode (excluding initial restore scenarios).

Changes

Cohort / File(s) Summary
PTY Resize Handling
apps/frontend/src/main/terminal/pty-manager.ts
Modified resizePty to force a SIGWINCH cycle when requested dimensions match current dimensions by performing a temporary resize to (cols - 1, rows) before the actual resize, with debug logging added.
Terminal Output Replay Logic
apps/frontend/src/renderer/components/terminal/useXterm.ts
Added conditional logic to skip buffered output replay when terminal is in Claude mode and not in initial restore; uses terminal state from useTerminalStore (isClaudeMode, pendingClaudeResume, isRestored flags).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #1650: Modifies resizePty in pty-manager.ts to handle terminal resize/PTY dimension behavior
  • #1241: Modifies useXterm.ts terminal output buffering and replay logic
  • #1743: Introduces terminal state flags (isClaudeMode, pendingClaudeResume) that this PR consumes for replay logic

Suggested labels

bug, area/frontend, size/M, os/macos, os/linux

Suggested reviewers

  • MikeeBuilds

Poem

🐰 A hop, a skip, a SIGWINCH call,
When terminal dimensions don't change at all,
Claude mode whispers "replay, replay no more,"
The buffer rests softly by the electron door! 🪟✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(terminal): resolve blank terminals after project switch' directly addresses the main problem being solved—blank terminals appearing after switching projects—and matches the primary objectives of the PR.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/terminal-blank-project-switch

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added area/frontend This is frontend only bug Something isn't working size/S Small (10-99 lines) labels Feb 14, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses a significant issue causing blank terminals after a project switch. The solution is well-thought-out, employing a two-part fix: forcing a SIGWINCH signal to trigger a redraw in TUI applications, and intelligently skipping stale buffer replays in Claude-mode terminals to prevent garbled displays. The code is clear and the accompanying comments are very helpful. I have one minor suggestion to enhance code robustness.

// For initial restore (isRestored=true), we DO replay to show the saved state
// as a loading preview while claude --continue starts.
const terminal = useTerminalStore.getState().terminals.find(t => t.id === terminalId);
const isClaudeActive = terminal?.isClaudeMode || terminal?.pendingClaudeResume;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the current logic works due to JavaScript's truthiness rules, explicitly converting the result to a boolean with !! would make the code more robust and the intent clearer. This ensures isClaudeActive is always a boolean and doesn't rely on the falsiness of undefined if terminal.isClaudeMode is false and terminal.pendingClaudeResume is undefined.

Suggested change
const isClaudeActive = terminal?.isClaudeMode || terminal?.pendingClaudeResume;
const isClaudeActive = !!(terminal?.isClaudeMode || terminal?.pendingClaudeResume);

@AndyMik90 AndyMik90 self-assigned this Feb 14, 2026
Copy link
Owner Author

@AndyMik90 AndyMik90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Auto Claude Review - APPROVED

Status: Ready to Merge

Summary: ### Merge Verdict: ✅ READY TO MERGE

✅ Ready to merge - All checks passing, no blocking issues found.

No blocking issues found

Risk Assessment

Factor Level Notes
Complexity Low Based on lines changed
Security Impact None Based on security findings
Scope Coherence Good Based on structural review

Generated by Auto Claude PR Review


This automated review found no blocking issues. The PR can be safely merged.

Generated by Auto Claude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/frontend This is frontend only bug Something isn't working size/S Small (10-99 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant