perf: launch sessions as initial tmux process to skip pane-ready poll#389
Open
naps62 wants to merge 1 commit intoasheshgoplani:mainfrom
Open
perf: launch sessions as initial tmux process to skip pane-ready poll#389naps62 wants to merge 1 commit intoasheshgoplani:mainfrom
naps62 wants to merge 1 commit intoasheshgoplani:mainfrom
Conversation
For non-shell tools (claude, gemini, codex, opencode, custom), pass the command directly to `tmux new-session` instead of starting a shell, polling for a prompt (up to 2s), and sending keys via send-keys. This eliminates ~1-2s of latency on every session launch. Shell sessions keep the legacy flow since they need a wrapping shell for status detection. Commands with bash-specific syntax are wrapped in `bash -c` for fish shell compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR reduces session launch latency by starting non-shell tool commands directly as the initial tmux pane process (skipping the waitForPaneReady prompt poll + send-keys path), while keeping shell sessions on the legacy flow for status-detection compatibility.
Changes:
- Launch commands via
tmux new-session ... <command>whenRunCommandAsInitialProcessis enabled, with conditionalbash -cwrapping. - Keep a fallback path using
send-keyswhen not launching as the initial process. - Enable
RunCommandAsInitialProcessfor all non-shell tools (and sandboxed sessions) in instance startup/restart flows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
internal/tmux/tmux.go |
Adds initial-process launch path for faster session start; keeps send-keys fallback. |
internal/session/instance.go |
Expands when RunCommandAsInitialProcess is enabled (non-shell tools + sandbox). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Sandbox sessions also get remain-on-exit for dead-pane detection. | ||
| i.tmuxSession.OptionOverrides = i.buildTmuxOptionOverrides() | ||
| i.tmuxSession.RunCommandAsInitialProcess = i.IsSandboxed() | ||
| i.tmuxSession.RunCommandAsInitialProcess = i.IsSandboxed() || i.Tool != "shell" |
Comment on lines
+1191
to
+1194
| if strings.Contains(command, "$(") || strings.Contains(command, "session_id=") { | ||
| escapedCmd := strings.ReplaceAll(command, "'", "'\"'\"'") | ||
| cmdToStart = fmt.Sprintf("bash -c '%s'", escapedCmd) | ||
| } |
Comment on lines
+1190
to
+1195
| cmdToStart := command | ||
| if strings.Contains(command, "$(") || strings.Contains(command, "session_id=") { | ||
| escapedCmd := strings.ReplaceAll(command, "'", "'\"'\"'") | ||
| cmdToStart = fmt.Sprintf("bash -c '%s'", escapedCmd) | ||
| } | ||
| args = append(args, cmdToStart) |
Comment on lines
+1184
to
+1195
| // Create new tmux session in detached mode with the command as the initial | ||
| // process. This avoids the slow shell-wait-sendkeys path (~2s pane ready poll). | ||
| // Commands containing bash-specific syntax are wrapped for fish compatibility. | ||
| startWithInitialProcess := command != "" && s.RunCommandAsInitialProcess | ||
| args := []string{"new-session", "-d", "-s", s.Name, "-c", workDir} | ||
| if startWithInitialProcess { | ||
| args = append(args, command) | ||
| cmdToStart := command | ||
| if strings.Contains(command, "$(") || strings.Contains(command, "session_id=") { | ||
| escapedCmd := strings.ReplaceAll(command, "'", "'\"'\"'") | ||
| cmdToStart = fmt.Sprintf("bash -c '%s'", escapedCmd) | ||
| } | ||
| args = append(args, cmdToStart) |
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
tmux new-sessionas the initial process instead of starting a bare shell, polling for a prompt (up to 2s viawaitForPaneReady), then sending keysbash -cfor fish shell compatibilityTest plan
🤖 Generated with Claude Code