Skip to content

Conversation

@snirt
Copy link

@snirt snirt commented Dec 17, 2025

Add ability to run multiple concurrent Claude Code terminal sessions with session management, smart ESC handling, and session-aware selection tracking.

New commands:

  • ClaudeCodeNew: Create a new terminal session
  • ClaudeCodeSessions: Show session picker (supports fzf-lua)
  • ClaudeCodeSwitch: Switch to session by number
  • ClaudeCodeCloseSession: Close session by number or active session

New features:

  • Smart ESC handling: double-tap ESC to exit terminal mode, single ESC sends to terminal (configurable via esc_timeout)
  • Session-aware selection tracking and message routing
  • OSC title handler for capturing terminal title changes
  • Configurable terminal keymaps (terminal.keymaps.exit_terminal)

New modules:

  • lua/claudecode/session.lua: Session lifecycle management
  • lua/claudecode/terminal/osc_handler.lua: Terminal title detection

Add ability to run multiple concurrent Claude Code terminal sessions with
session management, smart ESC handling, and session-aware selection tracking.

New commands:
- ClaudeCodeNew: Create a new terminal session
- ClaudeCodeSessions: Show session picker (supports fzf-lua)
- ClaudeCodeSwitch: Switch to session by number
- ClaudeCodeCloseSession: Close session by number or active session

New features:
- Smart ESC handling: double-tap ESC to exit terminal mode, single ESC
  sends to terminal (configurable via esc_timeout)
- Session-aware selection tracking and message routing
- OSC title handler for capturing terminal title changes
- Configurable terminal keymaps (terminal.keymaps.exit_terminal)

New modules:
- lua/claudecode/session.lua: Session lifecycle management
- lua/claudecode/terminal/osc_handler.lua: Terminal title detection
@snirt
Copy link
Author

snirt commented Dec 18, 2025

Found a bug in this PR - killing the claude-code using ctrl-c closes the instance, but does not remove the session record from the session list. I'll fix it soon.

Snir Turgeman added 4 commits December 18, 2025 17:53
Add jobresize() calls to notify the terminal job of window dimensions
when switching between sessions. This fixes the cursor appearing in
the wrong position and line shifting after session switch.

The terminal job needs to know its window dimensions to correctly
calculate cursor position and line wrapping. Without this, the
terminal renders based on stale window state from the previous session.
- Add clickable tabbar for session switching (floating and winbar modes)
- Support left-click to switch sessions, middle-click to close
- Add close button (✕) on each tab with same background as tab
- Add new session button (+) for creating new sessions
- Add scroll wheel support to cycle sessions in floating tabbar
- Add mouse selection tracking (LeftRelease/LeftDrag) for better selection capture
- Fix intentional close handling to suppress exit error on X click
- Add config validation for terminal.tabs options
… available

When a Claude terminal session exits (e.g., via Ctrl-C), the window now
stays open and switches to display another available session instead of
closing entirely. This provides a smoother multi-session experience.

Changes:
- Add session switching logic to TermClose handlers in both providers
- Disconnect old terminal instance from window before buffer switch
- Check session existence before destroying to prevent double-destruction
- Add close_session_keep_window() for explicit session switching
Add dedicated window_manager module that owns the single terminal window.
This separates window lifecycle from buffer lifecycle, fixing issues where:
- Creating new sessions would reset window to default size
- Switching between tabs could cause window duplication
- Closing tabs could leave windows in wrong positions

Changes:
- Add window_manager.lua: singleton that manages THE terminal window
- Refactor snacks.lua: create buffers only, delegate window to manager
- Refactor native.lua: simplified buffer-only management
- Update terminal.lua: initialize window_manager, improve tab navigation
- New tab now selects the created session
- Closing tab selects previous tab (or next if first)
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