Skip to content

fix: add terminal window validation and configurable persistence #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alvarosevilla95
Copy link

@alvarosevilla95 alvarosevilla95 commented Jun 22, 2025

Summary

Fixes terminal window validation issues and adds configurable terminal persistence.

Changes Made

  1. Window Validation Fix (Snacks Provider)

    • Adds validation to check if the terminal window is still valid before attempting to focus it
    • If the window was closed, reopens the terminal instead of throwing an error
    • Prevents crashes when the terminal window is manually closed and the user tries to toggle focus
  2. Configurable Terminal Persistence (Native Provider)

    • Adds preserve_on_close configuration option (default: false)
    • When true, preserves terminal process when window is manually closed (native provider only)
    • Maintains backward compatibility with existing behavior
    • Provides same functionality as snacks provider but makes it configurable

Configuration

Users can now enable terminal persistence by setting:

require('claudecode').setup({
  terminal = {
    preserve_on_close = true, -- Preserve terminal process when window is closed
    -- other terminal options...
  }
})

Default behavior (preserve_on_close = false): Terminal buffer is wiped when window is closed (original behavior)
New behavior (preserve_on_close = true): Terminal buffer is hidden when window is closed, preserving the process for later restoration

Technical Details

  • Both providers now handle closed terminal windows gracefully
  • Terminal processes are preserved during programmatic hiding (toggle functions) regardless of the setting
  • The preserve_on_close setting only affects manual window closing (X button, :q, etc.)
  • Comprehensive documentation added to README for the new configuration option

@alvarosevilla95 alvarosevilla95 changed the title fix: add window validation in terminal focus toggle fix: add terminal window validation and configurable persistence Jun 22, 2025
Adds validation to check if the terminal window is still valid before
attempting to focus it. If the window was closed, reopens the terminal
instead of throwing an error.

This prevents crashes when the terminal window is manually closed and
the user tries to toggle focus.
Adds preserve_on_close option to terminal configuration that allows users
to preserve terminal processes when windows are manually closed. Defaults
to false for backward compatibility.

- Add preserve_on_close config option (default: false)
- Update native provider to use configurable buffer behavior
- Fix hide_terminal to preserve process during programmatic hiding
- Update README with new configuration option and documentation

This provides the same functionality as the snacks provider fix but makes
it configurable so users can choose their preferred behavior.
@alvarosevilla95 alvarosevilla95 force-pushed the fix/terminal-window-validation branch from e942ac9 to 8101128 Compare June 22, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant