feat: add cmux and Ghostty terminal support for sessions#53
Merged
feat: add cmux and Ghostty terminal support for sessions#53
Conversation
cmux: full CLI support (new-workspace --cwd --command, select- workspace, focus-panel, send), but requires socket mode change from default cmuxOnly to automation/allowAll. Ghostty: macOS limited — no +new-window, no AppleScript dict, no tab-level switching. Fallback to clipboard only. Also document why git branch --show-current is not viable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cmux: full launch via new-workspace --cwd --command, switch via select-workspace with project name matching. Falls back to clipboard if socket access denied. Ghostty: clipboard + activate (macOS limited, no tab control). Settings: Terminal App selector (iTerm2/cmux/Ghostty), iTerm2 Open Mode only shown when iTerm2 selected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
new-workspace creates but doesn't focus. Add select-workspace with returned workspace ID + activate cmux app. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
list-workspaces output was truncated and titles don't always contain paths. Now iterate all workspaces and check each one's cwd via sidebar-state for exact path matching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pass 1: sidebar-state cwd + focused_cwd match (fast, exact) Pass 2: tree --all to find surface title matching project name (handles 2nd tab and renamed workspaces) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sequential sidebar-state for 33 workspaces took ~5s. Now runs all queries in parallel via Promise.all (~0.5s). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cmux has AppleScript dictionary with terminal.workingDirectory and focus, but testing shows count windows returns 0. Keep CLI sidebar-state + tree approach with parallel queries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Walk parent process tree to detect iTerm2/cmux/Ghostty/Terminal. Active sessions switch using detected terminal (not settings). Non-active sessions use settings terminal for launch. Show small uppercase badge (e.g. ITERM2, CMUX) on active items. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Switch: match terminal working directory, focus matching terminal Launch: new tab with surface configuration (command + cwd) Fallback to clipboard if AppleScript fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use 'from' instead of 'with configuration' for record parameter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
command parameter is passed to exec directly (not shell), so cd && claude fails. Use initial working directory for cwd and initial input to type the resume command + newline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove '(clipboard)' from Ghostty label (now full support). Show Open Mode (New Tab/Window) for both iTerm2 and Ghostty. Ghostty launch respects terminalMode setting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ghostty now has full AppleScript support (working directory, focus, new tab/window with surface configuration). cmux marked as limited support due to same-cwd matching issue. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Session-related dropdowns (Default Tab, Session Terminal, Open Mode, Session Preview) now only visible when switcher is in Sessions mode. Fixes popup closing issue when interacting with dropdowns in Projects tab. Closes #54 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Clarifies that this setting only affects launching new sessions, not switching to active ones (which auto-detects terminal). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add cmux and Ghostty terminal support for Claude Code session launch/switch, with auto-detection of which terminal each active session is running in.
Features
cmux new-workspace --cwd --command+ autoselect-workspace+ activate. Switch via parallelsidebar-statecwd matching +treesurface title fallback. Requires socket modeautomationorallowAll.working directorymatching +focus, launch vianew tab/new windowwithsurface configuration(initial working directory + initial input). No external requirements.Auto-Detection
For active sessions, CodeV walks the parent process tree (
ps -o comm=+ps -o ppid=) to find which terminal app the claude process is running in. This means:cmux Implementation
Launch:
cmux new-workspace --cwd <path> --command "claude --resume <id>"+select-workspace+ activateSwitch (two-pass):
sidebar-statequeries for all workspaces (~0.5s for 33 workspaces). Match bycwdorfocused_cwd.cmux tree --allto find surface titles matching project name. Handles 2nd-tab and renamed workspaces.Socket requirement:
automationorallowAllmode (tested: both work, defaultcmuxOnlydoes not)Ghostty Implementation
Launch: AppleScript
new tab/new windowwithsurface configuration from {initial working directory, initial input}. Usesinitial inputinstead ofcommandparameter (which gets passed toexecdirectly, not shell).Switch: AppleScript iterates all windows → tabs → terminals, matches
working directory, callsfocus.Same-CWD Limitation (affects ALL terminals)
When multiple sessions share the same
projectPath(e.g. two sessions in/Users/grimmer/git/codex-ff):lsofcwd matches the samehistory.jsonlentry)working directorymatch finds the first terminal, not necessarily the correct oneThis affects iTerm2, Ghostty, and cmux equally. Root cause: cwd-based matching cannot distinguish multiple terminals with the same working directory. Would need per-terminal PID or tty matching — iTerm2 has tty via AppleScript but our
detectActiveSessionsdeduplicates by cwd before tty matching.cmux-Specific Limitations
count windowsreturns 0isAppleScriptEnabledalways false — Ghostty fork lacksmacos-applescriptconfig key. Fix submitted: cmux PR 1826working directoryreturns emptyTerminalPanel.directorynever updated — should readpanelDirectories. Fix submitted: cmux PR 1826cmuxOnlyblocks external processescmux PR We Submitted
cmux PR 1826 (
fix: AppleScript count windows returns 0 + working directory returns empty):macos-applescriptconfig key →isAppleScriptEnabledalwaysfalseScriptTerminal.workingDirectoryreadsTerminalPanel.directorywhich is never updated → should readWorkspace.panelDirectoriessidebar-state+treeapproachcmux Upstream Items to Watch
fix: AppleScript count windows + working directoryfeat: add cwd to surface list APIBackground workspaces have dead PTYs--commanddelayTerminal Support Matrix
Related Issues
Design Doc
See docs/claude-session-integration-design.md for full research details.
🤖 On behalf of @grimmerk — generated with Claude Code