Title: here mode level 2: eliminate send_keys entirely — split-window/swap-pane/kill-pane · Issue #1032 · tmux-python/tmuxp · GitHub
Open Graph Title: here mode level 2: eliminate send_keys entirely — split-window/swap-pane/kill-pane · Issue #1032 · tmux-python/tmuxp
X Title: here mode level 2: eliminate send_keys entirely — split-window/swap-pane/kill-pane · Issue #1032 · tmux-python/tmuxp
Description: Parent: #1030 Approach Eliminate all send_keys usage in --here mode by replacing the "mutate existing pane" pattern with "create fresh pane, swap into position." This is the cleanest possible approach — zero shell assumptions. Core idea ...
Open Graph Description: Parent: #1030 Approach Eliminate all send_keys usage in --here mode by replacing the "mutate existing pane" pattern with "create fresh pane, swap into position." This is the cleanest possible appro...
X Description: Parent: #1030 Approach Eliminate all send_keys usage in --here mode by replacing the "mutate existing pane" pattern with "create fresh pane, swap into position." This is the cle...
Opengraph URL: https://github.com/tmux-python/tmuxp/issues/1032
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"here mode level 2: eliminate send_keys entirely — split-window/swap-pane/kill-pane","articleBody":"Parent: #1030\n\n## Approach\n\nEliminate all `send_keys` usage in `--here` mode by replacing the \"mutate existing pane\" pattern with \"create fresh pane, swap into position.\" This is the cleanest possible approach — zero shell assumptions.\n\n### Core idea\n\nInstead of sending `cd`, `export`, and shell commands to the existing pane (which assumes a POSIX shell is running), create a brand-new pane with the correct directory, environment, and shell, then swap it into the position of the original pane and kill the original.\n\n### Implementation\n\nReplace [`builder.py:690-727`](https://github.com/tmux-python/tmuxp/blob/886e63d37dbfeeefab1e645f168178b13ff03b7f/src/tmuxp/workspace/builder.py#L690-L727):\n\n```python\n# Before: send_keys cd, export, shell into existing pane\nactive_pane.send_keys(f\"cd {shlex.quote(start_directory)}\", enter=True)\nfor _ekey, _eval in environment.items():\n _here_pane.send_keys(f\"export {_ekey}={shlex.quote(str(_eval))}\", enter=True)\n_here_pane.send_keys(window_shell, enter=True)\n```\n\nWith:\n\n```python\n# After: create fresh pane with correct state, swap into position\n_active_pane = window.active_pane\nassert _active_pane is not None\n\n# Build split-window args\nsplit_kwargs: dict[str, t.Any] = {}\nif start_directory:\n split_kwargs[\"start_directory\"] = start_directory\nif environment:\n split_kwargs[\"environment\"] = environment\nif window_shell:\n split_kwargs[\"shell\"] = window_shell\n\n# Create new pane with correct dir/env/shell via tmux primitives\nnew_pane = window.split(**split_kwargs)\n\n# Swap new pane into the position of the original\nnew_pane.cmd(\"swap-pane\", \"-t\", _active_pane.pane_id)\n\n# Kill the original pane (now in the split position)\n_active_pane.kill()\n```\n\n### How this maps to tmux commands\n\n```\ntmux split-window -c /path/to/dir -e KEY=VALUE [shell_command]\ntmux swap-pane -t %original_pane_id\ntmux kill-pane -t %original_pane_id\n```\n\n### tmux version requirements\n\n- `split-window -c`: Available since tmux 1.9\n- `split-window -e`: Available since tmux 3.2 (tmuxp's minimum)\n- `swap-pane`: Available since tmux 0.8\n- All within tmuxp's tmux 3.2+ minimum requirement\n\n### Comparison with teamocil\n\nteamocil uses [`send_keys cd`](https://github.com/remi/teamocil/blob/9ceecf5/lib/teamocil/tmux/window.rb#L88-L95) for directory and [`split-window -c`](https://github.com/remi/teamocil/blob/9ceecf5/lib/teamocil/command/split_window.rb#L3-L13) for new panes. This approach goes further than teamocil by eliminating even the `cd` send_keys call.\n\n### Trade-offs\n\n**Pros:**\n- Zero `send_keys` for infrastructure — no shell assumption at all\n- Works regardless of what's running in the active pane (vim, python, fish)\n- Environment set at pane creation time via `-e` (tmux 3.2+)\n- Directory set via `-c` (tmux primitive)\n- Clean pane with fresh shell — no history pollution\n\n**Cons:**\n- Destroys the user's existing shell state (history, local variables, aliases loaded via `.bashrc`)\n- Brief visual flash as the swap occurs\n- More complex than Level 1 — uses `swap-pane` + `kill-pane` which is unusual in libtmux\n- The existing pane is killed — if the user had unsaved work in a background process, it's gone\n- May need libtmux API additions if `split()` doesn't support `-e` kwargs yet\n\n### Behavioral change\n\nThis changes `--here` semantics from \"modify the existing pane in-place\" to \"replace the existing pane with a fresh one.\" Users who rely on existing shell state in the first pane would lose it. This may be acceptable since `--here` is conceptually \"rebuild this window\" — but it should be documented.\n\n### Tests to add/update\n\n- Rewrite `test_here_mode_provisions_environment` to verify env via pane capture (new pane inherits env)\n- Rewrite `test_here_mode_start_directory_special_chars` to verify cwd without `send_keys`\n- Add test verifying `--here` works when active pane runs a non-shell program\n- Add test verifying original pane is replaced (pane count stays at 1)\n\n### libtmux prerequisites\n\nCheck whether `window.split()` supports:\n- `environment` kwarg (maps to `-e KEY=VALUE`)\n- `shell` kwarg (maps to the shell/command argument)\n- `start_directory` kwarg (maps to `-c`)\n\nIf not, these would need to be added to libtmux first.","author":{"url":"https://github.com/tony","@type":"Person","name":"tony"},"datePublished":"2026-03-29T09:33:17Z","url":"https://github.com/tmux-python/tmuxp/issues/1032"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b63cc249-351c-eb6b-be3c-3cfeddcf5a02 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC1C:3B8E5E:288EB2:382F41:6B008895 |
| html-safe-nonce | ca33b2f02b5266f8bbc5ee91f91b9a111a497fde94c3d2068ef4e1eda9a790b6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzFDOjNCOEU1RToyODhFQjI6MzgyRjQxOjZCMDA4ODk1IiwidmlzaXRvcl9pZCI6IjYzMzM5MjA0ODk0Nzk2MzcxNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a935760c569a5647a7ba74ef9b49ff984894a24dcd4ca3c8c14eca8f5068a9b6 |
| hovercard-subject-tag | issue:4163552222 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/tmux-python/tmuxp/1032/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d49339f0353fa71b30fe687ec0d9a62bbef44574708e9442bc873650f311b707/tmux-python/tmuxp/issues/1032 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d49339f0353fa71b30fe687ec0d9a62bbef44574708e9442bc873650f311b707/tmux-python/tmuxp/issues/1032 |
| og:image:alt | Parent: #1030 Approach Eliminate all send_keys usage in --here mode by replacing the "mutate existing pane" pattern with "create fresh pane, swap into position." This is the cleanest possible appro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tony |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61 |
| turbo-cache-control | no-preview |
| go-import | github.com/tmux-python/tmuxp git https://github.com/tmux-python/tmuxp.git |
| octolytics-dimension-user_id | 37234308 |
| octolytics-dimension-user_login | tmux-python |
| octolytics-dimension-repository_id | 12398170 |
| octolytics-dimension-repository_nwo | tmux-python/tmuxp |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 12398170 |
| octolytics-dimension-repository_network_root_nwo | tmux-python/tmuxp |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | db758f8e02b8257935fb03edf81a3e76eb3abd11 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width