summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-11 05:34:37 -0500
committerCraig Jennings <c@cjennings.net>2026-05-11 05:34:37 -0500
commitde555fa8b48c5ed5f17c0a8db9de7ecb946aa75d (patch)
tree162fd451e5944fc7ef60eeddc388e6a1f51e0c5d
parentca7015486d230192e94c51c0e5d014fc83a7a35f (diff)
downloaddotemacs-de555fa8b48c5ed5f17c0a8db9de7ecb946aa75d.tar.gz
dotemacs-de555fa8b48c5ed5f17c0a8db9de7ecb946aa75d.zip
feat(ai-vterm): name the tmux session's first window "ai"
I pass `tmux new-session -n` so the window running the AI tool shows up as "ai" in the window list instead of auto-naming after the running program. A shell opened by hand in a later window still auto-names (e.g. "zsh"), so the two read distinctly. The name is a new `defcustom` (`cj/ai-vterm-tmux-window-name`), symmetric with the session-prefix custom.
-rw-r--r--modules/ai-vterm.el26
-rw-r--r--tests/test-ai-vterm--launch-command.el16
2 files changed, 36 insertions, 6 deletions
diff --git a/modules/ai-vterm.el b/modules/ai-vterm.el
index 8f688301..7b84ba14 100644
--- a/modules/ai-vterm.el
+++ b/modules/ai-vterm.el
@@ -101,6 +101,17 @@ default \"aiv-\" is short for \"ai-vterm\"."
:type 'string
:group 'ai-vterm)
+(defcustom cj/ai-vterm-tmux-window-name "ai"
+ "Name given to the first tmux window in an AI-vterm session.
+
+Passed as `tmux new-session -n', so the window running the AI tool
+shows up as this name in `tmux ls' / the status line. A later
+window opened by hand (e.g. a shell) auto-names after its command,
+so the two read distinctly instead of both showing up as the
+running program."
+ :type 'string
+ :group 'ai-vterm)
+
(defconst cj/--ai-vterm-name-prefix "claude ["
"Buffer-name prefix shared by all AI-vterm buffers.
@@ -191,20 +202,23 @@ looked up in SESSIONS, so the lossy whitespace->hyphen transform in
(and (member (cj/--ai-vterm-tmux-session-name dir) sessions) t))
(defun cj/--ai-vterm-launch-command (dir)
- "Return the shell command line that runs Claude in a project tmux session.
+ "Return the shell command line that runs the AI tool in a project tmux session.
Uses `tmux new-session -A' so a second F9 on the same project reattaches
to the running session instead of spawning a new one. The session name
-is the project's basename via `cj/--ai-vterm-tmux-session-name'.
+comes from `cj/--ai-vterm-tmux-session-name'; the first window is named
+`cj/ai-vterm-tmux-window-name' (default \"ai\") so a later hand-opened
+window auto-names after its command and the two read distinctly.
The shell command run on first creation is
- <claude-command>; exec bash
-so the tmux window survives Claude exiting -- the session stays alive
-with a bare bash prompt for recovery, and reattach works the same way."
+ <cj/ai-vterm-claude-command>; exec bash
+so the tmux window survives the AI command exiting -- the session stays
+alive with a bare bash prompt for recovery, and reattach works the same way."
(let ((session (cj/--ai-vterm-tmux-session-name dir))
(start-dir (expand-file-name dir)))
- (format "tmux new-session -A -s %s -c %s '%s'"
+ (format "tmux new-session -A -s %s -n %s -c %s '%s'"
(shell-quote-argument session)
+ (shell-quote-argument cj/ai-vterm-tmux-window-name)
(shell-quote-argument start-dir)
(concat cj/ai-vterm-claude-command "; exec bash"))))
diff --git a/tests/test-ai-vterm--launch-command.el b/tests/test-ai-vterm--launch-command.el
index 464c88b6..17f02f02 100644
--- a/tests/test-ai-vterm--launch-command.el
+++ b/tests/test-ai-vterm--launch-command.el
@@ -31,6 +31,22 @@
" -s aiv-foo "
(cj/--ai-vterm-launch-command "/code/foo")))))
+(ert-deftest test-ai-vterm--launch-command-names-window ()
+ "Normal: `-n <window-name>' so the claude window is named distinctly."
+ (let ((cj/ai-vterm-claude-command "claude")
+ (cj/ai-vterm-tmux-window-name "ai"))
+ (should (string-match-p
+ " -n ai "
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
+(ert-deftest test-ai-vterm--launch-command-honors-custom-window-name ()
+ "Boundary: a non-default window name is what `-n' gets."
+ (let ((cj/ai-vterm-claude-command "claude")
+ (cj/ai-vterm-tmux-window-name "claude"))
+ (should (string-match-p
+ " -n claude "
+ (cj/--ai-vterm-launch-command "/code/foo")))))
+
(ert-deftest test-ai-vterm--launch-command-includes-start-directory ()
"Normal: `-c <dir>' so the new session's first window starts in DIR."
(let ((cj/ai-vterm-claude-command "claude"))